4 ms·
Lisp is not necessarily functional. There's a lot of mutation in Common Lisp even if the community favors a functional style. I think the question is: how does
by vnorilo 5y ago
Lisp is not necessarily functional. There's a lot of mutation in Common Lisp even if the community favors a functional style.
I think the question is: how does Lisp function without garbage collecting cons cells?
For one, I'm not sure they even rely on cons cells like "real" Lisp. Clojure doesn't either. They cite ML as inspiration.
Carp language guide states object lifetimes are statically inferred [1] which my guess is they allocate on stack (or malloc/free by scope) and detect use-after-free at compile time.
Another, more theoretical approach is using linear types which require all values to be "consumed" [2]
1: https://github.com/carp-lang/Carp/blob/master/docs/LanguageGuide.md https://github.com/carp-lang/Carp/blob/master/docs/LanguageG...
2: https://www.cs.utexas.edu/users/hunt/research/hash-cons/hash-cons-papers/BakerLinearLisp.pdf https://www.cs.utexas.edu/users/hunt/research/hash-cons/hash...
- protomikron 5y agoThanks for the links. There's also this Reddit discussion [0] from 2 years ago (it mentions Carp btw.) and an explanation about how Carp manages memory [1]. [0] https://www.reddit.com/r/haskell/comments/d5d13i/is_it_possible_to_design_a_functional_language/ https://www.reddit.com/r/haskell/comments/d5d13i/is_it_possi... [1] https://github.com/carp-lang/Carp/blob/master/docs/Memory.md https://github.com/carp-lang/Carp/blob/master/docs/Memory.md
- alexisread 5y agoIn particular, the reddit discussion mentions ASAP, which is a set of static analysis algorithms that can work with mutability, generics (polymorphism) and linear types. http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-908.pdf http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-908.pdf As far as I'm aware, this really only applies to single threaded systems. However, if you implement threadsafe modules and keep the shared stuff internal (use the ASAP algos here), you can fit the majority of use-cases including hard-realtime constraints. Composita is the module system I'm referring to. http://www.composita.net/Composita.html http://www.composita.net/Composita.html It allows concurrency with managed memory and no GC, through static analysis of the module (component) interface queues.
- timdeve 5y agoYou're correct, somewhat like clojure's Vector, the default collection at runtime in Carp is an Array which is heap allocated C array with an attached length. At compile time however the dynamic language uses more standard lispy lists.