Re: load recursively

2010-09-08 Thread Alexander Burger
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
expressions.

   ./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).

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


Re: load recursively

2010-09-08 Thread Jon Kleiser
Hi Alex,

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

/Jon

> Hi Jon,
>
>> I still don't get the difference this T makes. If I want to load two
>> files
>> with one 'load' call, when should I include the T?
>
> To load two files, you can simply write (load "file1" "file2").
>
> The T is there to get access to the remaining command line arguments.
> This is typically needed in executable scripts.
>
> For example, let's take the script
>
>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
>(load "@lib/misc.l")
>(doSomething)
>(bye)
>
> This script completely ignores any possible command line arguments.
>
> So you could 'load' the arguments, e.g.
>
>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
>(load "@lib/misc.l")
>(initSomething)
>(load T)  # Load the remaining args
>(doSomething)
>(bye)
>
>
> For example, the build script for the 64-bit version uses this (see
> "src64/mkAsm"). It first loads "@lib/misc.l", then extracts some further
> command line arguments with 'opt', then 'load's some library files and
> in the last line "defs.l" , "sys/xxx.defs.l", and finally the actual
> source files using 'T'.
>
>
> (load T) is similar to (apply load (argv)), with the difference that it
> will "eat" the arguments, while 'argv' leaves them in place. For
> example, the following script (let's call it "a")
>
>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
>(apply load (argv))
>(load T)
>(bye)
>
> demonstrates this:
>
>$ ./a -"println 123"
>123
>123
>
> Cheers,
> - Alex


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


Re: load recursively

2010-09-08 Thread Alexander Burger
Hi Jon,

> I still don't get the difference this T makes. If I want to load two files
> with one 'load' call, when should I include the T?

To load two files, you can simply write (load "file1" "file2").

The T is there to get access to the remaining command line arguments.
This is typically needed in executable scripts.

For example, let's take the script

   #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
   (load "@lib/misc.l")
   (doSomething)
   (bye)

This script completely ignores any possible command line arguments.

So you could 'load' the arguments, e.g.

   #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
   (load "@lib/misc.l")
   (initSomething)
   (load T)  # Load the remaining args
   (doSomething)
   (bye)


For example, the build script for the 64-bit version uses this (see
"src64/mkAsm"). It first loads "@lib/misc.l", then extracts some further
command line arguments with 'opt', then 'load's some library files and
in the last line "defs.l" , "sys/xxx.defs.l", and finally the actual
source files using 'T'.


(load T) is similar to (apply load (argv)), with the difference that it
will "eat" the arguments, while 'argv' leaves them in place. For
example, the following script (let's call it "a")

   #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
   (apply load (argv))
   (load T)
   (bye)

demonstrates this:

   $ ./a -"println 123"
   123
   123

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


Re: load recursively

2010-09-08 Thread Jon Kleiser
Hi Alex,

> Hi Jon,
>
>> In the docs on the 'load' function I read that, "When any is T, all
>> remaining command line arguments are loaded recursively." Can somebody
>> explain what this recursive loading is?
>
> There is nothing special about the word "recursive" here. It could as
> well say "When any is T, all remaining command line arguments are
> loaded", or ".. are loaded in turn".
>
> Do you think this is misleading? What would be a better way to describe
> it?
>
> Cheers,
> - Alex

I still don't get the difference this T makes. If I want to load two files
with one 'load' call, when should I include the T?

/Jon

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


Re: load recursively

2010-09-08 Thread Alexander Burger
Hi Jon,

> In the docs on the 'load' function I read that, "When any is T, all
> remaining command line arguments are loaded recursively." Can somebody
> explain what this recursive loading is?

There is nothing special about the word "recursive" here. It could as
well say "When any is T, all remaining command line arguments are
loaded", or ".. are loaded in turn".

Do you think this is misleading? What would be a better way to describe
it?

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