This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Multi-arity featurec #118
Merged
Merged
Multi-arity featurec #118
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8799e4d
Add test for linking events
lvh e3d60d2
Add test for find-free-vars with linked events
lvh c7aba62
Test multiple consistent literals
lvh bcc6aa9
Add dsl-literal?
lvh 68a44ec
Refactor commutative featurec
lvh f02aaa2
Multiple literals should just always error
lvh 14f8abc
Add some fake gensym to make the test work
lvh 7d9b318
Make the tests pass
lvh 27280e0
Move fake gensym out into a macro
lvh e381297
Add test for multiple terms unified with literal
lvh 84be0ee
Multi-arity featurec
lvh 8bd4cc7
Code golf
lvh 44935ce
Add negative test for multi-arity featurec
lvh ff40552
Add positive test for multi-arity featurec
lvh 16277a1
Test multi-arity features without a literal
lvh 7edbed8
Add assertion message
lvh 197bb4f
Add assertion message; make IPs visually distinct
lvh f5a1a96
Merge branch 'master' into multi-arity-features
lvh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,24 @@ | |
(finally | ||
(in-ns (ns-name old-ns))))))) | ||
|
||
(def dsl-literal? | ||
"Is this a literal in the DSL?" | ||
string?) | ||
|
||
(defn ^:private dsl->logic | ||
"Given a DSL query, compile it to the underlying logic (miniKanren) | ||
expressions." | ||
[dsl-query] | ||
(m/match [dsl-query] | ||
[((= ((attr lvar) :seq) value) :seq)] | ||
(let [lvar (free-sym lvar)] | ||
`(l/featurec ~lvar {~attr ~value})) | ||
|
||
[((= value ((attr lvar) :seq)) :seq)] | ||
(let [lvar (free-sym lvar)] | ||
`(l/featurec ~lvar {~attr ~value})) | ||
[(('= & terms) :seq)] | ||
(let [{literals true attr-terms false} (group-by dsl-literal? terms) | ||
feature (fn [value [attr lvar]] | ||
`(l/featurec ~(free-sym lvar) {~attr ~value}))] | ||
(m/match [(count literals) (count attr-terms)] | ||
[1 1] (feature (first literals) (first attr-terms)) | ||
[1 _] `(l/all ~@(map (partial feature (first literals)) attr-terms)) | ||
[0 _] (let [u (gensym)] | ||
`(l/fresh [~u] ~@(map (partial feature u) attr-terms))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's pretty great that even though this adds clear features compared to the previous version and yet it is only 2 lines longer; the only reason it's longer is because it generates the same code for old samples; if it was OK to always generate a |
||
|
||
[(('and & terms) :seq)] | ||
(let [logic-terms (map dsl->logic terms)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I should consider testing the negative case where some of the terms are bogus, seeing what the error message is, and seeing if I can improve it by introducing a predicate on the terms.