Support for string literals and a 'write' builtin predicate #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm working on generative storytelling and I needed to output text from Ceptre because it was to cumbersome to parse the output with a different program. This introduces side effects and the need for string literals.
When declaring a predicate with the
WRITE
builtin it is checked to be an action predicate having one or more arguments of any type. Multiple write predicates can be declared, this is needed to write values of different types. Action predicates are not really used in the code, I don't know what was the intention behind them but the fact they can only appear on the RHS of a rule means side effect to me. When a rulea * b -o write a b
is applied, it will printab
with no newline and thewrite a b
atom won't be added to the context as a special case of write. Maybe this case should be extended to all action predicates but for now only write has side effect. Or maybe it should be added to the context except when some special operator is used to flag an atom not to be added.Next, to be able to print any text without having to declare all words as predicates, string literals were needed.
There was a string type in the core engine (
SLit
terms) but unlike integers it wasn't implemented in the parser and in the typechecker so there was no way to obtain a string term.Finally the
--quiet
CLI flag was added so only the output of write is displayed.Example: