lua-users home
lua-l archive

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

On Tue, Nov 19, 2013 at 10:26 PM, Philipp Janda <> wrote:
In "Structure and Interpretation of Computer Programs" there is an implementation of cons-cell-lists using closures[1]. Something along the lines of:

Thanks.   I had looked some at that from SICP, but I had not invested time in understanding and developing it for Lua. ... It seemed a bit esoteric for what I was trying to do at the time.  But the closures-in-readonly-cell and lazy cons variants of the basic list module turned out to be a bit esoteric for my students anyway. :)

Although I have owned a copy of SICP since the late 1980s, I had not worked through it to a great extent. I am not a huge Scheme fan.  I did my own Lua versions of some of the numeric functions from chapter 1 and most of the extended complex number case stdudy from chapter two.  A group of students did a version of the digital circuit simulator.

If you really want all those type checks, I would use a weak table to keep track of all the functions that are in fact cons-cells.

Also thanks.  Weak tables were not in my "working set" of Lua programming features and techniques at the time (or yet for that matter).  

Type checking is something I struggle to find the correct level in dynamically typed languages.  In Haskell or Scala code, I may struggle to get the program past the type checker, but it usually is close to working at that point.  In Ruby or Lua, I usually find myself debugging the types during runtime tests. Often the code ends up with inconsistent type/precondition checking.