garbage-collectionlisp

Lisp without a Garbage Collector for low level programming


Is there a dialect of Lisp which has Lisp semantics and low level manipulation of C? Something like retrieving an arbitrary memory address (either virtual or physical memory) and do something with it; pointer to hardware device...

For example:

(defvar a '(1 2 3 4)) ;; I have a list
(defvar b (cdr a)) ;; b is the cdr of a. But I want b to
                   ;;  actually refer to the tail of a
(setf b '(4 5 6)) ;; b now has new value, but a remains unchanged

What I want is to use Lisp to express low level problems. For example, how do I control individual bytes and bits when running Lisp on bare metal? In C, I can get a pointer and perform pointer arithmetic to point to anywhere I want in a memory space (virtual or physical). Pointer can also point to devices and arbitrary defined addresses by hardware designer.

Why do I need this? Well, I want to learn how to use Lisp with low level programming. In the long run, I want to write a simple OS for learning, but in Lisp. I will write one in C as well for initial understandings, but if I can only write in C, how can I be sure and say I understand how to implement an OS? I think I only truly understand how to implement an OS if I can write it in other language than C to make sure.

I don't want to write something like C core for the OS and Lisp for everything else.


Solution

  • As I mentioned in my comment, most Lisp implementations can do that. Common Lisp already has all kinds of bit calculation functions. All implementations provide interfaces to low-level operations.

    You can write web servers, compilers, window managers, etc. in Lisp. Many Lisp systems are written in Lisp and thus need primitives to write/read to/from memory.

    You just need to take some Lisp implementation and read the manual. It's all documented.

    For example see the portability layer CFFI (Common Foreign Function Interface), the chapter on pointers. CFFI works on top of several Common Lisp implementations.