colon in text file causes hiccups

Started by JohnE, February 16, 2009, 07:25:33 AM

Previous topic - Next topic

JohnE

What am I doing wrong here?   I saved this very short program as 'test.lsp':



(set 'infile (open (main-args 2) "r"))

(print (read-line infile) "n")

(close infile)



It is in a directory with this very short file called 'test.txt':

a_label:



If I run this on the Windows console command line:

newlisp test.lsp test.txt



I get:

a_label:



ERR: symbol expected : "a_label:"



and am back in the command console.



If I change test.txt to:

a_label



It opens the file, prints 'a_label', and leaves me in newlisp, where I should be.



What is that colon doing?



John

(Oops, edited, because in the original posting I left out the 'a_label:' which atually gets printed)

JohnE

#1
Me again already.



If test.lsp is reduced to:



(set 'infile (open (main-args 2) "r"))

(close infile)



Then I still get the result:



ERR: symbol expected : "a_label:"



And back into the command line.



Seems like newLISP is reading the contents of the file without being asked. :(



I know it must be me, it always is.  I've missed something.  



Regards, John

Lutz

#2
this is what happens after executing on the command-line



newlisp test.lsp test.txt





newLISP loads test.lsp and executes it, which loads test.txt. Because test.lsp does not exit, newLISP tries to load text.txt as a program and tries to evaluate the string "a_label:". Because the ":" is syntax in newLISP awaiting a symbol after it.





Put and (exit) statement at the end of test.lsp and everything will be fine ;-)

JohnE

#3
Thanks Lutz, much obliged.  I knew it was me (so I got that bit right).

A lesson soundly learned.



Regards,  John