[plt-dev] feature request

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Apr 14 17:18:49 EDT 2010

On Apr 14, Matthias Felleisen wrote:
> A lot of libraries read in file content as lists (or S-expressions)
> of list-based structures (see csv on planet for one example, which I
> am currently incorporating to a small degree into
> 2htdp/batch-io). If I had this structure -- including in teaching
> languages -- I could easily 'view' these S-expressions/lists as
> structs, making for much more readable code.

+1 for the use case (but I don't have an opinion on whether it
justifies implementing them or not).  And here is how you do it in CL:

Plain list -- with the default keyworded constructor

  CL-USER(1): (defstruct (foo (:type list)) x y)
  CL-USER(2): (make-foo :y 2 :x 1)
  (1 2)
  CL-USER(3): (foo-x (list 1 2))

Tagged list, with a positional constructor with arguments in reverse

  CL-USER(4): (defstruct (foo (:type list) :named (:constructor mkfoo (y x)))
                x y)
  CL-USER(5): (mkfoo 2 1)
  (FOO 1 2)
  CL-USER(6): (foo-p '(1 2))     ; ("-p" is a bad spelling for "?")
  CL-USER(7): (foo-p '(foo 1 2))
  CL-USER(8): (foo-x (mkfoo 2 1))

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.