Hi Jon,

> : (index 9 (list 1 2 (prinl 9) (prinl 'more) 9))
> 9
> more
> -> 3
> I see that the index function evaluates the entire lst before
> searching for a match. Wouldn’t it be more efficient to evaluate the
> elements of lst one by one, testing the result for a match, and only
> proceed with evaluation of the next element if a match was not found? Is
> there a specific reason why you didn’t implement it that way?

What you describe here is call "lazy evaluation". While some languages
support this, PicoLisp (like most other Lisps) doesn't.

Think about what this would mean: The function 'list' must know somehow
that it should stop, because some function up in the call history
doesn't need the whole list.

And even if it knew that, can it know that some side effects (like your
'prinl' above) may be omitted?

The fundamental rule of Lisp function calls (a function recursively
evaluates its arguments before it starts to run) is broken here.

> Another question re. index:
> In the method final static int indx(Any x, Any y) in ersatz/sys.src, on lines 
> 988-989, there is this:
>          if (z == (y = y.Cdr))
>             return 0;
> Can you explain which case this if-test is handling?

You found the answer by yourself in your next mail ;-)
♪♫ Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to