Amb: Difference between revisions
Content added Content deleted
(SETL) |
(→SETL: Improved backtracking version and moved it in front) |
||
Line 313: | Line 313: | ||
=={{Header|SETL}}== |
=={{Header|SETL}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
if exists lWord = words(i), rWord in {words(i+1)} | |
|||
lWord(#lWord) /= rWord(1) then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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. |
|||
⚫ | |||
<lang SETL>program amb; |
<lang SETL>program amb; |
||
Line 339: | Line 357: | ||
end program;</lang> |
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. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
'{walked treaded grows} {slowly quickly}]'); |
|||
print(amb(sets)); |
|||
⚫ | |||
sentence := []; |
|||
⚫ | |||
⚫ | |||
ok and (sentence = [] or |
|||
word(1) = (reverse sentence(#sentence))(1)) then |
|||
sentence with:= word; |
|||
else |
|||
⚫ | |||
⚫ | |||
end; |
|||
return sentence; |
|||
⚫ | |||
⚫ |