Barton Willis wrote:
> -----maxima-bounces at math.utexas.edu wrote: -----
>
>
>
>> Here's a naive attempt at implementing FILTER:
>>
>> :lisp (defmfun $filter (p l) (cons '(mlist) (remove-if-not p (cdr
>> l))))
>>
>> It even appears to work:
>>
>> (%i66) filter(evenp, [1, 2, 3]);
>> (%o66) [2]
>>
>> Am I missing anything?
>>
>
> Your filter function works OK (I think) for a predicate that is a CL
> function,
> but it fails when the predicate is a Maxima function. Example:
>
> (%i13) f(x) := is(mod(x,3) = 2)$
>
> (%i14) filter(f,[1,2,3,4,5]);
> Maxima encountered a Lisp error:
>
> Also, the function 'sublist' might do what you want
>
> (%i16) sublist([1,2,3,4,5],'f);
> (%o16) [2,5]
>
>
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?
-sen
> BW
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>