4 ms·
Lisp variants only really have linked lists. So yes you can do recursion over them, but for someone who has never done a C-like language before, the arrays and
by spencerchubb 3y ago
Lisp variants only really have linked lists. So yes you can do recursion over them, but for someone who has never done a C-like language before, the arrays and for loops will take getting used to
- reikonomusha 3y agoLisp "variants" have lists, hash tables, multi-dimensional arrays, strings, bit sequences, streams, etc.
- aeonik 3y agoIs it the case that all the cons cells at the base of the language are compiled into more efficient structures?
- lispm 3y agocons cells are not the base for vectors, strings and a bunch of other datastructures. Cons cells are mostly only used for nested lists or similar.
- aeonik 3y agoI guess I'm curious how the implementation of Vector works in Lisps. I thought it would be some sort of combination of Atoms and Cons cells. I looked into the Racket Repo to find something, but had a hard time finding the code.
- Bogdanp 2y agoIn Racket, a vector is a fixed-size contiguous array of memory. The values in each slot of a vector are tagged pointers so values like fixnums don't require any indirection to reach (i.e. they're unboxed). Racket also has specialized vector types for storing fixnums (fxvector), floats (flvector), strings (string) and bytes (bytes). Other Schemes and Common Lisp have similar constructs. Just because a language is a lisp doesn't mean its primitives have to be implemented using cons cells.
- soegaard 2y agoAs an example of other Schemes, here are the details of the representation used by Larceny (a Scheme): https://www.khoury.northeastern.edu/home/lth/larceny/notes/note2-repr.html https://www.khoury.northeastern.edu/home/lth/larceny/notes/n...
- kazinator 2y agoIn a traditional-style Lisp which has atoms and cons cells, "atom" is not a specific type. It is a category which means "not a cons cell". Everything that is not a cons cell is an atom: symbol, string, number, character, vector, I/O stream, function, class object, ... Notice vector in there.
- lispm 2y agoThe purpose of a vector in Lisp is to provide contiguous storage with integer index addressing and O(1) access time. Cons cells are typically used to provide lists with O(n) access time.
- cess11 3y agoNo they don't. The basic data structures in Racket are listed here, https://docs.racket-lang.org/reference/data.html https://docs.racket-lang.org/reference/data.html . There are also specific array implementations in modules, like the generic array interface in the array module or arrays for math in a math module. Recursing over a list is a way to learn how to implement for, while and friends. If you know this technique understanding for is just understanding a subset of what you are already familiar with. It can be used to iterate over an arrays as well as lists, e.g. with ranges: https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._range%29%29 https://docs.racket-lang.org/reference/pairs.html#%28def._%2... Racket can also be used to teach object oriented programming and programming with structs, if the aim is to teach patterns used in C-like languages generally it's not a bad fit. Well, except advanced stuff like pointer witchery. Though you could probably implement a teaching language that does it with arrays or the byte code directly if you wanted to. It might be a good way to improve on error messages for pedagogical purposes.
- pjmlp 3y agoOnly if stuck in 1950's Lisp.