lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 19.01.2014 05:35 schröbte H. Conrad Cunningham:
On Sat, Jan 18, 2014 at 10:38 AM, Philipp Janda <siffiejoe@gmx.net> wrote:

`cons`, `car`, `cdr`, `setcar`, and `setcdr` are the only functions that
need to know the difference, so you can even change the implementation
later ...


I have a set of example modules I created for the course I taught in my
university's Fall semester (late August to mid-December) on my website at
http://www.cs.olemiss.edu/~hcc/csci658/notes/658lectureNotes.html#cellList

However, I intentionally did not include anything like a setcar or setcdr,
instead forcing creation or a new Cons cell. I wanted immutability of the
cells.

I started my experiments that way too. And then I tried to implement some functions from SRFI-1[1] using only `cons`, `car`, `cdr`, and recursion. And I got stack overflows for large input lists. Some functions I could fix easily (e.g. length), but others are difficult to implement efficiently without mutation. So I added `setcar` and `setcdr` (and started using explicit loops in the implementation) ...


- Conrad Cunningham


Philipp

  [1]: http://srfi.schemers.org/srfi-1/srfi-1.html