(I realized that the way defs are parsed now means that each def
(but the last) is first asserted with the wrong definition expression
(it includes the symbol of the following definition at the end) and
then the parser figures out that there's another defintion following
and re-asserts the correct expression. It would be nice to fix that
but it's kind of a PITA. I used to build a list of definitions and
then assert them all at the end. For now there aren't enough defs to
justify the extra work.
As much fun as it was using ? as an operator, now that all the defs live in a text file you don't see it in the Prolog code anymore.
This way I get to use sweet sweet ASCII (except for the ? symbol in the copyright notice.)
...then the branch combinator works as intended. (Although the constraint-based stuff was also cool, it would have captured information from the comparison.)
?- joy(`[32 >] [++] [--] ifte`, Si, So).
Si = [_6598|_6600],
So = [_6598+1|_6600] ;
Si = [_6598|_6600],
So = [_6598-1|_6600] ;
false.
?- sjc(hmm, `[32 >] [++] [--] ifte`).
func(hmm, [A|B], [A+1|B]).
true ;
func(hmm, [A|B], [A-1|B]).
true ;
false.
If the expression isn't 'true' or 'false' atoms then we assume it's a comparison expression and try to check its truth value.
If this fails then it will try both branches, to allow for e.g. compilation. THis almost works, but there's a choice point or something that gets hit before it tries the false path,
?- joy(` [32 >] [++] [--] ifte`, Si, So).
Si = [_2076|_2078],
So = [_2076+1|_2078] ;
wtf? +
Si = [_2076|_2078],
So = [[+], 1, _2076|_2078] ;
Si = [_2076|_2078],
So = [_2076-1|_2078] ;
wtf? -
Si = [_2076|_2078],
So = [[-], 1, _2076|_2078] ;
wtf? branch
Si = [_2076|_2078],
So = [[branch], [++], [--], _2076>32, _2076|_2078] ;
wtf? swap
Si = [_2076|_2078],
So = [[swap, branch], [--], [++], _2076>32, _2076|_2078] ;
wtf? first
Si = [_2076|_2078],
So = [[first, [++], [--], swap, branch], [_2076>32|_2078], _2076|_2078]
etc...