[mercury-users] syntax across languages
Pixel
pixel at mandrakesoft.com
Mon Jun 3 21:00:55 AEST 2002
Ralph Becket <rafe at cs.mu.OZ.AU> writes:
> > Comparison: < > =< =>
>
> s/=>/>=/
got it.
[...]
> > > Multiple selection: two different syntaxes.
> > >
> > > (2) disjunctions:
> > >
> > > ( X = positive, ...
> > > ; X = negative, ...
> > > ; X = zero, ...
> > > )
> >
> > one thing i try to have for the "switch" entry, is that the val only
> > appears once (syntactically).
>
> It seems a small thing to worry about. The Mercury term for a
> disjunction where each arm is headed by a unification of a variable with
> a different data constructor is `switch', precisely because of its
> similarity to the C construct of the same name.
what i mean:
switch (a_long_expression(with_lots_of_parameters)) {
case foo: ...
case bar: ...
}
vs
( a_long_expression(with_lots_of_parameters) = foo, ...
; a_long_expression(with_lots_of_parameters) = bar, ...
)
i'd prefer something along:
X = a_long_expression(with_lots_of_parameters),
(X = foo, ... ; X = bar, ...))
is that ok?
>
> > this would be better in if_then_else where i give the n-ary
> > if_then_else. The problem is I don't know if it would better with a
> > comment telling the conditions must be separate, or writing explictly
> > the cut
>
> A Mercury switch is not the same as an if-then-else chain. For a start,
> behaviour depends on the mode. Also (unless the right compiler flags are
> given) the compiler is free to reorder the disjuncts.
ok sorry.
- I thought mercury had a "red cut"
- and i didn't understand what the "switch" term was about. I've read
and understood that "switch" in mercury is a special kind of
disjunctions.
> > > (1) multiple clauses:
> > >
> > > foo(positive) = ...
> > > foo(negative) = ...
> > > foo(zero) = ...
> >
> > i'd prefer an anonymous solution. is there one?
>
> This is it! The variable being switched on isn't even mentioned, so in
> that sense it's even more `anonymous' than the C version.
???
C has
switch (a_long_expression(with_lots_of_parameters)) {
case foo: ...
case bar: ...
}
the *value* switched on isn't mentioned.
in any case, here i meant that in "foo(positive)", "foo" is not
anonymous! If there is no anonymous construct, is there a way to have
"foo" localized a la haskell:
foo (a_long_expression with_lots_of_parameters)
where foo Positive = ...
foo Negative = ...
thanks!
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list