This commit is contained in:
Tibo De Peuter 2025-05-09 10:30:51 +02:00
parent 5bfeb96176
commit 88c90220fe
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 8 additions and 0 deletions

View file

@ -148,6 +148,7 @@ open class Preprocessor {
// IO
Functor.of("write/1") -> Write(args[0])
Functor.of("nl/0") -> Nl
Functor.of("writeln/1") -> WriteLn(args[0])
Functor.of("read/1") -> Read(args[0])
// Lists

View file

@ -17,6 +17,8 @@ import prolog.logic.unifyLazy
* Write [Term] to the current output, using brackets and operators where appropriate.
*/
class Write(private val term: Term) : Operator(Atom("write"), null, term), Satisfiable {
constructor(message: String) : this(Atom(message))
override fun satisfy(subs: Substitutions): Answers {
val t = applySubstitution(term, subs)
@ -45,6 +47,11 @@ object Nl : Atom("nl"), Satisfiable {
override fun applySubstitution(subs: Substitutions): Nl = this
}
class WriteLn(private val term: Term) : Conjunction(Write(term), Nl) {
constructor(message: String) : this(Atom(message))
override fun applySubstitution(subs: Substitutions): WriteLn = WriteLn(applySubstitution(term, subs))
}
/**
* Read the next Prolog term from the current input stream and unify it with [Term].
*