You can curry the sequence into the filter expression (using the fry vocab):
dup '[ reverse _ member? ] filter
Or, more traditional curry:
dup [ [ reverse ] dip member? ] curry filter
Or, you can leave it "under" the stack and access it using stack shufflers:
dup [ reverse over member? ] filter nip
Part of your problem is that "dup reverse swap filter?" isn't doing what
you expect.
To help diagnose those kind of problems you can set a breakpoint like this
(using B):
dup [ B dup reverse swap member? ] filter
Then you'll can see what inputs the quotation is getting on the stack.
On Tue, Mar 22, 2016 at 10:37 AM, cat stevens <thebinarymi...@gmail.com>
wrote:
> Hello!
>
> I've an array:
>
> { "abc" "def" "cba" "fed" "junk" }
>
> I'd like to filter this array by whether the reverse of an element is also
> a member.
>
> In Python, I'd express this as:
>
> >>> array = ["abc", "def", "cba", "fed", "junk"]
> >>> [item for item in array if item[::-1] in array] # [::-1] reverses a
> string
>
> And the result of the list comprehension would be
>
> ['abc', 'def', 'cba', 'fed']
>
> A more functional example would be, e.g:
>
> list(filter(lambda x: x[::-1] in array, array))
>
> For the same result.
>
> How can I do the same thing in Factor? I've tried:
>
> dup [ dup reverse swap member? ] filter
>
> which gives an empty array because the quotation fails for each item.
>
> Regards, cat.
>
>
> ------------------------------------------------------------------------------
> Transform Data into Opportunity.
> Accelerate data analysis in your applications with
> Intel Data Analytics Acceleration Library.
> Click to learn more.
> http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk