Created
April 18, 2011 03:14
-
-
Save dalmaer/924751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| amb_run(function(amb, fail){ | |
| /* <preamble> */ | |
| // utility function to test if two strings are adjacent | |
| function adjacent(str1, str2) { | |
| return str1.charAt(str1.length - 1) == str2.charAt(0); | |
| } | |
| // input data | |
| var w1 = amb([ "the", "that", "a" ]); | |
| var w2 = amb([ "frog", "elephant", "thing" ]); | |
| var w3 = amb([ "walked", "treaded", "grows" ]); | |
| var w4 = amb([ "slowly", "quickly" ]); | |
| /* </preamble> */ | |
| return function(w1, w2, w3, w4) { | |
| /* <main-program> */ | |
| if (!(adjacent(w1, w2) && adjacent(w2, w3) && adjacent(w3, w4))) | |
| fail(); | |
| console.log(w1, w2, w3, w4); | |
| /* </main-program> */ | |
| }; | |
| }); | |
| // result is "that" "thing" "grows" "slowly" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment