integer?

Started by Sammo, December 10, 2003, 06:36:17 AM

Previous topic - Next topic

Sammo

Until now I've been running newLISP.DLL via NeoBook.  This morning I installed from newlisp_7301_win-tk-104.exe.



1) Why does newLISP require the c:temp directory (I'm running WIN2K) when there's a perfectly good temp directory elsewhere in the directory tree?  I created c:temp and newLISP runs fine now.  Not a real problem -- just wondering.



2) I installed the non-DLL version of newLISP to test the integer? function.  The following seems wrong:



     > (map integer? '(1 2 1.1 sam 1sam sam1))

     (true true nil nil true nil nil)



The seemingly wrong things are a) integer? is mapped to a list of six arguments but returns 7 results; b) the fifth result (integer? 1sam) returns true!



I wanted to test the integer? function because I noticed that I could call my Roman Numeral converter with (roman 1sam) and it would return "I".  The opening test in my program is:



     (if (and (integer? n) (> n 0)) ...



Not only did (integer? 1sam) return true, the subsequent code treated "1sam" as an integer of value 1.

HPW

#1
Sam,



It's a feature!



Take a look at this thread:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=126">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=126
Hans-Peter

Sammo

#2
;list of three -> four results (notice the malformed "1sam")

> (map integer? '(1 1 1sam))

(true true true nil)



;list of three -> three results

> (map integer? '(1 1 sam))

(true true nil)



I'm guessing that (integer? 1sam) uses as much of the argument "1sam" as it can to make an integer and leaves the rest for the lisp reader to deal with.  The lisp reader sees more characters -- "sam" and so constructs another atom or symbol from them.  I could maybe accept that treating 1sam as an integer is a feature, but treating 1sam as two distinct entities is not a feature -- it is a bug!

Lutz

#3
Hi Sam, first to the c:temp issue. newLISP-tk needs a temp directory for temporary files. As a default c:temp is configured. You can change this by editing the 'newlisp-tk.config' file.



To the "1sam" issue. One could change the parse to flag this as an parse error, which I do not want fo reasons outlined below. At this moment if you do:



(parse "1sam") => (1 "sam")



The advantage is that you are able to feed any non-LISP text to the parser wihout causing errors (after translating quotes). When doing natuarl language processing work, it is attractive to work at words as symbols directly, instead of using words as string tokens. This makes especially sence in newLISP, where the symbol implementation is very efficient and scaleable to millions (if you have the memory ;)) of symbols.  Looking at "1sam" as two tokens makes sense, if you think of natural language constructs, such as 1kg 1Mbyte 1000$, etc.



I hope that this way to parse code in newLISP is not too big of a drawback for you when using newLISP.



If you have doubts on how the parser works, it is exposed via the function 'parse' which works exactly like newLISPs internal parser (when no break string is specified).



You can cusotmize 'parse' with an addtional break string argument (can be a regular expression), but that would not change the behaviour of parsing newLISP source.



Lutz

Lutz

#4
there have been several changes in the parser during the 7.3.xx series, so make sure you get the latest version of newLISP from the development drectory.



Lutz