green_tory

joined 1 year ago
[–] green_tory@alien.top 1 points 1 year ago

Not just trees; any operation that involves mutating or manipulating list-like structures is more efficient than arrays.

Some examples:

Removing an element is delinking a single cons cell, vs either copying to a new array or shuffling all subsequent elements left. It also doesn't break any references to list cells, even the removed cell.

Slicing, at minimum, only requires having the cons cell at the new head of the list; rather than either a special datastructure to represent a slice, or copying to a new array.

Filtering means pulling cons cells from a nursery on an ad-hoc basis, using them to collect filtered elements into a new list of unknown length. With an array, you need a pre-allocated buffer that either sets a limit on the size of the filtered set, or requires reallocation on resize with a O(n) copy.

Just, in general, you can be a lot more relaxed with flinging data around lists without having to think about the algorithmic overhead of allocating, reallocating, copying and shuffling arrays.

[–] green_tory@alien.top 1 points 1 year ago

If you were to use Janet arrays as one uses lists in a lisp, then you'd quickly find yourself in a performance tar pit. Arrays would be frequently allocated, freed, resized, copied, and so forth.

A linked list built around cons cells allows slicing, augmentation, filtering, and so on almost for free.

That means writing in a proper lisp lends itself towards almost thoughtlessly mutating and manipulating lists; whereas writing code in Janet means spending more care about what you're doing with the data structure.

[–] green_tory@alien.top 1 points 1 year ago (5 children)

Janet.

It's not a lisp or lisp dialect because it is not built around lists. It doesn't even have cons cells.

[–] green_tory@alien.top 1 points 1 year ago (1 children)

Let's see some Janet and Fennel times.

[–] green_tory@alien.top 1 points 1 year ago

As a former Schemer: I wish Scheme were as portable as CL, and had something as awesome as QuickLisp. There's something fantastic about being able to use the CommonLisp implementation that's most appropriate for your platform/target and still be able to take your code with you.