list-library only prints to serial port on PicoCalc


#1

On PicoCalc, (list-library) seems to not print to the PicoCalc’s internal screen, but only to the serial terminal.
That makes the Lisp Library harder to use interactively on the PicoCalc.

PS: require also behaves weirdly when nothing is connected to the serial port. It seems to not print anything when it’s done.


#2

Yes, it seems that in all versions of uLisp (not just PicoCalc), list-library is hardwired to print just to the serial port. The problem with require may be related to that.

I’ll investigate and hopefully fix it. Thanks for spotting this!


#3

I’ve just powered up my PicoCalc (running uLisp 4.8f) and installed a demo library with:

// Lisp Library
const char LispLibrary[] = R"lisplibrary(

(defun square (x) (* x x))
(defun cube (x) (* x x x))

)lisplibrary";

But then list-library seems to work fine, whether or not I have serial connected:

> (list-library)
square cube

Also, require seems to work as expected.

As I mentioned in my previous comment, list-library only writes to the normal output, and you can’t provide a stream as a second parameter as you can with other print functions.

If you can give me a case that demonstrates the problem I’ll look further.

Thanks!


#4

Hmm you’re right, your example works just fine.

It seems to actually have to do with LispLibrary strings that start with a comment. This one fails:

const char LispLibrary[] PROGMEM = R"lisplibrary(

; butlast

(defun butlast (lst)
  "(butlast lst)
Returns all but the last item in lst."
  (unless (null lst) (subseq lst 0 (1- (length lst)))))

)lisplibrary";

While this one (without the ; butlast) is ok:

const char LispLibrary[] PROGMEM = R"lisplibrary(

(defun butlast (lst)
  "(butlast lst)
Returns all but the last item in lst."
  (unless (null lst) (subseq lst 0 (1- (length lst)))))

)lisplibrary";

Could this be related to the special logic that disables echo if an input starts with a comment to allow for more robust pasting of code?


#5

I’d consider this a very low priority bug, as far as I’m concerned, given there’s an easy workaround of avoiding comments in the lisp library contents.
Probably doesn’t even need to be fixed as long as it’s documented somewhere?


#6

You’re correct about the explanation. The Lisp Library uses the same nextitem() function as when you enter programs in the REPL, and that disables serial output at a ‘;’ comment character by setting the NOECHO flag.

I think it counts as a bug if it wastes someone’s time puzzling about what’s going on!

The fix is relatively simple; a LISPLIBRARY flag that inhibits the disabling of NOECHO. I’ll put that in the next version. In the meantime you can use bracketing comments #| … |# that won’t have this effect. Thanks for finding this!


#7