RFC open on newLISP documentation

Notices and updates
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

read-file

Post by newdep »

Hello Lutz,


Perhaps a remark on the manual for 'read-file, as from 9.0.0 there are more
options with read-file i think its a good idea to mention these ->


* read-file used from within a script always will execute the file (if its a newlisp file)
that its reading, except when the script that uses the read-file function has
an explicit (exit).

But because read-file now also has "file://" support , there is a way around
the use of an (exit). The NOT use of an (exit) is often done during testing
of a script.

;; this will execute the file when no (exit) is supplied afterwards.
(setq buffer (read-file (main-args 2)))

;; this also will execute the file when no (exit) is supplied afterwards.
(setq buffer (read-file (append "file://" (main-args 2))))

;; this will NOT execute the file!, BUT 1 backdraw, you cant use
;; an append on file:// + filename, that will execute again, as above!
(setq buffer (read-file "file://myscript.lsp"))


PS: the explicit (exit) actualy goes for read-buffer too.


a global workarround on the automatic execute is i.e.the example below
within a script while its executed from the command-line like ->

---script
#!/usr/bin/newlisp
(setq buffer (read-file (rest (chop (main-args 2)))))

---command line
./prog.lsp {readme.lsp}



Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

'read-file' does not execute any files ist just reads them, and there is nothing special about the "file://" prefix.

What you arte experiencing is the fact that your first script, because it does not exit, consumes the argument of the second program. For this reason it is always important that a script exits. If a script does not exit than newlisp will try and load arguments which where meant to be consumed by the script.

Let me explain with an example:

Code: Select all

#!/usr/bin/newlisp
# this is program: main

(println (main-args))
(set 'buff (append "file://" (main-args 2)))

(exit)
and the second program:

Code: Select all

;program: test
(println "hello world")
(exit)
now run it from the shell:

Code: Select all

~> ./main test
("/usr/bin/newlisp" "./main" "test")
~>
Only the statement in main is executed showing the contents of main-args. Then the (exit) statement in main keeps newLISP from loading test (which already has been read by main) and it exits.

Now lets delete the exit statement in main and run again:

Code: Select all

~> ./main test
("/usr/bin/newlisp" "./main" "test")
hello world
~> 
newLISP loads main and executes the statements in main reading the file test, then because the exit in main is missing, newLISP also loads the second file test and executes the (println ...) statement.

You see nothing is executed here by 'read-line'. Never forget to put an (exit) statement at the end of your scripts, or newLISP will try to consume the comand line arguments, which where meant for the script.

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Thanks Lutz, for the explenation...
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Latest manual... some small misplaced "" in net-eval

example:

(net-eval "192.168.1.94" 4711 "(+ 3 4")) → 7
(net-eval "192.168.1.94" 4711 "(+ 3 4") 1) → nil ; timeout to short
(net-eval "192.168.1.94" 4711 "(+ 3 4") 1000) → 7


should be ->

example:

(net-eval "192.168.1.94" 4711 "(+ 3 4)" ) → 7
(net-eval "192.168.1.94" 4711 "(+ 3 4)" 1) → nil ; timeout to short
(net-eval "192.168.1.94" 4711 "(+ 3 4)" 1000) → 7
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Remarkt for the manual since the introduction of UNIX local sockets!

Do not use "newlisp -c -d 4177 myfile.lsp is you want to load the file "myfile.lsp"
because this will remove the file "myfile.lsp" and create a local UNIX socket called "myfile.lsp="

Use "newlisp -c myfile.lsp -d 4177" if you want to load a file in deamon mode!

just lost 1/2 gig of data ;-) (long life the backup system "copy-file ;-)
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

small remark

Post by newdep »

9.2.5 manual section "directory"

(directory "." "\\.c") → ("foo.c" "bar.c")
(directory "." {\.c}) → ("foo.c" "bar.c")

should be ->

(directory "." "\.c$") → ("foo.c" "bar.c")
(directory "." {\.c$}) → ("foo.c" "bar.c")
-- (define? (Cornflakes))

Locked