Hi Jon,

> Thanks for the extensive explanation! I'll work a bit on this later to
> make sure I understand every part of it. ;-)

OK, perhaps I should also elaborate a little on the background:

As you know, if you start picoLisp with ./p or ./dbg, it 'load's all
arguments in sequence, then displays a ':' prompt and starts the REPL.
Arguments starting with a hyphen are direcly evaluated as Lisp

   ./dbg a.l -"println 123" b.l

This will load "a.l", print the number 123, then load "b.l", and then
drop into the REPL.

Instead, you could also simply start ./dbg, and then do the same as:

   : (load "a.l" "-println 123" "b.l")

In case of a script, however, we must be aware of what Unix does with
it. If the first line starts with '#!', the next token is used as the
path to an executable program (e.g. /usr/bin/picolisp), and a single
further argument (e.g. /usr/lib/picolisp/lib.l) that is allowed on that
line, is passed to that program.

The second argument to that program will be the script itself. So what
/usr/bin/picolisp sees as arguments are first /usr/lib/picolisp/lib.l,
and then the script file. As the first line of the script starts with a
'#', it is ignored as a comment, the rest is executed.

Now, if as in the example (bye) is executed at the end of that script
(which is typical for stand-alone scripts), the script will terminate
without looking at further arguments. They are simply ignored.

If the script does not call (bye), then the following arguments will be
passed to the program as usual, resulting in argument number three, four
etc. But this will take place _after_ the script was completely
interpreted. It the script wants to do something with its arguments, it
is responsible to 'load' these arguments, or process them otherwise.
This can be done with (opt) to retrieve the next argument, with (argv)
to get the complete list of argument strings, or with (load T) to let it
handle them in the "standard" way, i.e. execute them according to the
rules of 'load' (file vs. Lisp expression).

- Alex
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to