[mercury-users] Binding variables in an if then else?
Peter Schachte
schachte at cs.mu.OZ.AU
Mon Aug 9 10:36:44 AEST 2004
> Suppose we have a variable that we want to decompose or unify, say
> AList = [1,2,3]
>
> I want to assign the values in AList to V1, V2, and V3, respectively.
>
> ( AList = [A1, A2, A3] ->
> V1 = A1,
> V2 = A2,
> V3 = A3
> ;
> throw("Something is wrong")
> )
>
> Is it possible to write this more compactly?
I think the nicest thing for cases like this would be to write
something like:
expect(Alist = [A1, A2, A3])
(maybe even make expect a prefix operator.)
The semantics of expect(X) would be the same as that of X, except that
failure of X would be transformed into an exception much like your
example above, so if the determinism of X were semidet, expect would
be det, and similarly for nondet => multi.
I'm sure something like this would be in the library by now, except
that the mode system won't let you code it. But it could be built
into the compiler.
--
Peter Schachte A rock pile ceases to be a rock pile the moment a
schachte at cs.mu.OZ.AU single man contemplates it, bearing within him the
www.cs.mu.oz.au/~schachte/ image of a cathedral.
Phone: +61 3 8344 1338 -- Antoine de Saint-Exupery
--------------------------------------------------------------------------
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