RFC open on newLISP documentation

Started by kazemori, November 28, 2003, 02:34:32 PM

Previous topic - Next topic

Lutz

#270
I agree, those examples explain it a lot better than the words. I will put in your examples, but leave it up to Michael to shorten the English explaining the different synyaxes when he comes to letter S.



Lutz

newdep

#271
Yes he's doing a nice job ;-) quite some work though!





Here is another semphore example... perhpas usefull ->





;;

;; File     : sem.lsp

;; Comment  : fork with semaphore

;;



;; semaphore actions

(constant 'wait -1 'run 1 'release 0)



(define (shout counter channel)

    (while (<= counter 20)

    (begin

        (write-line (string counter) channel)

        (sleep 100)

        (semaphore sid wait)

        (inc 'counter))))



(define (listen channel)

    (setq y "")

    (while (!= y "20")

     (begin

        (println "* " (setq y (read-line channel)))

        (sleep 100)

        (semaphore sid run))))



;; create io communication pipes

(map set '(in out) (pipe))



;; create a semaphore 'sid

(setq sid (semaphore))



;; init the semaphore to inactive

(semaphore sid)



;; fork the functions

(fork (shout 0 out))

(fork (listen in))



;; release the sid system wide!

(semaphore sid 0)



(exit)







The output is this ->



# newlisp sem.lsp

* 0

* 1

* 2

* 3

* 4

* 5

* 6

* 7

* 8

* 9

* 10

* 11

* 12

* 13

* 14

* 15

* 16

* 17

* 18

* 19

* 20
-- (define? (Cornflakes))

HPW

#272
8.9.8 doc for 'int'


QuoteIf str is invalid, integer returns nil as a default value if not otherwise specified.


should read:


QuoteIf str is invalid, int returns nil as a default value if not otherwise specified.


since integer is deprecated.
Hans-Peter

m i c h a e l

#273
Hans-Peter: Thank you for catching this. The manual has been updated with your change.



Norman: I've made a note to include your code changes and intend to add them when we get to the S's. Thanks for the great examples!  (I learn best from examples :-)





m i c h a e l

Lutz

#274
Rev 12 of the newLISP Users Manual and Reference is online:



http://newlisp.org/downloads/newlisp_manual.html">http://newlisp.org/downloads/newlisp_manual.html



Its includes the changes from 'integer' -> 'int'



Thanks to Michael for edits in the 'N' letter



Lutz

newdep

#275
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

#276
'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:



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

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

(exit)


and the second program:


;program: test
(println "hello world")
(exit)


now run it from the shell:


~> ./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:


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

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

newdep

#278
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

#279
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

#280
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))