Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Multi-arity featurec #118

Merged
merged 18 commits into from
Apr 1, 2016
Merged

Multi-arity featurec #118

merged 18 commits into from
Apr 1, 2016

Conversation

lvh
Copy link
Contributor

@lvh lvh commented Mar 28, 2016

Closes #106, #117. Builds on #111.

`(l/all ~@logic-terms))
[0 _] (let [u (gensym)
logic-terms (map (partial featurec-term u) attr-terms)]
`(l/fresh [~u] ~@logic-terms))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: you could write this as one clause, but then it would change what all of the old (= (:ip x) "10.0.0.1") generated code would look like.

@lvh
Copy link
Contributor Author

lvh commented Mar 28, 2016

This adds a new feature, so I should probably add an explicit test that just runs the query.

@lvh
Copy link
Contributor Author

lvh commented Mar 28, 2016

Oh, and this does not yet solve the infix version of this problem... But that should probably be a different ticket/PR so as to keep these as small as possible...


[((= value ((attr lvar) :seq)) :seq)]
`(l/featurec ~lvar {~attr ~value})
[(('= & terms) :seq)]
Copy link
Contributor Author

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.

@codecov-io
Copy link

Current coverage is 92.00%

Merging #118 into master will decrease coverage by -0.23% as of 8c6ae06

@@            master   #118   diff @@
=====================================
  Files           17     17       
  Stmts          219    225     +6
  Branches        10     11     +1
  Methods          0      0       
=====================================
+ Hit            202    207     +5
- Partial         10     11     +1
  Missed           7      7       

Review entire Coverage Diff as of 8c6ae06

Powered by Codecov. Updated on successful CI builds.

@lvh
Copy link
Contributor Author

lvh commented Mar 29, 2016

OK. I've added the test and I'm working on the infix stuff in a separate PR; so this is ready for review after #111, which it is dependent on.

@lvh
Copy link
Contributor Author

lvh commented Mar 29, 2016

I have also filed #119 since that is some presumably-confusing behavior we're getting out of the logic engine here.

(is (thrown? IllegalArgumentException
(#'q/dsl->logic '(= (:ip x) "10.0.0.1" "10.0.0.1"))))
(is (thrown? IllegalArgumentException
(#'q/dsl->logic '(= (:ip x) "10.0.0.1" "10.0.0.2")))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this assertion repeated by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope; this tests subtly different things (and perhaps I should document that)

The former has multiple literals but they are still consistent
The latter has multiple literals but they are inconsistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the former is rationally equivalent to just having 1 literal; the latter is internally inconsistent and will never succeed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I thought I scanned it more thoroughly - I didn't realize the ips only differ by the final octet, 1 vs 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add an assertion message and make the IPs more visually distinct

[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)))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 fresh form, it could be just as long as possibly even shorter.

@derwolfe
Copy link
Contributor

derwolfe commented Apr 1, 2016

This looks good to go - Thanks!

@derwolfe derwolfe merged commit be0f7e4 into RackSec:master Apr 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants