Re: [q-lang-users] "listof" surprises
Brought to you by:
agraef
From: Alexander N. <AN...@sp...> - 2007-05-13 07:34:27
|
Hello maggesi, Sunday, May 13, 2007, 3:01:10 AM, you wrote: mmui> Hi, mmui> I just got burned by this unexpected (for me, of course) behavior of mmui> list comprehension. Given the program mmui> delta X X = 1; mmui> delta _ _ = 0 otherwise; mmui> tabulate N M F = [[F I J : I in [1..N]] : J in [1..M]]; mmui> eye N = tabulate N N delta; mmui> then (eye 2) evaluates to [[0,0],[0,0]] instead of [[1,0],[0,1]] as I mmui> would have imagined. I vaguely understand that the first argument is mmui> passed to delta 'too early' in tabulate, but I didn't try to read mmui> cond.q and understand precisely why it works like this (yet). Yes, it is evaluated 'too early', but there's a simple method to fix it: delta X:Int Y:Int = 1 if Y = X; = 0 otherwise; thus delta I J will just remain not evaluated. -- Best regards, Alexander mailto:AN...@sp... |