Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for string literals and a 'write' builtin predicate #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

scouarn
Copy link

@scouarn scouarn commented May 2, 2024

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 rule a * b -o write a b is applied, it will print ab with no newline and the write 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:

nat : type. #builtin NAT nat.
str : type. #builtin STRING str.

write/str str : action. #builtin WRITE write/str.
write/nat nat : action. #builtin WRITE write/nat.
write/sentence str str str nat str : action. #builtin WRITE write/sentence.

go str nat : pred.

stage rules {
  print1: go Name Age -o write/sentence "My name is " Name ", I am " Age " years old.\n".
  print2: go Name Age -o
       write/str "My name is "
    * write/str Name
    * write/str ", I am "
    * write/nat Age
    * write/str " years old.\n".
}

context init = { go "Bob" 25 }.

#trace _ rules init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant