Menu

Show posts

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

Topics - frontera000

#1
newLISP in the real world / debug segfault
March 10, 2008, 11:02:28 AM
[root@andLinux ~]# newlisp

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 ~]#
#2
newLISP in the real world / setsockopt / getsockopt
December 17, 2007, 09:00:56 AM
i am in need of setting some socket options. specifically, i am interested in setting send and receive socket level buffer sizes.  these numbers can affect network throughput performance significantly. i am writing some high performance network apps and the lack of socket option API is getting in the way.  i could import shared library but i think perhaps newLISP needs these things in the socket API.  that allows more portable way of setting options (winsock and BSD style )



any thoughts?
#3
newLISP Graphics & Sound / guiserver ide output blurry
August 05, 2007, 12:24:07 PM
Hi all!

Guiserver is really great.   The IDE is fun to use. I noticed one thing though. Sometimes when I "run" the code using the > button, the output area text gets blurry (multiple lines get superimposed). Has anyone seen this?
#4
newLISP in the real world / Another newbie question
October 10, 2006, 09:27:02 AM
> (setq x '(1 '(2 3 4)))

(1 '(2 3 4))

> x

(1 '(2 3 4))

> (x 0)

1

> (x 1)

'(2 3 4)

> (first (x 1))



array, list or string expected in function first : (x 1)

> (first '(2 3 4))

2

>



Somehow quoted list works differently.
#5
newLISP in the real world / Perhaps a dumb question
October 10, 2006, 09:24:41 AM
I'm still a newbie...



(while (setq x (pop (list 1 2 3 4))) (print x))



gets into infinite loop printing 1.



Assigning (list 1 2 3 4) to something and using



(while (setq x (pop z something)) (print x))



works fine.



Why?
#6
Anything else we might add? / cond and if
September 26, 2006, 01:50:54 PM
cond and if seem to work differently:



> ((lambda (x) (if (= (x 0)  'quote) (print "found") (print "not"))) '(quote a))

> found"found"





But





 > ((lambda (x) (case (x 0) ('quote (print "found")) (true "not"))) '(quote a))

>"not"



why is this?
#7

(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))

 


when this is run foo:foo looks like this:


Quote
> foo:foo

(lambda ((foo:arg1 foo:arg2)) (setq foo:myvar foo:arg1) (setq foo:main-var



  foo:arg2))


Even if template had "MAIN:main-var".



It looks like this has to do with translateCreateSymbol() in nl-symbol.c.



I want to be able to create a function in a new context, while allowing it to access symbols from other context.  



Is there a way?
#8
Anything else we might add? / coroutines for newLISP
August 28, 2006, 05:49:40 PM
I was looking at a portable coroutine library and I found one that runs on MacOSX , linux and windows.



I played around with libCoroutine

http://www.dekorte.com/projects/opensource/libCoroutine/">http://www.dekorte.com/projects/opensou ... Coroutine/">http://www.dekorte.com/projects/opensource/libCoroutine/



I wrote a bit about it in my blog. http://sparebandwidth.blogspot.com/2006/08/play-around-with-coroutines.html">http://sparebandwidth.blogspot.com/2006 ... tines.html">http://sparebandwidth.blogspot.com/2006/08/play-around-with-coroutines.html



Anyway, I hacked newLISP source code (version 8.9.7) to add prmitives for coroutine stuff using the libCoroutine code.



It seems to work.



Basically, I create a context for each coroutine task using a code template commonly used by bunch of threads.



;;; 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))



But to run this, newLISP must be modified with my hacks.  If anyone is interested, I can make it available.  



Would you be interested in something like this Lutz?
#9
This may be a dumb thing to do:



(define-macro (foo1 ctx1 arg1)
  (context  ctx1)
  (define (foo1 arg1)
    (setq var1 arg1)))

(foo1 fooctx1 "hello1")


And it crashes newLISP.exe.


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>






Another thing is that I wanted to create foo1 in foo1 context.  But I guess while running the macro in MAIN context, creating context inside the running macro and defining new function does not make the new ones go into the newly created context -- they instead go to MAIN.  But still that crashes, so I don't know.



But the following seems to work a little better:



(define-macro (foo1 ctx1 arg1)
  (setq FOO1 (context  ctx1))
  (define (FOO1:foo1 FOO1:arg1)
    (setq FOO1:var1 FOO1:arg1)))


Basically I want to be able to create a context and a function and call that function in one expression.
#10
Anything else we might add? / trivial p2p in newLISP
August 22, 2006, 11:09:24 AM
Quote
; a trivial P2P file sharing program written in newLISP for demo purpose

;

;  based on ideas from http://www.freedom-to-tinker.com/tinyp2p.html">http://www.freedom-to-tinker.com/tinyp2p.html

; and http://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))




I put some information in my blog http://sparebandwidth.blogspot.com">http://sparebandwidth.blogspot.com
#11
newLISP in the real world / net-select
August 21, 2006, 03:15:29 PM
Is there a way to wait "forever" in net-select?



Unix select() when passed NULL timeout value will do that. Looking at the manual and source code for p_netSelect() there is no way to do that in newlisp?



perhaps make the timeout value of -1 to signify that NULL will be passed to select() call?
#12
newLISP in the real world / newlisp readline problem?
August 15, 2006, 01:18:00 PM
I think the 8.9.3 newlisp.exe binary  built with GNU readline library might be causing some trouble.  Normally I use Linux and never noticed any problems before but when running windows newlisp, I noticed that sending a long expression can cause trouble.  For example, this code from clock.lsp


Quote


(set 'digits '((" ### " "  #  " "#####" "#####" "#   #" "#####" "#    " "#####" "#####" " ### "

"     ")("#   #" " ##  " "    #" "    #" "#   #" "#    " "#    " "    #" "#   #" "#   #" "  #  "

)("#   #" "  #  " "#####" " ### " "#####" "#####" "#####" "   ##" "#####" " ####" "     ")("#  

#" "  #  " "#    " "    #" "    #" "    #" "#   #" "   # " "#   #" "   # " "  #  ")(" ### " "  #

  " "#####" "#####" "    #" "#####" "#####" "   # " "#####" "  #  " "     ")))




is OK when loaded from file or pasted into newlisp-tk and evaluated. But if you paste into the newlisp.exe cmd shell it will not work.



It is only one example. I have had different problems with inputting into newlisp.exe by sending it a lot of text.



Another thing I noticed is that when running newlisp.exe inside emacs on Windows the prompt does not appear.  It seems to have something to do with GNU readline.  This is no problem on Linux by the way.



Is this is a bug report?
#13
Anything else we might add? / fork
August 15, 2006, 01:07:00 PM
I am a bit confused about fork. It seems to be based on Unix fork() which creates a process. But manual says something about thread which is suggestive of light-weight process or threads as in pthread.  Normally thread is something that shares memory space with other threads, not a complete process with its own memory space.



Many languages have thread support and they all use light-weight threads, not processes.  I am wondering perhaps we should clarify the terminology in the manul or perhaps I am misguided. Is it the intent of newLISP to use processes for forking off an expression? I see value in that and it is useful. I am just wondering if there is a plan for supporting proper threads in the future and any clarifications on this. Java and C# have thread support in the language. Perl, python, ruby, etc. have support libraries. Lua has a coroutine that is interesting in that it can be used for multi-tasking as well as a generator. I am thinking it might be tricky to implement a coroutine in newLISP without support for continuation, but it might be interesting to have that feature.
#14
Anything else we might add? / tk image display problem
August 07, 2006, 04:10:33 PM
hi



i am a novice newlisp hobbyist.


Quoteset myimage [image create photo -file /home/bob/hacks/xyz.gif]



 label .imagedisplayer -image $myimage

 pack .imagedisplayer


when run with wish, this displays image xyz.gif



i tried to do the same in newlisp-tk
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)




when newlisp-tk is used to run this file it does not work.



any help? thanks.
#15
i am new to newlisp.



section 6 of Design Elements and Patterns in newLISP

has the following:



(set 'data:data '(a b c d e f g h))



(define (change db i value)

    (nth-set (db i) value))



(change data 3 999)



but db is undefined when change is called.

ERR:value expected in function nth-set : (db i)



can anyone tell me why?