colon in text file causes hiccups

For the Compleat Fan
Locked
JohnE
Posts: 14
Joined: Thu Nov 01, 2007 5:08 pm

colon in text file causes hiccups

Post by 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
Posts: 14
Joined: Thu Nov 01, 2007 5:08 pm

colon in text file causes hiccups

Post by JohnE »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 14
Joined: Thu Nov 01, 2007 5:08 pm

Colon hic

Post by JohnE »

Thanks Lutz, much obliged. I knew it was me (so I got that bit right).
A lesson soundly learned.

Regards, John

Locked