12 ms·
`cons`, is a raw memory allocation. It`s `malloc`for linked rather than sequential memory Yeah, cons is like malloc, except that the object it creates is autom
by wes-exp 12y ago
`cons`, is a raw memory allocation. It`s `malloc`for linked rather than sequential memory
Yeah, cons is like malloc, except that the object it creates is automatically memory managed / garbage collected. There is no corresponding "free" call. Actually, that means cons is not like malloc.
Clojure takes advantage of being fully managed code
Do you realize that Lisp uses automatic memory management (just like the JVM or CLR)?
- brudgers 12y agoLisp's are high level languages. The JVM and CLR are virtual machines that interpret and compile bytecode. Some Lisps utilize virtual machines, Clojure being an example of one which does not use it's own, CMULisp and Racket are examples of Lisps which use their own VM, and ClozureCL and SBCL are Lisps which compile directly to native code. How Chicken Scheme fits into the whole virtual machine model...well it's just too fine an ontological line for me to call. Why are there no Fortran machines or Algol Machines or C machines? The `cons` cell is a raw memory structure, just one step removed from assembly and originally accessed directly in machine code with `car` and `cdr`. It's associated symbol is literally a pointer directly to a memory location. It's so close to assembly language that thirty years ago implementing it directly in hardware was considered practical.
- wes-exp 12y agoThe `cons` cell is a raw memory structure It's associated symbol is literally a pointer directly to a memory location A cons is not "raw memory"; it is a typed data structure, and in Common Lisp it is even considered an OOP object of the cons class. It is equivalent to having a data structure called "pair" that can hold two things. All memory-allocated data structures ultimately have an address of some kind, so this whole discussion about pointers is utterly meaningless. For that matter, arrays, strings, and basically every known memory data structure is "raw" too. After all, they have an address. The fact that cons/car/cdr can be implemented cheaply in hardware stems from the fixed and small size of cons. That doesn't make it somehow inferior. By the way, the Java stuff is implemented in hardware too, does that make Java inferior? http://en.wikipedia.org/wiki/Java_processor http://en.wikipedia.org/wiki/Java_processor