Re: (dsssl) loop problem

Subject: Re: (dsssl) loop problem
From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 4 Sep 2001 10:52:07 -0700
Hi Lutz,

You shouldn't put the '(make sequence)' procedure inside the loop.  You want
the loop simply to return a string, but the way you've written it, the true
branch of the conditional returns a string, while the false branch makes a
flow-object.

If you want to keep this approach, just rearrange it so the (let loop . . .)
occurs as the content of a (literal ...) procedure, and the 'false' branch
of the conditional looks like:

  (loop (node-list-rest nl) (string-append str (data (node-list-first
nl)))))

(If you really wanted a sequence of flow objects, one for each MYELEMENT
element, you would probably need a containing (sosofo-append) around the
loop, and an (empty-sosofo) to end it--but in this case (map-constructor)
would probably be a better choice.)

Alternatively, you can use (node-list-reduce).  It's a little more abstract,
but uses less code, and it is a general-purpose template for processing any
node-list to return either another node-list, or any other data type you
need.

In your example, it would look like this:
(node-list-reduce
    (select-elements (descendants (current-node)) '("MYELEMENT")))
    (lambda (str snl) (string-append str (data snl)))
    "")

The 3 arguments to (node-list-reduce) are:
    1. the node-list to process
    2. a procedure for combining an 'initial' value with some value derived
from the first node on the list
    3. an 'initial' value for the procedure to work with (in this case, the
empty string).

The (node-list-reduce) procedure recursively applies the result of the
procedure (given as the 2nd argument) to the succeeding nodes of the
original node-list.  The DSSSL standard can probably explain this better
than I can. (10.2.2)

Just wrap the (node-list-reduce . . .) in a (literal . . .) and I think
you'll have what you want.

Good luck,
Paul Tyson
paul@xxxxxxxxxxxxxxxxxxxxxx

----- Original Message -----
From: "Lutz Pliske" <pliske@xxxxxxxx>
To: <dssslist@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, September 04, 2001 9:03 AM
Subject: (dsssl) loop problem


> Hi there, it´s probably easy but I don´t get the problem:
>
> I want this function to return a string that was built while looping
> thrue the nodelist and picking an informatin from every member of this
> nodelist. I start with a "" and then add all the following strings with
> a string-append. When the looping is finished the function will return a
> string with all the values. Well - not like this:
>
> (define (f_make-entities)
>    (let loop((nl (select-elements (descendants (current-node))
> "MYELEMENT"))(str ""))
>       (if (node-list-empty? nl)
>          str
>          (make sequence
>             (loop (node-list-rest nl) (string-append str "information
> from this nodelist element"))
>          )
>       )
>    )
> )
>
> I am getting "this context requires a text-sosofo". So I tried a
> (literal "information from this nodelist element"). That didn´t help.
>
> Please help ....
>
> Greetings Lutz
>
>
>  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist



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

Current Thread