changeset b7053efa752f in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=b7053efa752f user: Simon Forman <sform****@hushm*****> date: Sun Aug 04 09:28:01 2019 -0700 description: loop combinator handles ambiguity. remove some old notes. diffstat: thun/thun.pl | 32 +++++++------------------------- 1 files changed, 7 insertions(+), 25 deletions(-) diffs (47 lines): diff -r 76b76caaf4de -r b7053efa752f thun/thun.pl --- a/thun/thun.pl Sat Aug 03 19:02:24 2019 -0700 +++ b/thun/thun.pl Sun Aug 04 09:28:01 2019 -0700 @@ -223,6 +223,13 @@ combo(loop, [_, false|S], S, E, E ). combo(loop, [B, true|S], S, Ei, Eo) :- append(B, [B, loop|Ei], Eo). +combo(loop, [B, Expr|S], S, Ei, Eo) :- + \+ Expr = true, \+ Expr = false, + catch( % Try Expr and do one or the other, + (Expr -> append(B, [B, loop|Ei], Eo) ; Ei=Eo), + _, % If Expr don't grok, try both branches. + (Ei=Eo ; append(B, [B, loop|Ei], Eo)) + ). combo(step, [_, []|S], S, E, E ). combo(step, [P, [X]|S], [X|S], Ei, Eo) :- !, append(P, Ei, Eo). @@ -309,28 +316,3 @@ grow(Ei, Eo) :- to_fixed_point(rebo(expando, grow ), Ei, Eo). shrink(Ei, Eo) :- to_fixed_point(rebo(contracto, shrink), Ei, Eo). - - -/* -?- E=[foo,bar,swap,cons,baz],phrase(shrink, E, ExprOut). -E = [foo, bar, swap, cons, baz], -ExprOut = [foo, bar, swons, baz]. - -?- E=[foo, bar, swons, baz],phrase(grow, E, ExprOut). -E = [foo, bar, swons, baz], -ExprOut = [foo, bar, swap, cons, baz]. - -*/ - - -% ... --> [] | [_], ... . - -% for the ellipsis operator -% http://swi-prolog.996271.n3.nabble.com/DCG-idioms-td3117.html which references: -% David B. Searls, Investigating the Linguistics of DNA with Definite Clause Grammars. NACLP 1989. - -% phrase(expando, ExprIn, ExprOut). - -% E=[foo,bar,swap,cons,baz],phrase((...,contracto,...), E, ExprOut). -% E = [foo, bar, swap, cons, baz], -% ExprOut = [swons, baz] \ No newline at end of file