Here's a naive implementation:
(de list-make ("Lst")
(queue "Lst" "("))
(de list-link ("Lst" Node)
(queue "Lst" Node)
(queue "Lst" " "))
(de list-close ("Lst")
(queue "Lst" ")"))
(de list-close-all ("Lst")
(let (Open (length (sect (val "Lst") (list "(" )))
Close (length (sect (val "Lst") (list ")" ))))
(for X (- Open Close)
(queue "Lst" ")")))
(car (str (pack (val "Lst")))))
(setq L NIL)
(list-make 'L)
(list-make 'L)
(list-link 'L 'parent)
(list-make 'L)
(list-link 'L 'child)
(list-link 'L 'child)
(list-close-all 'L)
-> ((parent (child child)))
I don't know how I feel about it...
On Mon, Nov 26, 2012 at 1:11 PM, Joe Bogner <[email protected]> wrote:
> I'm sure I'm making this harder than it is. I spent several hours
> tinkering around trying to find a way to sequentially build a nested list.
>
> make and link have spoiled me.
>
> Instead of this:
>
> : (make (link (make (link 'parent (make (link 'child 'child))))))
> -> ((parent (child child)))
>
> or
>
> : (list (list 'parent (list 'child 'child))))
> -> ((parent (child child)))
>
> I would like to do
>
> (setq L NIL)
> (list-make 'L)
> (list-make 'L)
> (list-link 'L 'parent)
> (list-make 'L)
> (list-link 'L 'child)
> (list-link 'L 'child)
>
> Or something along those lines. The reason for the question is that I find
> myself building things in for loops and it seems like I would need to use
> some form of recursion to build it with make or list.
>
> I've had some success with push and queue but was wondering if there's a
> more elegant way.
>
>