programming-hint ?

Started by didi, July 01, 2007, 04:33:58 AM

Previous topic - Next topic

didi

( 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 ?

Lutz

#1
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

cormullion

#2
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?

Lutz

#3
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

didi

#4
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  ;-)

rickyboy

#5
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
(λx. x x) (λx. x x)