Confused with main-args

For the Compleat Fan
Locked
Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Confused with main-args

Post by 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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

newdep wrote: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
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

C:\Programme\newlisp>testm
("testm")
newLISP v.9.2.5 on Win32, execute 'newlisp -h' for more info.
> (exit)

C:\Programme\newlisp>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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 100
Joined: Thu Mar 10, 2005 2:27 pm
Location: Russia

Post by alex »


Locked