Ohhh, gotcha.
Well, I don't know the canonical way to "return" an array of values, since
the actual return keyword is meant for setting the status code. But I can
help with the two other issues I see:


   1. You're missing an $a in the eval $argv[1] line.
   2. You need a -1 to specify the end of an array. Cf.
   http://fishshell.com/docs/2.0/index.html#expand-index-range

To make it all clear, here's what I got:


function _filter_array

    set --local pred $argv[1] # like, short for "predicate"

    set -l proper_args $argv[2..-1] # "-l" is short for "--local"

    set -l res

    for a in $proper_args

        if eval $pred $a

            set res $res $a

        end

    end

    echo $res #see that indeed only the even elements remain

end


On Fri, Jun 21, 2013 at 4:20 PM, Costantino Giuliodori <
costantino.giuliod...@gmail.com> wrote:

> Tanks for tips, but my question is about the second function.
>
> Il giorno 21/giu/2013 20:50, "Josh Tilles" <merelyapseudo...@gmail.com>
> ha scritto:
>
> >
> > It looks like you're trying using the percent symbol "%" for division.
> I'm pretty sure fish uses % for process-expansion or something.
> >
> > You probably want:
> >
> > function _even
> > math "$argv[1]%2 == 0"
> > # could also do:
> > # math " ( $argv[1] % 2 )  ==  0"
> > # if you wanted the spacing or operator precedence to be clearer.
> > end
> >
> > See http://fishshell.com/docs/2.0/commands.html#math for a bit of an
> explanation. (The parentheses on the left-hand side are optional, btw.)
> >
> > On Jun 21, 2013, at 2:33 PM, Costantino Giuliodori <
> costantino.giuliod...@gmail.com> wrote:
> >
> >> why this type of function is not possible?
> >>
> >> function _even
> >>         test ($argv[1]%2) = 0
> >> end
> >>
> >>
> >> function _filter_array
> >>
> >>     for a in $argv[2..]
> >>         if eval $argv[1]
> >>             set res $res $a
> >>         end
> >>     end
> >>
> >> end
> >>
> >> --
> >> Costantino
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to