newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Cyril on November 19, 2007, 09:21:34 PM

Title: Confused with main-args
Post by: Cyril on November 19, 2007, 09:21:34 PM
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?
Title:
Post by: newdep on November 20, 2007, 12:48:37 AM
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.
Title:
Post by: Cyril on November 20, 2007, 08:40:58 PM
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?
Title:
Post by: HPW on November 20, 2007, 10:49:44 PM
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)) "\"))
Title:
Post by: newdep on November 21, 2007, 12:20:08 AM
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"

>
Title:
Post by: alex on November 21, 2007, 01:15:44 AM
See http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1644&highlight= as variant...