why does this do this?

For the Compleat Fan
Locked
tomtoo
Posts: 46
Joined: Wed Oct 28, 2009 10:00 pm

why does this do this?

Post by tomtoo »

go.lsp ...

Code: Select all

#!/usr/bin/newlisp
(set 'b (join (rest (rest (main-args))) " "))
;(exit)
a.txt ...

Code: Select all

hello
b.txt ...

Code: Select all

(hello)
$ ./go.lsp a.txt
newLISP v.10.2.1 64-bit on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.

> b
"a.txt"

$ ./go.lsp b.txt

ERR: invalid function : (hello)

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: why does this do this?

Post by johu »

Please see Command line help summary.
http://www.newlisp.org/downloads/newlis ... l#cmd_help
If a newLISP executable program is followed by parameters the program must finish with and (exit) statement, else newLISP will take command-line parameters as additional newLISP scripts to be loaded and executed.
newLISP takes a.txt and b.txt as newLISP scripts ,
because go.lsp dose not have (exit) statement.

In the first example,
After go.lsp was loaded , a.txt is loaded.
Symbol hello is evaluated as nil.

In the second example,
S-expression (hello) is evaluated and then the error occurs.

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Re: why does this do this?

Post by m35 »

I've been using newLISP for years now and I still forget about this behavior ^_^

tomtoo
Posts: 46
Joined: Wed Oct 28, 2009 10:00 pm

Re: why does this do this?

Post by tomtoo »

Yep. seems counterintuitive. I did notice the (exit) bit--in my example it was commented out, I think. I was confused because I never told newlisp to read anything. Just of the top of my head, it seems like the argument should have been treated as though it was "bob," or anything else. It just happened to be a file name.

Thanks, though. What is this "documentation" you speak of? It sounds strange and wonderful...

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: why does this do this?

Post by johu »

Sorry.

I am Japanese, and I am not good at English.
Therefore, my English might be strange.

tomtoo
Posts: 46
Joined: Wed Oct 28, 2009 10:00 pm

Re: why does this do this?

Post by tomtoo »

No need to apologize--your input was welcome and helpful, and I was joking about documentation. :-)

Locked