Consider...
characteristic(a, lambda([z],if z>0 then 1 else 0));
characteristic([1,2,-1,-2,3,-3], lambda([x],x>0)) ==>
[1,1,0,0,1,0]
so you could do
a*characteristic(a, lambda([x],x>0))
which may have some usefulness..
or maybe what you are doing below is...
selectif(pred,set):= if set=[] then set else if pred(first(set)) then
cons (first(set),selectif(pred,rest(set)) )else selectif(pred,rest(set));
selectif(lambda([z],z>0), a)
The syntax could be simpler by a macro-expansion definition (see buildq), to
selectif(a>0,a)
or use a smaller name...
RJF
Robert Dodier wrote:
>Stavros Macrakis wrote, in part:
>
>
>
>>Maxima users are familiar with other languages they use,
>>including conventional mathematical notation, other symbolic
>>systems (Mathematica, Maple), and numeric systems (Fortran,
>>Matlab, Java, Perl, Python, Excel (!), etc.). If we're going
>>to introduce new notations, we should look at these and other
>>languages as a model, not at Common Lisp.
>>
>>
>
>Concerning notation and operations on lists, the "old guard"
>of programming languages (Fortran and a lot of stuff derived
>from it -- Basic, C/C++, Java) have a very weak, limited set
>of built-in operations for processing lists. Lisp, I'm sure,
>is very powerful, but also very idiosyncratic.
>
>More recent languages -- certainly Perl and Python but also
>S and Matlab -- have more interesting operations and
>more concise notations.
>
>For example, I do this kind of stuff in Octave every day:
>(I'm pretty sure it also works in Matlab)
>
> mean( a( a > 0 ) )
>
>or
>
> sum( a( b == 1 ) )
>
>The "a > 0" and "b == 1" expressions construct indices
>that are then used to get a subset of a vector "a". Sure, you
>can do it in Fortran or Fortran-alikes -- but I think after
>you get used to that kind of all-at-once operation you
>won't want to go back to do-loops.
>
>If inspiration for list operations is needed, I'd look
>first at Octave/Matlab, then Python. If still more is
>needed, I'd look at R/S.
>
>For what it's worth,
>Robert Dodier
>
>