Filtering Lists



On 10/26/07, S. Newhouse <sen1 at math.msu.edu> wrote:
> Why does the 'non-evaluation' of f in this application of sublist work?
> It seems that both
>    sublist([1,2,3,4,5],'f);
> and
>    sublist([1,2,3,4,5],f);
> work
>
> Why does this happen?
>
> Since, (I think) sublist finds those terms in a list for which a
> predicate is true,  why does it work if the predicate is not evaluated?

Sublist is a normal function; the Maxima evaluator evaluates and
simplifies its arguments.  Thus

   myfun : evenp;
   sublist(append([1,2,3],[2,5]), myfun);

is equivalent to

   sublist( '[1,2,3,2,5], 'evenp );

In both cases, the sublist function (or functional if you prefer that
terminology) then applies the predicate, a functional argument, to
each element of the list.  The application of the predicate is
independent of where the predicate came from (a quoted argument or an
evaluated argument).

Quoting the functional argument prevents this level of evaluation from
happening:

   sublist( '[1,2,3], 'myfun )

will apply the literal function myfun to each of 1,2,3.  Sublist
treats any non-false value as true (I think this is a design error,
but that's a different discussion) so this will return [1,2,3].

Is that clearer?

          -s