WriteLn
This commit is contained in:
parent
5bfeb96176
commit
88c90220fe
2 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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].
|
||||
*
|
||||
|
|
Reference in a new issue