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.
Garbage-collection has always been necessary because the computer's supply of addressable space has always been much less than the total space used during execution of a list-processing program. Garbage-collection makes it possible to reuse the system's limited supply of addressable space.
Garbage collection is an essential part of any Lisp interpreter or compiler. It allows Lisp to manipulate lists and more complex data structures without requiring the programmer to be concerned about the allocation and deallocation of the memory they need.
Primitive programming languages like C and C++ do not have their garbage collection instead expect the developer to not only allocate the object but also deallocate it explicitly. Hence we see the functions like "malloc" and "free".
Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With