Skip to content

Instantly share code, notes, and snippets.

@dalmaer
Created April 18, 2011 03:14
Show Gist options
  • Save dalmaer/924751 to your computer and use it in GitHub Desktop.
Save dalmaer/924751 to your computer and use it in GitHub Desktop.
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