-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: case
and if
for branching in rule synthesis.
#6
Conversation
0a3b98d
to
1b6143c
Compare
case
and if
keywords for branching in rule synthesis.case
and if
keywords for branching in rule synthesis + memory macro
case
and if
keywords for branching in rule synthesis + memory macrocase
and if
for branching in rule synthesis + memory macro
case
and if
for branching in rule synthesis + memory macrocase
and if
for branching in rule synthesis.
1b6143c
to
9162002
Compare
loam/datalog.lisp
Outdated
(defun synthesize-if-segment (if-segment curr-rhs end-handle) | ||
(destructuring-bind (head if-form &rest branches) | ||
if-segment | ||
(assert (eql head 'if)) | ||
(assert (= (length branches) 2)) ; Must only have then and else branches. | ||
(loop with first = t | ||
for branch-segments in branches | ||
for test-segment = (if first `(when ,if-form) `(when (not ,if-form))) | ||
for curr-rhs-tail = (append curr-rhs (list test-segment)) | ||
when first do (setq first nil) | ||
append (synthesize-segments branch-segments (copy-list curr-rhs-tail) end-handle) | ||
into output-rules | ||
finally (return output-rules)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider something like this, which is easier for me to follow:
(defun synthesize-if-segment (if-segment curr-rhs end-handle) | |
(destructuring-bind (head if-form &rest branches) | |
if-segment | |
(assert (eql head 'if)) | |
(assert (= (length branches) 2)) ; Must only have then and else branches. | |
(loop with first = t | |
for branch-segments in branches | |
for test-segment = (if first `(when ,if-form) `(when (not ,if-form))) | |
for curr-rhs-tail = (append curr-rhs (list test-segment)) | |
when first do (setq first nil) | |
append (synthesize-segments branch-segments (copy-list curr-rhs-tail) end-handle) | |
into output-rules | |
finally (return output-rules)))) | |
(defun synthesize-if-segment (if-segment curr-rhs end-handle) | |
(assert (eql (car if-segment) 'if)) | |
(destructuring-bind (condition if-branch else-branch) | |
(cdr if-segment) | |
(flet ((aux (branch condition-form) | |
(synthesize-segments branch `(,@curr-rhs ,condition-form)) end-handle)) | |
(nconc (aux if-branch `(when ,condition)) | |
(aux else-branch `(when (not ,condition))))))) |
loam/datalog.lisp
Outdated
when (eql kind :predicate) | ||
collect (make-rule `(,lhs-signal <-- ,@(copy-list curr-rhs-tail))) into output-rules | ||
and collect rhs-handle into curr-rhs-tail | ||
when (or (eql kind :rule-binding) (eql kind :restriction)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you know you could write the following (for example)?
when (typep kind '(member :rule-binding :restriction))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, but please strongly consider using my suggested simplification of synthesize-if-segment
.
06ac308
to
2230f59
Compare
This PR:
case
andif
for branching in rule synthesis.