Prev: GUI stuff
Next: mod_lisp, apache
From: Francogrex on 20 May 2010 10:23 For those of you who have experience with Parenscript: (ps (loop for i from 0 to 100 do ((@ document write) (list i (random 1.0))))) translate to: "for (var i = 0; i <= 100; i += 1) { document.write([i, Math.floor(1.0 * Math.random())]); };" Where does the Math.floor come from! It's not supposed to be there!
From: Tomas Zellerin on 20 May 2010 10:42 On 20 kvÄ, 16:23, Francogrex <fra...(a)grex.org> wrote: > For those of you who have experience with Parenscript: > (ps  (loop for i from 0 to 100 do ((@ document write) (list i (random > 1.0))))) > translate to: > "for (var i = 0; i <= 100; i += 1) { >   document.write([i, Math.floor(1.0 * Math.random())]); > > };" > > Where does the Math.floor come from! It's not supposed to be there! Where from: ps-macro-lib.lisp (random (&optional upto) (if upto `(floor (* ,upto ((@ *math random)))) '((@ *math random))))) Why (my guess): to implement CL random behaviour for integer parameters. However, fails for floats then... What to do: use full name with Math yourself.
From: Francogrex on 20 May 2010 12:03 On May 20, 4:42 pm, Tomas Zellerin <zelle...(a)gmail.com> > Where from: ps-macro-lib.lisp > (random (&optional upto) (if upto > `(floor (* ,upto ((@ *math random)))) > '((@ *math random))))) > > Why (my guess): to implement CL random behaviour for integer > parameters. However, fails for floats > then... > > What to do: use full name with Math yourself. Something like: (ps (loop for i from 0 to 100 do ((@ document write) (list i ((@ *math random)))))) ok it works but without wanting to be cynical, I might just as well write the whole thing directly in js. I hope this will be corrected in the future. Thanks
From: Alan Malloy on 20 May 2010 19:41 Tomas Zellerin wrote: > On 20 kvě, 16:23, Francogrex <fra...(a)grex.org> wrote: >> For those of you who have experience with Parenscript: >> (ps (loop for i from 0 to 100 do ((@ document write) (list i (random >> 1.0))))) >> translate to: >> "for (var i = 0; i <= 100; i += 1) { >> document.write([i, Math.floor(1.0 * Math.random())]); >> >> };" >> >> Where does the Math.floor come from! It's not supposed to be there! > > Where from: ps-macro-lib.lisp > (random (&optional upto) (if upto > `(floor (* ,upto ((@ *math random)))) > '((@ *math random))))) > > Why (my guess): to implement CL random behaviour for integer > parameters. However, fails for floats > then... > > What to do: use full name with Math yourself. I'm not familiar with Parenscript, but it looks like you can achieve the same results simply by removing the 1.0 argument to random? I'm aware this isn't quite Lispy, but this macro will result in Math.random() instead of Math.floor(1.0 * Math.random()), which is what you want. So: (ps (loop for i from 0 to 100 do ((@ document write)(list i (random))))) -- Cheers, Alan (San Jose, California, USA)
From: Tomas Zellerin on 21 May 2010 08:08 On 21 kvÄ, 01:41, Alan Malloy <alan.NO.S...(a)malloys.org> wrote: > Tomas Zellerin wrote: > > On 20 kvÄ, 16:23, Francogrex <fra...(a)grex.org> wrote: > >> For those of you who have experience with Parenscript: > >> (ps  (loop for i from 0 to 100 do ((@ document write) (list i (random > >> 1.0))))) > >> translate to: > >> "for (var i = 0; i <= 100; i += 1) { > >>   document.write([i, Math.floor(1.0 * Math.random())]); > > >> };" > > >> Where does the Math.floor come from! It's not supposed to be there! > > > Where from: ps-macro-lib.lisp > >   (random (&optional upto) (if upto > >                  `(floor (* ,upto ((@ *math random)))) > >                  '((@ *math random))))) > > > Why (my guess): to implement CL random behaviour for integer > > parameters. However, fails for floats > > then... > > > What to do: use full name with Math yourself. > > I'm not familiar with Parenscript, but it looks like you can achieve the > same results simply by removing the 1.0 argument to random? I'm aware > this isn't quite Lispy, but this macro will result in Math.random() > instead of Math.floor(1.0 * Math.random()), which is what you want. > > So: > (ps (loop for i from 0 to 100 do ((@ document write)(list i (random))))) > > -- > Cheers, >     Alan (San Jose, California, USA)â Skrýt citovaný text â > > â Zobrazit citovaný text â Oops. You are most likely right, I should not write when tired :)
|
Pages: 1 Prev: GUI stuff Next: mod_lisp, apache |