I’m encountering a problem when testing my uLisp code on a Teensy 4.1 (or Pico) via Minicom. I paste my lisp code, and test, and everything works fine (yay!). But if I have to modify that code and repaste it into minicom, it doesn’t work anymore (even if I makunbound globals). I actually have to remove/reinsert the teensy 4.1 in order to start over…
First try after pasting my code…
59556> y
("$c = $." "$v x y $.")
59556> (tokenize y)
(("$c" . mmconst) ("=" . mmlabel) ("$." . mmend) ("$v" . mmvar) ("x" . mmlabel) ("y" . mmlabel) ("$." . mmend))
But if I repaste the same code…
59556> y
("$c = $." "$v x y $.")
59556> (tokenize y)
nil
Note that available cells is the same after pasting/repasting my code into minicom. In this example, I just pasted in the very same code.
I’m not sure what could be happening… I’m new to uLisp (and new to Lisp, also) so don’t hesitate to let me know if I’m doing something wrong.
Here’s my code; sorry it’s lengthy; I’m not asking anyone to troubleshoot it but so you can test what I’m doing yourself… (The Tokenize routine “lex’s” a list of strings containing MetaMath code. In this example, Y contains a couple of simple MetaMath statements.)
(defvar mmkeywords
'((#\[ . mmbgninc) (#\] . mmendinc)
(#\c . mmconst) (#\. . mmend)
(#\{ . mmbgnblock) (#\} . mmendblock)
(#\v . mmvar) (#\d . mmdisjoint)
(#\f . mmfloat) (#\e . mmessential)
(#\a . mmaxiom) (#\p . mmproof1)
(#\= . mmproof2))
)
(defvar mmwhitespace '(#\Tab #\Newline #\Return #\Space))
(defvar y '("$c = $." "$v x y $."))
(defun tokenize (stringlist)
(let (tokenlist c nextc label token dpair skip)
(setq tokenlist '())
(setq label '"")
(setq skip nil)
(dolist (aline stringlist)
(dotimes (i (length aline))
(cond
(skip
(setq skip nil)
)
(t
(setq c (char aline i))
(cond
((member c mmwhitespace)
(when (> (length label) 0)
(setq dpair (cons label 'mmlabel))
(setq tokenlist (reverse (cons dpair (reverse tokenlist))))
(setq label '"")
)
)
((and (eq c #\$) (> (length aline) i))
(setq nextc (char aline (+ i 1)))
(setq skip t)
(setq token (cdr (assoc nextc mmkeywords)))
(cond
(token
(setq label (concatenate 'string (string c) (string nextc)))
(setq dpair (cons label token))
(setq tokenlist (reverse (cons dpair (reverse tokenlist))))
(setq label '"")
)
(t
(format t "illegal character after $: ~a~%" nextc)
(break)
)
)
)
((and (eq c #\$) (<= (length aline) i))
(format t "illegal $ at end of line~%")
(break)
)
(t
(setq label (concatenate 'string (string label) (string c)))
)
)
)
)
)
(when (> (length label) 0)
(setq dpair (cons label 'mmlabel))
(setq tokenlist (reverse (cons dpair (reverse tokenlist))))
(setq label '"")
)
)
(return tokenlist)
)
)