newLISP Fan Club

Forum => Anything else we might add? => Topic started by: didi on July 01, 2007, 04:33:58 AM

Title: programming-hint ?
Post by: didi on July 01, 2007, 04:33:58 AM
( sequence -1 1 0.2 )  results in :



(-1 -0.8 -0.6 -0.4 -0.2 5.551115123e-017 0.2 0.4 0.6 0.8 1)



Instead of  "0"   "5.55..e-017"  is shown,  the reason is probably the float-arithmetic ,  but i need a 'nice' looking sequence with "0"  . Has anyone an idea ?
Title:
Post by: Lutz on July 01, 2007, 06:29:34 AM
in your previous post:


( first ( filter (  fn(x) ( > x mvalue) ) prefer-list )

you can also use shorter:


(exists (curry < mvalue) prefer-list)

(exists ...) is like (first (filter ..)) and with 'curry you can shorten the lambda expression




( sequence -1 1 0.2 ) results in :

(-1 -0.8 -0.6 -0.4 -0.2 5.551115123e-017 0.2 0.4 0.6 0.8 1)


use round


(map (fn (x) (round x -1))  ( sequence -1 1 0.2 ))
=> (-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1)


in this case we cannot use 'curry because the parameter mapped is not the last of the two.



Lutz
Title:
Post by: cormullion on July 01, 2007, 06:45:31 AM
I get different results:


$ newlisp
newLISP v.9.1.0 on OSX UTF-8, execute 'newlisp -h' for more info.

>  ( sequence -1 1 0.2 )
(-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1)


Why is that?
Title:
Post by: Lutz on July 01, 2007, 06:51:50 AM
I get that too, but didi is probably not on a Mac. These issues depend on the OS, its libraries and compiler used to make newLISP.



Lutz
Title:
Post by: didi on July 01, 2007, 08:38:16 AM
Thanks, now it's all OK  :-)  



syntax : ( exists  func-condition  list )

returns the first list-element , that meets the func-condition - this is clear .



But i have to think about the curry-command , and why in the last example only 'map' is possible   .. but i have already found a thread in this forum about curry - ok, i'll understand it  ;-)
Title:
Post by: rickyboy on July 07, 2007, 09:19:08 PM
Quote from: "didi"But i have to think about the curry-command , and why in the last example only 'map' is possible   .. but i have already found a thread in this forum about curry - ok, i'll understand it  ;-)

Hi didi!  Please take the time to meditate on curry, if you need to.  You will come to realize how cool it is and you will be ready to join the Cult of Curry.  I will personally initiate you when we meet at the next newLISP Users Convention -- you will learn the secret handshake and walk away with a nice embossed certificate to show to your friends.  :-)



--Rick