(current-line) vs. $0

Started by Sammo, December 06, 2003, 02:15:45 PM

Previous topic - Next topic

Sammo

Using HPW's NeoBook interface to newLISP.DLL, I wrote this program to copy an input text file (Data1.txt) to an output text file (Data2.txt) eliminating duplicate entries along the way.  Basically, (unique (contents of Data1.txt)) -> Data2.txt.



This is the NeoBook Interface which establishes the input and output files and then calls the NewLisp code:


SetVar "[LispCode]" "(set 'inFile (open {[PubDir]Data1.txt} {read}))"
hpwNewLispCall "[PubDir]" "[LispCode]" "[LispResult]"

SetVar "[LispCode]" "(set 'outFile (open {[PubDir]Data2.txt} {write}))"
hpwNewLispCall "[PubDir]" "[LispCode]" "[LispResult]"

hpwFileRead "[PubDir]LispCode.txt" "ALL" "[LispCode]"
hpwNewLispCall "[PubDir]" "[LispCode]" "[LispResult]"

And here is LispCode.Txt (the newLISP code is kept in a separate file and read by the hpwFileRead line above):


(set 'uniqueLines '())
(while (read-line inFile)
    (if (not (member (current-line) uniqueLines))
        (set 'uniqueLines (append uniqueLines (list (current-line))))))
(close inFile)
(map (lambda (aLine) (write-line aLine outFile)) uniqueLines)
(close outFile)

My question is this: On manual page 57, (current-line) is deprecated in favor of $0, but I'm not sure how to use $0.  I originally wrote (in part):


(while (read-line inFile)
    (if (not (member $0 uniqueLines))
        (set 'uniqueLines (append uniqueLines (list $0)))))

but that didn't work at all, so I tried:


(while (read-line inFile)
    (set 'myLine $0)
    (if (not (member myLine uniqueLines))
        (set 'uniqueLines (append uniqueLines (list myLine)))))

thinking that the value of $0 had to be captured quickly before it could was changed by another funciton.  But that didn't work, either.



Instead of $0 I'm using (current-line) successfully but wondering what I should be using?



Thanks,

-- Sam

Lutz

#1
The decision to deprecate 'current-line' has been reversed meanwhile and 'current-line' will not be deprecated.



I suggest when working with NeoBook newlisp.dll you get the lates version of the manual from the newLISP distribution in the development directory:



http://newlisp.org/download/development/">http://newlisp.org/download/development/



because a lot of things have changed since the official release version 7.3.1.



Also in my previous post about  the >2048 limitation I was wrong: that >2048 limitation does *not* exist for 'parse' with break-string, and I tried it out on a file. So I am not sure what caused the error message in your case.



Lutz