variable $it not set - updating itn book

Started by conan, December 06, 2011, 04:22:22 AM

Previous topic - Next topic

conan

I found a reference to variable $it set by setf in Introduction to newlisp book, in the chapter on strings,  http://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/Strings&stable=0#Modifying_strings">//http://en.wikibooks.org/w/index.php?title=Introduction_to_newLISP/Strings&stable=0#Modifying_strings



which doesn't exist in the manual nor works in v10.3.3.



I was about to remove the mention, but then decided to ask first in here just in case there's another way to achieve the same results. I mean to operate on the character selected by setf and use that result as the input to the same setf.



The manual only talks about $<int> and $idx

Lutz

#1
The example in the WikiBooks introduction should be changed to:


(set 'wd "cream")
;-> "cream"
> (setf (wd 0) (char (inc (char (copy $it)))))
;; or: (setf (wd 0) (char (+ (char $it) 1)))
;-> "d"
wd
;-> "dream"


Without the copy you get a protection violation for $it which must not be changed.



The system variable $it is mentioned in the 10.3.3 doc for setf



http://www.newlisp.org/downloads/newlisp_manual.html#setf">http://www.newlisp.org/downloads/newlis ... .html#setf">http://www.newlisp.org/downloads/newlisp_manual.html#setf



look at the last examples.



$it is also used in several other functions. For an overview of system variables see here:



http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols">http://www.newlisp.org/downloads/newlis ... em_symbols">http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols

Lutz

#2
... turns out it should not give a protection error. char shouldn't pass out the reference to inc. This will be fixed.



ps: fixed for this week's development release 10.3.8 for char and other functions. A change in the WikiBook Introduction is not necessary.

conan

#3
Quote from: "Lutz"
The system variable $it is mentioned in the 10.3.3 doc

http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols">http://www.newlisp.org/downloads/newlis ... em_symbols">http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols


Sorry about that Lutz, my bad. I just went for the index instead of searching and now I'm noticing that the index is for functions and that there're plenty of mentions of $it.


Quote from: "Lutz"
A change in the WikiBook Introduction is not necessary.


Should it mention the different behavior (pre and post v10.3.8) ?

Lutz

#4
Perhaps we should then update the introduction with this:


(setf (wd 0) (char (+ (char $it) 1)))

and then it covers all versions.



Ps: just did the modification in WikiBooks.

cormullion

#5
Cool to see some collaborative editing action, thanks guys. Btw, only registered users can make changes without a reviewer accepting them; I think this is because I marked the book's status as nearly completed... :) Which it never will be, I hope!