Re: file function purpose

2018-10-17 Thread Curtis
Thanks for taking the time to explain. I understand, now.

On Wed, Oct 17, 2018, 4:43 PM  wrote:

> Typo, in my example (car (file)) of course returns "somepath/" (contains
> the directory separator '/').
>
> You can easily test the behaviour by creating a file foo.l containing
> the following single line:
> (out NIL (prinl (car (file
>
> Then start pil repl and load this file once directly without a path and
> once with its absolute path:
> : (load "foo.l")
> /
> -> "./"
> : (load "/home/user/foo.l")
> /home/user/
> -> "/home/user/"
>
> Notice here the output is first the print and then -> prefixes the
> return value of the loaded script, which of course is the same string we
> just printed.
>
> Am 2018-10-17 22:27, schrieb andr...@itship.ch:
> > So during execution of (load "somepath/somefile.l") the code (car
> > (file)) returns "somepath".
> > For this the (car (file)) has to be placed within somefile.l on top
> > level (code that gets executed directly during the load, not e.g. as
> > part of a function definition unless it is called as `read macro).
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: file function purpose

2018-10-17 Thread andreas
Typo, in my example (car (file)) of course returns "somepath/" (contains 
the directory separator '/').


You can easily test the behaviour by creating a file foo.l containing 
the following single line:

(out NIL (prinl (car (file

Then start pil repl and load this file once directly without a path and 
once with its absolute path:

: (load "foo.l")
/
-> "./"
: (load "/home/user/foo.l")
/home/user/
-> "/home/user/"

Notice here the output is first the print and then -> prefixes the 
return value of the loaded script, which of course is the same string we 
just printed.


Am 2018-10-17 22:27, schrieb andr...@itship.ch:

So during execution of (load "somepath/somefile.l") the code (car
(file)) returns "somepath".
For this the (car (file)) has to be placed within somefile.l on top
level (code that gets executed directly during the load, not e.g. as
part of a function definition unless it is called as `read macro).


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: file function purpose

2018-10-17 Thread andreas

Hi Curtis

The purpose of (file) and the given examples makes only really sense in 
a specific context, which indeed is not further explained there.

Additionally, for understanding this it's important to know that:

During execution of (load), the loaded file is the current input stream.

Meant is the "read" step of the picolisp interpreter (the R in REPL), 
when the source code is turned into the binary picolisp representation 
within memory (pointers and cells).
So during execution of (load "somepath/somefile.l") the code (car 
(file)) returns "somepath".
For this the (car (file)) has to be placed within somefile.l on top 
level (code that gets executed directly during the load, not e.g. as 
part of a function definition unless it is called as `read macro).


This way the loaded file can get loaded using a indirect path, and the 
loaded file can still find out how it got loaded (via which path) and so 
re-use that path to load another file directly in the same directory as 
in (load (pack (car (file)) "localFile.l")) or the path information can 
be stored in a global variable as in (setq *Nanomsg (pack (car (file)) 
"lib/libnanomsg.so")).


When only (load)ing files from the same directory (no subdirectories), 
it has indeed no effect.
But when this is used in a file meant to be further included in other 
projects which do not necessarily (load) it using always the same path, 
this construct allows that the included file still can do further 
loading with paths relative to the files own location and the including 
project has not to care about path/directory structure for additional 
indirectly loaded files.


The alternative would be to use (chdir "somepath/" (load "somefile.l")) 
in the including project so that during execution of (load "somefile.l") 
the current directory is guaranteed to be the local directory of 
"somefile.l".


Best regards,
beneroth


Am 2018-10-17 20:59, schrieb Curtis:

What I mean to say is, it looks as though, from where "file" is being
called, it would always return NIL.
On Wed, Oct 17, 2018 at 1:19 PM Curtis  
wrote:


I'm a little confused by the purpose of the (file) function's use in
the example given here: https://software-lab.de/doc/refF.html#file
The example is: (load (pack (car (file)) "localFile.l"))  # Load a
file in same directory

But, doesn't (load "localFile.l") do the same thing?

I noticed the same combination of pack, car, file here:
https://github.com/aw/picolisp-nanomsg/blob/master/EXPLAIN.md
(setq *Nanomsg (pack (car (file)) "lib/libnanomsg.so"))

Isn't it the same thing as just (setq *Nanomsg "lib/libnanomsg.so"))?


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: file function purpose

2018-10-17 Thread Curtis
What I mean to say is, it looks as though, from where "file" is being
called, it would always return NIL.
On Wed, Oct 17, 2018 at 1:19 PM Curtis  wrote:
>
> I'm a little confused by the purpose of the (file) function's use in
> the example given here: https://software-lab.de/doc/refF.html#file
> The example is: (load (pack (car (file)) "localFile.l"))  # Load a
> file in same directory
>
> But, doesn't (load "localFile.l") do the same thing?
>
> I noticed the same combination of pack, car, file here:
> https://github.com/aw/picolisp-nanomsg/blob/master/EXPLAIN.md
> (setq *Nanomsg (pack (car (file)) "lib/libnanomsg.so"))
>
> Isn't it the same thing as just (setq *Nanomsg "lib/libnanomsg.so"))?

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


file function purpose

2018-10-17 Thread Curtis
I'm a little confused by the purpose of the (file) function's use in
the example given here: https://software-lab.de/doc/refF.html#file
The example is: (load (pack (car (file)) "localFile.l"))  # Load a
file in same directory

But, doesn't (load "localFile.l") do the same thing?

I noticed the same combination of pack, car, file here:
https://github.com/aw/picolisp-nanomsg/blob/master/EXPLAIN.md
(setq *Nanomsg (pack (car (file)) "lib/libnanomsg.so"))

Isn't it the same thing as just (setq *Nanomsg "lib/libnanomsg.so"))?

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe