makelist vs create_list



On 4/9/07, van Nek <van.nek at arcor.de> wrote:
> I believe, map(lambda([x], expr), L) is a hard piece of code for newbies.

Agreed.

> Is  expr, x : L   in top level or  ev( expr, x : L )  in programs equivalent
> to map(lambda([x], expr), L) resp. makelist(expr, x, L) or are there some
> differences?

No, ev(expr,x:l) is very roughly equivalent to block([x:l],expr) or
equivalently lambda([x],expr)(l) or map(lambda([x], [expr]).  It does
not map over lists.

But actually ev does some other things as well, notably substituting
values of variables before the main evaluation; its behavior is really
rather complicated and messy.  For example:

      var1: 'var2$
      var2: 'var3$

      var1   =>   var2
      block([],var1)  => var2
      lambda([x],var1)(3) => var2

so far so good.  Now, with ev:

      var1, x=3   =>   var3
but
      block([],var1),x=3   =>  var2
      lambda([x],var1)(3),x=3  =>  var2

That is why I recommend avoiding ev, *especially* in programs.  It is
primarily a convenience feature for top-level use.

              -s