programming-hint ?

For the Compleat Fan
Locked
didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

programming-hint ?

Post by 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

in your previous post:

Code: Select all

( first ( filter (  fn(x) ( > x mvalue) ) prefer-list )
you can also use shorter:

Code: Select all

(exists (curry < mvalue) prefer-list)
(exists ...) is like (first (filter ..)) and with 'curry you can shorten the lambda expression

Code: Select all

( 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

Code: Select all

(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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I get different results:

Code: Select all

$ 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

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
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

didi wrote: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)

Locked