[q-lang-users] "listof" surprises
Brought to you by:
agraef
From: <ma...@ma...> - 2007-05-12 23:01:22
|
Hi, I just got burned by this unexpected (for me, of course) behavior of list comprehension. Given the program delta X X =3D 1; delta _ _ =3D 0 otherwise; tabulate N M F =3D [[F I J : I in [1..N]] : J in [1..M]]; eye N =3D tabulate N N delta; then (eye 2) evaluates to [[0,0],[0,0]] instead of [[1,0],[0,1]] as I would have imagined. I vaguely understand that the first argument is passed to delta 'too early' in tabulate, but I didn't try to read cond.q and understand precisely why it works like this (yet). This is not the point anyway. My question rather is: wouldn't be a different behavior more appropriated to avoid this kind of traps? E.g., I would like to propose something like: special comprehension E V ~R; comprehension E V R =3D map (lambda V E) R; for which the definition like tabulate N M F =3D comprehension (comprehension (F I J) I [1..N]) J [1..M= ]; seems to show a more predictable behavior. Just trying to learn Q ... M. --=20 Marco Maggesi Universit=E0 degli Studi di Firenze http://www.math.unifi.it/~maggesi/ ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. |