Amb: Difference between revisions
Content deleted Content added
SETL |
→SETL: Improved backtracking version and moved it in front |
||
Line 313:
=={{Header|SETL}}==
<lang SETL>program amb;▼
if exists lWord = words(i), rWord in {words(i+1)} |
lWord(#lWord) /= rWord(1) then
end proc;▼
end program;</lang>▼
Sadly ''ok'' and ''fail'' were only ever implemented in CIMS SETL, and are not in any compiler or interpreter that is available today, so this is not very useful as it stands.
===Alternate version (
<lang SETL>program amb;
Line 339 ⟶ 357:
end program;</lang>
We cheat a bit here - this version of ''amb'' must be given the whole list of word sets, and that list is consumed recursively. It can't pick a word from an individual list.
▲===Alternate version (uses [http://www.setl-lang.org/wiki/index.php/Backtracking backtracking])===
▲<lang SETL>program amb;
▲sets := unstr('[{the that a} {frog elephant thing} ' +
▲proc amb(sets);
▲ (for words in sets)
▲ if exists word in words |
▲ fail;
▲ end if;
▲end proc;
▲end program;</lang>
|