Re: (dsssl) node-lists

Subject: Re: (dsssl) node-lists
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Mon, 9 Jul 2001 13:26:13 -0500
Quoting Patrice LaFlamme <ewd@xxxxxxxxxx>:
> On Mon, Jul 09, 2001 at 10:16:33AM -0500 or thereabouts, Brandon Ibach wrote:
> >    Now, if you're just looking for an "array", then a regular list
> > would serve your purpose.  There are several ways to create a list,
> > the simplest of which being:
> > 	(list "abc" 123 ...)   (as many items as you want)
> 
> yes, this is sort of what I want.
> 
> But how do I add items to it? how do I access them?
> 
   Hmmm... this is a somewhat loaded question.  You must keep in mind
that DSSSL is a "side-effect free" language, meaning that you aren't
allowed to "modify" a value.  Rather, you can only use a value in a
"read-only" sense to construct a new value.  For instance:
	(let ((a '(a b c))  (b '(b c d)))
	  (list (append a b) a b))  =>  ((a b c b c d) (a b c) (b c d))
   Here, the (list) function created a list of three lists.  The first
list was the result of the (append) function, which creates a list
consisting of the members of the lists which are passed to it.  The
second and third lists are simply the lists we started with, a and b.
   Note that the (append) function created a new list.  It didn't
modify our original lists in any way.
   Okay... that having been said (and I hope I haven't clobbered you
with stuff you already know), there are several ways to access list
items.  The most basic are the functions (car) and (cdr):
	(car '(a b c))              =>  a
	(cdr '(a b c))              =>  (b c)
	(cdr (cdr '(a b c)))        =>  (c)
	(car (cdr '(a b c)))        =>  b
	(car (cdr (cdr '(a b c))))  =>  c
As you can see, (car) returns the first item in a list, and (cdr)
returns the whole list, minus the first item.  Read up a bit on
"pairs" (I think the DSSSL spec talks about them... if not, any good
Scheme tutorial or book would) and you'll see where these functions
originate.
   An easier function to use, in most cases, is (list-ref):
	(list-ref '(a b c) 0)  =>  a
	(list-ref '(a b c) 1)  =>  b
	(list-ref '(a b c) 2)  =>  c
   Hope all this helps.  As Jany said, maybe you want to tell us a bit
about what you're trying to do, as we may be able to provide some
higher-level tips on how to approach the problem.

-Brandon :)

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist

Current Thread