Skip to content

Commit

Permalink
Updates for 34.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tizoc committed Aug 19, 2023
1 parent 483dfd5 commit 6da530c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [Unreleased]

## [34.5] - 2023-08-19

### Added

- `assert` and `retract` functions restored.

## [34.4] - 2023-07-02

### Fixed
Expand Down Expand Up @@ -483,7 +489,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
- y-or-n? fixed
- compiler warnings suppressed in CLisp

[Unreleased]: https://github.com/Shen-Language/shen-sources/compare/shen-34.4...HEAD
[Unreleased]: https://github.com/Shen-Language/shen-sources/compare/shen-34.5...HEAD
[34.4]: https://github.com/Shen-Language/shen-sources/compare/shen-34.4...shen-34.5
[34.4]: https://github.com/Shen-Language/shen-sources/compare/shen-34.3...shen-34.4
[34.3]: https://github.com/Shen-Language/shen-sources/compare/shen-34.2...shen-34.3
[34.2]: https://github.com/Shen-Language/shen-sources/compare/shen-34.1...shen-34.2
Expand Down
4 changes: 2 additions & 2 deletions sources/declarations.shen
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
(set *infs* 0)
(set *hush* false)
(set *optimise* false)
(set *version* "34.4")
(set *version* "34.5")
(set *step* false)
(set *it* "")
(set *residue* [])
Expand Down Expand Up @@ -129,7 +129,7 @@
intern integer? input input+ inline include include-all-but it is is! in in-package internal implementation if
head hd hdv hdstr hash get get-time gensym fn function fst freeze fresh fork foreign fix file fail fail-if factorise
findall false enable-type-theory explode external exception eval-kl eval error-to-string error empty? element?
dynamic do difference destroy defun define defmacro defcc defprolog declare datatype cn cons? cons cond concat
do difference destroy defun define defmacro defcc defprolog declare datatype cn cons? cons cond concat
compile cd cases call close bind bound? boolean? boolean bootstrap (intern "bar!")
atom? asserta assertz assoc arity append and adjoin <-address address-> absvector? absvector abort])

Expand Down
60 changes: 60 additions & 0 deletions sources/prolog.shen
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,66 @@

(package shen []

(define asserta
Clause -> (assert* Clause top))

(define assertz
Clause -> (assert* Clause bottom))

(define assert*
[H <-- | B] Where -> (let F (predicate H)
X (terms H)
N (length X)
Vars (parameters N)
Arity (arity F)
Create (if (= Arity -1)
(do (eval (create-skeleton F Vars)) (put F dynamic []))
skip)
Insert (insert-info F X B [H <-- | B] Where)
F))

(define predicate
[F | _] -> F
F -> F)

(define terms
[_ | Terms] -> Terms
_ -> [])

(define create-skeleton
F Vars -> [defprolog F | (dynamic-default F Vars)])

(define dynamic-default
F Vars -> (append Vars [<-- [call-dynamic (cons-form Vars) [get F dynamic]] (intern ";")]))

(define insert-info
F X B Clause Where -> (let G (gensym g)
Create (eval (append [defprolog G] X [<-- | B]))
Entry [(fn G) | Clause]
Dynamic (get F dynamic)
New (if (= Where top)
[Entry | Dynamic]
(append Dynamic [Entry]))
(put F dynamic New)))

(defprolog call-dynamic
Vars (- [[G | _] | _]) <-- (callrec G Vars);
Vars (- [_ | Gs]) <-- (call-dynamic Vars Gs);)

(define callrec
G [] Bindings Lock Key Continuation -> (G Bindings Lock Key Continuation)
G [X | Y] Bindings Lock Key Continuation -> (callrec (G X) Y Bindings Lock Key Continuation))

(define retract
[H <-- | B] -> (let F (predicate H)
Info (get F dynamic)
(put F dynamic (retract-clause [H <-- | B] Info))))

(define retract-clause
_ [] -> []
Clause [[_ | Clause] | Info] -> Info
Clause [Info | Infos] -> [Info | (retract-clause Clause Infos)])

(define compile-prolog
F Clauses -> (compile (/. X (<defprolog> X)) [F | Clauses]))

Expand Down
2 changes: 1 addition & 1 deletion sources/toplevel.shen
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
E -> (do (pr (error-to-string E) (stoutput)) (nl 0)))

(define credits
-> (do (output "~%Shen, www.shenlanguage.org, copyright (C) 2010-2022, Mark Tarver~%")
-> (do (output "~%Shen, www.shenlanguage.org, copyright (C) 2010-2023, Mark Tarver~%")
(output "version: S~A, language: ~A, platform: ~A ~A~%"
(value *version*) (value *language*) (value *implementation*) (value *release*))
(output "port ~A, ported by ~A~%~%" (value *port*) (value *porters*))))
Expand Down
1 change: 0 additions & 1 deletion sources/types.shen
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
(declare destroy [symbol --> symbol])
(declare difference [[list A] --> [[list A] --> [list A]]])
(declare do [A --> [B --> B]])
(declare dynamic [symbol --> [list symbol]])
(declare <e> [[str [list A] B] --> [str [list A] [list C]]])
(declare <!> [[str [list A] B] --> [str [list A] [list A]]])
(declare <end> [[str [list A] B] --> [str [list A] B]])
Expand Down

0 comments on commit 6da530c

Please sign in to comment.