prolog: write/1 + nl/0 via output buffer, 7 tests; built-ins box done
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 02:56:31 +00:00
parent 1846be0bd8
commit 072735a6de
3 changed files with 118 additions and 1 deletions

View File

@@ -299,6 +299,8 @@
((pl-cut? g) (begin (dict-set! cut-box :cut true) (k)))
((and (pl-atom? g) (= (pl-atom-name g) "true")) (k))
((and (pl-atom? g) (= (pl-atom-name g) "fail")) false)
((and (pl-atom? g) (= (pl-atom-name g) "nl"))
(begin (pl-output-write! "\n") (k)))
((and (pl-compound? g) (= (pl-fun g) "=") (= (len (pl-args g)) 2))
(pl-solve-eq! (first (pl-args g)) (nth (pl-args g) 1) trail k))
((and (pl-compound? g) (= (pl-fun g) "\\=") (= (len (pl-args g)) 2))
@@ -335,6 +337,10 @@
(let
((call-cb {:cut false}))
(pl-solve! db (first (pl-args g)) trail call-cb k)))
((and (pl-compound? g) (= (pl-fun g) "write") (= (len (pl-args g)) 1))
(begin
(pl-output-write! (pl-format-term (first (pl-args g))))
(k)))
(true (pl-solve-user! db g trail cut-box k))))))
(define
@@ -387,6 +393,42 @@
(pl-trail-undo-to! trail mark)
(pl-solve! db else-goal trail cut-box k)))))))))
(define pl-output-buffer "")
(define pl-output-clear! (fn () (set! pl-output-buffer "")))
(define
pl-output-write!
(fn (s) (begin (set! pl-output-buffer (str pl-output-buffer s)) nil)))
(define
pl-format-args
(fn
(args)
(cond
((empty? args) "")
((= (len args) 1) (pl-format-term (first args)))
(true
(str
(pl-format-term (first args))
", "
(pl-format-args (rest args)))))))
(define
pl-format-term
(fn
(t)
(let
((w (pl-walk-deep t)))
(cond
((pl-var? w) (str "_" (pl-var-id w)))
((pl-atom? w) (pl-atom-name w))
((pl-num? w) (str (pl-num-val w)))
((pl-str? w) (pl-str-val w))
((pl-compound? w)
(str (pl-fun w) "(" (pl-format-args (pl-args w)) ")"))
(true (str w))))))
(define
pl-solve-not-eq!
(fn