[plt-dev] feature request
This is probably obvious but you could write a pretty simple function
to build the prefab struct out of the sexp and even put it in a
library to be used as a replacement for read.
Robby
On Wednesday, April 14, 2010, Eli Barzilay <eli at barzilay.org> wrote:
> 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)
> FOO
> CL-USER(2): (make-foo :y 2 :x 1)
> (1 2)
> CL-USER(3): (foo-x (list 1 2))
> 1
>
>
> Tagged list, with a positional constructor with arguments in reverse
>
> CL-USER(4): (defstruct (foo (:type list) :named (:constructor mkfoo (y x)))
> x y)
> FOO
> CL-USER(5): (mkfoo 2 1)
> (FOO 1 2)
> CL-USER(6): (foo-p '(1 2)) ; ("-p" is a bad spelling for "?")
> NIL
> CL-USER(7): (foo-p '(foo 1 2))
> T
> CL-USER(8): (foo-x (mkfoo 2 1))
> 1
>
>
> --
> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
> http://barzilay.org/ Maze is Life!
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-dev
>