[CM] grace to lisp and back

Matti Koskinen mjkoskin at kolumbus.fi
Mon Nov 21 16:14:07 PST 2011


Portmidi never worked in lisp cm, so I tried another approach.

Looking at s7.html, there's a chapter about external c-programs to load as dynamic lib. I added the
cload  part in s7.c and built grace from source. All went well an I modified a socket-program found from the net.
Now grace can send and receive messages in  udp. In Clozure sockets are already available, and some lisp in CL and scheme in grace, and now the two can communicate (very basic, but works). Now I can send from grace a lisp s-expression and lisp evaluates it correctly. But the other way round is more difficult. Lists etc. are ok, but I tried to send something like this from lisp  e.g.. "(define *cmd* '(define aa '(a b c d)))" to grace. eval-string evaluates the thing, but *cmd* is in uppercase :
> *cmd*
(DEFINE AA '(A B C D))

now (eval *cmd*) gives error, because DEFINE is in uppercase. The received message is in uppercase, so I convert it first lowercase, but s7 eval sets *cmd* anyway in uppercase.  From scheme to lisp there's no problem as lisp handles symbols in uppercase ok.

Tested more: outside the function this thing works, I ran it in parts, and then added eval-string back, and now it works there too after running eval-received with eval-string removed and the func only returned the msg in lowercase.
Then running eval-strings with returned lowercase msg gave correct results, but first time running eval-string inside the function didn't work. Strange
 
(define (eval-received msg)
  (let* ((msfg1 #f)
         (msg-len (string-length msg))
         (strlower (make-string msg-len #\null)))
    (loop for i from 0 below msg-len do
          (string-set! strlower i (char-downcase (string-ref msg i))))
    (print strlower)
    ;(eval (with-input-from-string strlower (lambda () (read))))))
    (eval-string strlower)))

-matti




More information about the Cmdist mailing list