setting (main-args)

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

setting (main-args)

Post by newdep »

Hi Lutz,

(main-args) is used as a copy from argv in the newlisp.c code..

I would like to manipulate the (main-args) during newlisp startup.

But this is not that easy ;-)

If you take i.e. my new option called "-o" and use it like this ->

newlisp -o "(chop (main-args))" it will nicely print the chopped args
but if I then type (main-args) it gives me still the main argv values.

Do you have any idea how to manipulate the (main-args) during startup?

Yes that sounds strange, but emagine newlisp.exe being executed from another
shell or program that always sends its own args too.. then newlisp does not have
its own args but also the ones from the shell or program that executed it...


Regards, Norman
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The original argv[] list is stored in a protecteed system symbol $main-args. But you can modify it as the following dialog shows:

Code: Select all

~> newlisp a b c d e f 
newLISP v.8.9.3 on OSX UTF-8, execute 'newlisp -h' for more info.

> (main-args)
("newlisp" "a" "b" "c" "d" "e" "f")
> (constant '$main-args (chop (main-args)))
("newlisp" "a" "b" "c" "d" "e")
> (main-args)
("newlisp" "a" "b" "c" "d" "e")
> 
Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

HA thanks..great solution! that I did not think of that..
(thats because i probably did not know of $main-args ;-)
-- (define? (Cornflakes))

Locked