Re: [Factor-talk] Rosettacode and amb

2009-12-09 Thread Samuel Tardieu
> "Sam" == Samuel Tardieu  writes:

Sam>   - no more macro: "select" recursively builds a candidate using
Sam> "amb"

And as Jon noticed (in a private chat session), "select" is best defined as

  : select ( seq -- seq' ) [ amb-lazy ] map ;

rather than using the constructive recursive version.

 Sam
-- 
Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


--
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Doctext for map-reduce needs fixing

2009-12-09 Thread Ben Schlingelhof
Hi there,

by sheer luck I stumbled across a mistake in the map-reduce
documentation. It says:
"Unclips the first element of the sequence, calls map-quot on that
element, and proceeds like a reduce, where the calculated element is
the identity element and the rest of the sequence is the sequence to
reduce."
Alright, example:
{ 1 3 5 } [ sq ] [ + ] map-reduce
"Unclips the first element of the sequence,"
{ 1 3 } 5 [ sq ] [ + ] map-reduce
"calls map-quot on that element, and proceeds like a reduce, where the
calculated element is the identity element and the rest of the
sequence is the sequence to reduce."
{ 1 3 } 25 [ + ] reduce
=> 29

Maybe better to say:
"Calls map with map-quot on the complete sequence, then unclips the
first element and proceeds like a reduce..."

same thing in 2map-reduce

Cheers,
Ben

--
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Rosettacode and amb

2009-12-09 Thread Samuel Tardieu
> "Jon" == Jon Harper  writes:

Jon> Hi everyone, I wanted to use amb (one the of problems of
Jon> rosettacode.org) in factor, but I'm not sure if the solution I came
Jon> up with is good. Could you give some feedback ? Is there a
Jon> easier/more efficient way than the "macro-map" macro I wrote ?

I added an annotation with a simpler (IMO) version:

  - no more macro: "select" recursively builds a candidate using "amb"

  - use "2all?" instead of your convoluted reduce (you could have used
"2map-reduce" but "2all?" will probably use shortcuts)

  - use "CONSTANT:" instead of an inlined word

Jon> The code is here (only the annotation) :
Jon> http://paste.factorcode.org/paste?id=1053#568

Also, as a personal style preference, I dislike words that do something
useful *and* print the result unless a non-printing variant exist. I
would have written something like:

: search ( -- str ) words select dup sentence-match? [ fail ] unless " " join ;

: search. ( -- ) search . ;

MAIN: search.

Amongst other things, this eases testing (although one can argue that
redirecting standard output into a string is damn easy in Factor :-).

  Sam
-- 
Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


--
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk