Confused with main-args

Started by Cyril, November 19, 2007, 09:21:34 PM

Previous topic - Next topic

Cyril

Does it exist a reliable way to process command-line args of a newlisp script, working for both a script in a source form and a script linked with an interpreter in a single executable? In the first case real args starts from second, in the second -- from first. How to find a right one?
With newLISP you can grow your lists from the right side!

newdep

#1
How many argsuments would you like to process?



I always count from the last to the first argument to workaround this..

(instead of starting at the first/second and counting forward)



Norman.
-- (define? (Cornflakes))

Cyril

#2
Quote from: "newdep"How many argsuments would you like to process?


If only I need a fixed number of args to process, I'll not ask this question here! Believe me, I was able to count backwards before elementary school. ;-) But if I need one obligatory and one optional argument?
With newLISP you can grow your lists from the right side!

HPW

#3
Quote
C:Programmenewlisp>testm

("testm")

newLISP v.9.2.5 on Win32, execute 'newlisp -h' for more info.

> (exit)



C:Programmenewlisp>newlisp testm.lsp

("newlisp" "testm.lsp")

newLISP v.9.2.5 on Win32, execute 'newlisp -h' for more info.

> (exit)


So (=(first(main-args))"newlisp") should indicate you are running a script with the newlisp.exe. Then you set your offset for the parameter.



Edit: You must check also for a path and strip it out: (last(parse (first(main-args)) "\"))
Hans-Peter

newdep

#4
This is what i ment..(but not what you seek?) ->

You get always the absolute length and lists are limited to their length..



> $main-args

("newlisp" "bla" "one" "two" "three")

> (length $main-args)

5

> ($main-args -100)

"newlisp"

> ($main-args -10)

"newlisp"

> ($main-args -6)

"newlisp"

> ($main-args -5)

"newlisp"

>
-- (define? (Cornflakes))

alex

#5
See http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1644&highlight=">http://www.alh.net/newlisp/phpbb/viewto ... highlight=">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1644&highlight= as variant...