[itn book] map+curry+inc unexpected behaviour on v10.3.3

Q&A's, tips, howto's
Locked
conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

[itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by conan »

I'm reading now the chapter Working with numbers from Introduction to newlisp book, and in the third code example under the subtitle Invisible conversion and rounding we see:

Code: Select all

(set 'lst '(2 6 9 12))
;-> (2 6 9 12)
(inc (lst 0))
;-> 3
lst
;-> (3 6 9 12)
(map inc lst)
;-> (4 7 10 13)
(map (curry inc 3) lst)
;-> (6 9 12 15) ; === CHECK OUT THIS LINE ===
lst
;-> (3 6 9 12)
But on v10.3.3 I get the map+curry operation to work on the list like this instead:

Code: Select all

newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
> (set 'lst '(2 6 9 12))
(2 6 9 12)
> (inc (lst 0))
3
> lst
(3 6 9 12)
> (map inc lst)
(4 7 10 13)
> (map (curry inc 3) lst)
(6 12 21 33) ; === CHECK OUT THIS LINE ===
> lst
(3 6 9 12)
It's taking the number by pairs and adding them instead of increasing them individually by 3 (except the first one).

Now I recall reading about a function that takes elements by pairs, can't recall the name right now, but recalling that it exists confuses me on this behaviour. Is it expected? Is map+curry+inc supposed to take the list elements in pairs and operate them with one another? I feel it shouldn't, but I may be wrong.

Doing...

Code: Select all

newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
> (set 'lst '(2 6 9 12))
(2 6 9 12)
> (map (curry inc 3) lst)
(5 11 20 32)
> lst
(2 6 9 12)
> (map (lambda (x) (+ x 3)) lst)
(5 9 12 15)
> (map (lambda (x) (inc x 3)) lst)
(5 9 12 15)
> (map (curry + 3) lst)
(5 9 12 15)
...works as expected. So now I see the curry+inc is the issue.

What's going on? Should I update ITN book and denote the pitfall as expected behavior or should this behavior be modified?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by Lutz »

Destructive functions should not be used with curry, but as a workaround, you could do:

Code: Select all

> lst
(2 6 9 12)
> (map (curry inc (copy 3)) lst)
(5 9 12 15)
This will be mentioned in the reference manual for 'curry' and should also be mentioned in the WikiBooks introduction.

ps: is now added in the online manual http://www.newlisp.org/downloads/newlis ... html#curry

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by conan »

Lutz wrote:Destructive functions should not be used with curry...
This will be mentioned in the reference manual for 'curry' and should also be mentioned in the WikiBooks introduction.
Cool. I'll be updating ITN book in a couple of hours, I need to take a nap now.

jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by jopython »

What is the ITN book?

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by conan »

jopython wrote:What is the ITN book?
I mentioned the full title in the first message: ITN book is Introduction to newLISP book. It's linked in newlisp.org documentation, I thought it was pretty known in the community.

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by xytroxon »

Cormullion's original work was a single html (or pdf) version users downloaded to their machines... The wikibooks version came later... Older users are more familiar of thinking in terms of "the Cormullion html/pdf rather than of "ITN"... With other's adding / editing content though, "ITN" becomes a more proper way to think of it in the future...

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by conan »

I just added the notice to avoid using curry with destructive functions in the chapter Apply and map which is the first one to mention curry function.

However I stomp on something when I went to edit the section Invisible conversion and rounding. See, the thing is cormullion wrote that section to tell about inc and dec converting floats to int when no step was provided. But I noticed newlisp v10.3.3 does increment and decrement without converting floats to ints.

cormullion stated:

Code: Select all

(inc 2.5) ; gives 3, not 3.5 as expected
But that's not true anymore on v10.3.3:

Code: Select all

(inc 2.5)
3.5
So the question is:

A.- Should I erase the whole section since the behavior has changed?
B.- Or are there other functions that still make the conversion from float to int and can be used to exemplify the issue?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by Lutz »

Since stable release 10.2.0 (developed in 10.1.10) inc and dec always produce floats and we have the new ++ and -- which produce integers. Now consistently all operators made of letters of the alphabet produce floats and operators written with special characters pruduce ints.

http://www.newlisp.org/downloads/previo ... lease.html

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: [itn book] map+curry+inc unexpected behaviour on v10.3.3

Post by conan »

Thanks, I used ++ to keep the section. Also modified it a little bit to make emphasis on the implicit conversion both inc/dec and ++/-- do.

Locked