>>>>> "Jon" == Jon Harper <[email protected]> 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 -- [email protected] -- 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk