Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58771
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Amb (2.) |
| Date | 2017-05-07 13:12 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oen6fe$cjv$1@gioia.aioe.org> (permalink) |
> The Amb operator takes a variable number of expressions (or
> values if that's simpler in the language) and yields a correct
> one which will satisfy a constraint in some future
> computation, thereby avoiding failure.
> The task is to somehow implement Amb, and demonstrate it with
> a program which chooses one word from each of the following
> four sets of character strings to generate a four-word
> sentence:
>
> "the" "that" "a"
> "frog" "elephant" "thing"
> "walked" "treaded" "grows"
> "slowly" "quickly"
>
> The constraint to be satisfied is that the last character of
> each word (other than the last) is the same as the first
> character of its successor.
>
> The only successful sentence is "that thing grows slowly";
> other combinations do not satisfy the constraint and thus
> fail.
(use amb amb-extras
srfi-13 (only srfi-13 string-take string-take-right)
srfi-1 (only srfi-1 every))
(define (good? a b)
(equal? (string-take-right a 1) (string-take b 1)))
(amb-find
(begin
(define answer
(list (amb "the" "that" "a")
(amb "frog" "elephant" "thing")
(amb "walked" "treaded" "grows")
(amb "slowly" "quickly")))
(amb-assert (every good? answer (cdr answer)))
answer))
===>
("that" "thing" "grows" "slowly")
In Forth?
--
[E]verything that happens in the world is for the benefit of the Jewish
People.... G-D ... created the world for the sake of the Jewish People, and it
is our responsibility to implement the Torah---absolute morality and the
blueprint of creation---in it.
www.IsraelNationalNews.com/Articles/Article.aspx/2125#.UUnBZxx4xn8
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Amb (2.) "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-07 13:12 +0000
csiph-web