Infinite precision arithmetic


#1

A new example showing how to provide infinite precision integer arithmetic in uLisp:

http://www.ulisp.com/show?1FHA


#2

no division or modulus operator though :(. A 2.5k arduino is maybe too limited but on a bigger part it would be nice to have real bignums, at least as a compile time option.


#3

Bignums are definitely a cool feature of Common Lisp, but I’m not sure how useful they would be in uLisp, which is mainly aimed at control and measurement applications.


#4

Interesting. I wonder if you could make a post sometime about the philosophy of uLisp. I usually think of MCU control/measurement applications as using mostly static storage areas with numeric data, while the strengths of Lisp are dynamic storage management and handling symbolic and non-numeric data. It’s really cool to have a Lisp so small that it can run on an Atmega328 but I wonder where its strengths show up on such small cpus. Anyway you’ve done a lot of nice work!


#5

Have you had a look at the uLisp site? That may explain more about the philosophy of uLisp:

http://www.ulisp.com/

Many control/measurement applications could benefit from Lisp’s ability to handle complex data structures, such as a robot mapping an environment, or a GPS interface to find the shortest route between two locations.


#6

Yes, I did look at the uLisp site and it’s very well done, but I had thought that the route finding (etc) examples were more in the spirit of demos than applications. Until now I had not really thought of programming these tiny parts in Lisp for anything serious. I’ve been playing with Forth which is also interactive, but it’s a much lower level language than Lisp. I’ve mostly been interested in small dynamic languages (Lisp, Lua, MicroPython etc.) for processors a few sizes up from the Atmega (ARM Cortex M3 or M4 level, say). uLisp casts a new light on things.

Added: one philosophical point that interests me is whether uLisp is intended specifically for the Atmega cpus, or if other ones are interesting too.


#7

I’ve targeted the AVR CPUs because they are are easy to embed in projects and wire up to peripherals. For example, it’s feasible to write a digital clock programmed in Lisp using the ATmega328:

http://www.technoblogy.com/show?OK8

On any ARM CPU that supports Unix a better choice would be Clozure Common Lisp:

http://lispm.de/ccl

It should be possible to port uLisp to any other CPU with at least 2K of RAM and 32K of program space. Some of the MSP430 range would qualify.


#8

Unix would be on a much larger class of cpu. I’m thinking of ARM embedded MCUs like on the Teensy 3.2, which has 256k of flash and 64k of ram, or maybe the very cheap Maple Mini clones that have 64k of flash and 20k of ram (link). I think uLisp seems promising for those. The ESP8266 is also interesting (wemos.cc D1 for example).

I notice that the compaction function for writing out the program image appears to use quadratic time in the amount of memory, so that might be an issue on larger cpus. I’ll try to rewrite it to use linear time (there are various clever algorithms for that from Lisp lore).


#9

Yes, the compaction function was a quick fix - I’d be interested to see a better version. Thanks!


#12

Note that the compaction function compactimage() is only called when you do (save-image), and not on every garbage collection.


#13

Yes, I did notice that, but still I could imagine it getting pretty slow with a bigger part. Also a compacting gc would be useful if there was variable length data like strings. (It would need a different algorithm than the one I half-posted earlier though).