! Copyright (C) 2009 Jon Harper ! See http://factorcode.org/license.txt for BSD license. USING: backtrack continuations fry generalizations kernel locals prettyprint sequences ; IN: amb : words ( -- seq ) { { "the" "that" "a" } { "frog" "elephant" "thing" } { "walked" "treaded" "grows" } { "slowly" "quickly" } } ; inline : letters-match? ( str1 str2 -- ? ) [ last ] [ first ] bi* = ; : sentence-match? ( seq -- ? ) dup rest t [ letters-match? and ] 2reduce ; MACRO:: macro-map ( seq macro -- ) seq length :> tmp seq [ ] each [ macro tmp napply tmp narray ] tmp ncurry ; : search ( -- ) words [ amb ] macro-map dup sentence-match? [ " " join ] [ fail ] if . ; MAIN: search