Dear Isaac,
Isaac Levin wrote:
hello to all i have a quick question about the syntax
of Oz and how to implement a much needed instruction.
i am familiar with scheme and the use of car and cdr.
my question is how can you easily access the head and
tail of the list so u can manipulate it. my goal is to
have an Isin function that checks if the head of a
list is included in another list, i am very new to the
language so i have no clue how to do this after
reading the online tutorial. so in conclusion, i am
interested in grabbing the head and tail of a list.
thanks prior for the help.
The list pair L=X|T is nothing more than a tuple with two fields,
indexed by 1 and 2. The first element, X, is given by 'L.1', and the
second one, T, by 'L.2'. You can define Car and Cdr as
fun {Car L} L.1 end
fun {Cdr L} L.2 end
Note that you can also access them by pattern matching (with the case
statement). This is more elegant, and a very common way in Oz.
fun {Car L}
case L of X|T then X end
end
fun {Cdr L}
case L of X|T then T end
end
Note that the functions above are equivalent to the following.
fun {Car X|T} X end
fun {Cdr X|T} T end
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users