newLISP v.9.3.3 on Linux IPv4, execute 'newlisp -h' for more info.
> (define ( x y ) (setq x y ))
(lambda (y) (setq x y))
> (debug (x 1))
-----
(define (x y)
#(setq x y)#)
[-> 3 ] s|tep n|ext c|ont q|uit > n
Segmentation fault
[root@andLinux ~]#
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(setq main-var 1)
(define (make-function-context)
(let (temp (append (lambda) (list (first (args 1))) (rest (args 1))))
(def-new 'temp (sym (args 0) (args 0)))))
(define (function-template (arg1 arg2))
(setq myvar arg1)
(setq MAIN:main-var arg2))
(make-function-context 'foo (0 function-template))
Quote
> foo:foo
(lambda ((foo:arg1 foo:arg2)) (setq foo:myvar foo:arg1) (setq foo:main-var
foo:arg2))
;;; coroutine testing
(define (make-coroutine)
(let (temp (append (lambda) (list (first (args 1))) (rest (args 1))))
(def-new 'temp (sym (args 0) (args 0)))))
(define (coroutine-generic myname me him)
(begin
(setq taskname myname)
(while 1
(println (format "%s bytes left on stack %d" taskname (coroutine-bytes-left-on-stack me) ))
(coroutine-switch me him)
(sleep 1000))))
(define (coroutine1)
(setq task2-handle (coroutine-create))
(make-coroutine 'task2 (0 coroutine-generic))
(setq task3-handle (coroutine-create))
(make-coroutine 'task3 (0 coroutine-generic))
(setq task4-handle (coroutine-create))
(make-coroutine 'task4 (0 coroutine-generic))
(coroutine-start task1-handle task2-handle (task2:task2 "task2" task2-handle task1-handle))
(coroutine-start task1-handle task3-handle (task3:task3 "task3" task3-handle task1-handle))
(coroutine-start task1-handle task4-handle (task4:task4 "task4" task4-handle task1-handle))
(setq task-list '(task2-handle task3-handle task4-handle))
(setq num 0)
(while (< num 20)
(println (format "coroutine1: bytes left on stack %d" (coroutine-bytes-left-on-stack task1-handle) ))
(coroutine-switch task1-handle (task-list (int (first (random 0 3 1)))))
(setq num (+ 1 num))
(sleep 1000)))
(setq task-main-handle (coroutine-main))
(setq task1-handle (coroutine-create))
(coroutine-start task-main-handle task1-handle (coroutine1))
(define-macro (foo1 ctx1 arg1)
(context ctx1)
(define (foo1 arg1)
(setq var1 arg1)))
(foo1 fooctx1 "hello1")
Quote
> (debug (foo1 fooctxt1 "hello1"))
-----
(define-macro (foo1 ctx1 arg1)
#(context ctx1)#
(define (foo1 arg1)
(setq var1 arg1)))
[-> 3 ] s|tep n|ext c|ont q|uit > ctx1
fooctxt1
[-> 3 ] s|tep n|ext c|ont q|uit > s
-----
(define-macro (MAIN:foo1 MAIN:ctx1 MAIN:arg1)
#(context MAIN:ctx1)#
(define (MAIN:foo1 MAIN:arg1)
(setq MAIN:var1 MAIN:arg1)))
RESULT: fooctxt1
[<3> s
-----
(define-macro (MAIN:foo1 MAIN:ctx1 MAIN:arg1)
(context MAIN:ctx1)
#(define (MAIN:foo1 MAIN:arg1)
(setq MAIN:var1 MAIN:arg1))#)
[-> 3 fooctxt1] s|tep n|ext c|ont q|uit > s
***newLISP Crashes here *****
C:Documents and SettingsOwner>
(define-macro (foo1 ctx1 arg1)
(setq FOO1 (context ctx1))
(define (FOO1:foo1 FOO1:arg1)
(setq FOO1:var1 FOO1:arg1)))
Quote
; a trivial P2P file sharing program written in newLISP for demo purpose
;
; based on ideas fromhttp://www.freedom-to-tinker.com/tinyp2p.html">http://www.freedom-to-tinker.com/tinyp2p.html
; andhttp://ansuz.sooke.bc.ca/software/molester/">http://ansuz.sooke.bc.ca/software/molester/ and
;http://ansuz.sooke.bc.ca/software/molester/2005010301.php"> http://ansuz.sooke.bc.ca/software/moles ... 010301.php">http://ansuz.sooke.bc.ca/software/molester/2005010301.php
;
; command reference
; i/ advertise presence of your node to the peer
; g<filename>/ requests a file
; f<message> forward to peers
; h/ gets list of all peers
;
; used internally
; e<filename>/ expect a file
; x sent after receiving a file to make sure
;
; the program below is a toy, not a serious p2p program.
;
; differences from original mole-ster:
; use of 'x' -- to allow data receipt on receiving side when file is sent
; data is read in 8k chunks at a time. this is to avoid having to read
; the entire file into a buffer before writing. it allows larger files to be
; transferred.
;
; more more information refer to the original mole-ster web sites.
;
(context 'P2P)
(constant 'SIGINT 2)
(define (interrupted)
(println "interruted by user!")
(exit))
(signal SIGINT interrupted)
(set 'my-address "")
(set 'my-password "")
(set 'peers '())
(define (get-addr addr-and-port) (regex "(.*):(.*)" addr-and-port) $1)
(define (get-port addr-and-port) (regex "(.*):(.*)" addr-and-port) (integer $2))
(define (op-send dest-addr source-addr filename data)
(if (set 'socket (net-connect (get-addr dest-addr) (get-port dest-addr)))
(begin
(net-send socket (format "%s %s %s/" my-password source-addr filename))
(net-send socket data )
(if (!= data "")
(net-receive socket 'buf 1))
(close socket))))
(define (P2P:P2P my-password peer-address my-address commands )
(set 'peers (append peers (list peer-address)))
(dolist (cmd commands) (op-send peer-address my-address cmd ""))
(set 'socket (net-listen (get-port my-address)))
(while true
(while (and (not (net-error)) (not (net-select socket "read" 1000)))
(if (net-error) (print (net-error))))
(set 'peer-socket (net-accept socket)) (net-receive peer-socket 'buf 1024 "/")
(regex "^([a-zA-Z0-9]*) ([0-9:.]*) ([e-i])([^/]*)(/)" buf)
(set 'peer-password $1)
(set 'peer-address $2)
(set 'peer-command $3)
(set 'requested-filename $4)
(set 'data $6)
(if (= peer-password my-password)
(case peer-command
("e" (begin
(set 'finished false)
(while (not finished)
(while (and (not (net-error)) (not (net-select peer-socket "read" 1000)))
(if (net-error) (print (net-error))))
(if (!= nil (net-receive peer-socket 'input-data 8192))
(begin
(append-file requested-filename input-data)
(set 'finished true)))
(net-send socket "x")))
("f" (dolist (peer peers) (op-send peer my-address requested-filename data)))
("g" (op-send peer-address my-address (append "e" requested-filename)
(read-file requested-filename)))
("h" (dolist (peer peers) (op-send peer-address peer "i" "")))
("i" (append peers peer-address))))
(close peer-socket)))
(context 'MAIN)
(P2P:P2P (main-args 2) (main-args 3) (main-args 4) (slice (main-args) 5 -1))
Quote
(set 'digits '((" ### " " # " "#####" "#####" "# #" "#####" "# " "#####" "#####" " ### "
" ")("# #" " ## " " #" " #" "# #" "# " "# " " #" "# #" "# #" " # "
)("# #" " # " "#####" " ### " "#####" "#####" "#####" " ##" "#####" " ####" " ")("#
#" " # " "# " " #" " #" " #" "# #" " # " "# #" " # " " # ")(" ### " " #
" "#####" "#####" " #" "#####" "#####" " # " "#####" " # " " ")))
set myimage [image create photo -file /home/bob/hacks/xyz.gif]Quote
label .imagedisplayer -image $myimage
pack .imagedisplayer
Quote
(context 'fiv)
(define (fiv4)
(tk [text]
set myimage [image create photo -file /home/bob/hacks/xyz.gif]
label .imagedisplayer -image $myimage
pack .imagedisplayer
[/text]))
(context 'MAIN)
(tk "wm withdraw .")
(fiv:fiv4)