## (dsssl) Loop and Data content

 Subject: (dsssl) Loop and Data content From: "Javier Farreres de la Morena" Date: Fri, 11 Apr 2003 11:19:22 +0200
```>From: =?iso-8859-2?Q?Miros=B3aw_Prywata?= <Miroslaw.Prywata@xxxxxxxxxx>
>Subject: (dsssl) simple loop  question
>
>I have simple problem with processing node list in loop. I do not know
where
>to put increment condition (finally I comment it out and jade is processing
>only the first element as expected).

Loop is a functional construction. It is the named let.
Scheme works on recursion, not on iteration, but on a special kind of recursion,
final recursion.

Final recursion is that in which the recursive call is the last one to be
executed. It is usually implemented with an accumulator.

Example:

(let loop ((x 10)
(acc 0)
(if (= x 0)
acc
(loop (- x 1) (+ x acc))))

This portion of code executes the sum of values of x from 1 to the initial
value of x. The execution would be:

(loop 10 0)
(loop 9 10)
(loop 8 19)
(loop 7 27)
(loop 6 34)
(loop 5 40)
(loop 4 45)
(loop 3 49)
(loop 2 52)
(loop 1 54)
(loop 0 55)
55

Final recursion is equivalent to iterations, it executes in constant space.

>------------------------------
>From: Ian Zimmerman <itz@xxxxxxxxxxxxx>
>Subject: Re: (dsssl) simple loop  question
>
>DSSSL is a functional language, so use recursion instead of iteration,
>or even better, use higher order functions.  I haven't checked your
>code for anything else, but this should convey the idea:

Yes, much better use higher order functions. They are supposed to be efficiently
implemented.

>------------------------------
>From: tmcd@xxxxxxxxx
>Subject: Re: (dsssl) simple loop  question
>
>>> The following function should proceses current (or given) node
>>> list, wrap character data with <mi>element and process other
>>> elements.
>
>So there is a way to get character data?  I was wondering how to
>distinguish the input
>    <ltt-name></ltt-name>
>from
>    <ltt-name>A name goes here</ltt-name>

In the first case, the grove element will not have content. In the other
case it will have content in form of data-char nodes, one for each letter.

You can obtain the text with the data procedure.

Javi

-------------------------------------------------
¡¡¡ POR SÓLO 16,95 euros al mes !!!
+ tiempo de conexión (0,024 ./min.)
Y cuota máxima garantizada de 39,95 ./mes
AHORA ALTA GRATIS
¡¡¡ Por fin pagas por lo que consumes !!!
-------------------------------------------------

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

```