-
Notifications
You must be signed in to change notification settings - Fork 38
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
Fix for namespaced keywords #83
Conversation
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.
Some suggestions
src/compliment/context.clj
Outdated
@@ -18,6 +18,7 @@ | |||
(-> s | |||
(str/replace "{" "(compliment-hashmap ") | |||
(str/replace "}" ")") | |||
(str/replace #"::([-\w]+/)" (fn [[_ kw-ns]] (str ":" kw-ns))) |
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.
It seems more accurate to query (ns-aliases *ns*)
to obtain a namespace name to be prepended to kw-ns
?
{:keys [key1 key2] :strs [key3]} m2 | ||
{:keys [key1 key2] :strs [key3] :syms [key4]} m2 | ||
{:keys [:a/key5 :b/key6]} m3 | ||
{:c/keys [key7 key8]} m4 |
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.
Shouldn't there also be test coverage for...?
:c/syms
::c/keys
::c/syms
@@ -82,10 +82,13 @@ | |||
'(let [foo 42, | |||
[bar baz] lst | |||
{a :a, {b :b :as c} :b, [d] :d} m | |||
{:keys [key1 key2] :strs [key3]} m2 | |||
{:keys [key1 key2] :strs [key3] :syms [key4]} m2 | |||
{:keys [:a/key5 :b/key6]} m3 |
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 think there should also be coverage for {:keys [::a/keyN ::b/keyM]}
(i.e. ns-aliased)
@@ -12,6 +12,10 @@ | |||
|
|||
(def letfn-like-forms '#{letfn}) | |||
|
|||
(def destructuring-keys #{:keys :strs :syms}) | |||
|
|||
(def destructuring-key-names #{"keys" "strs" "syms"}) |
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.
(def destructuring-key-names #{"keys" "strs" "syms"}) | |
(def destructuring-key-names (into #{} (map name) destructuring-keys)) |
@vemv Fixed, thank you for review. |
@vmfhrmfoaj Your changes look to good to me. Can you also mention them in the changelog, please? |
@bbatsov I updated. |
Thanks for accurately satisfying all suggestions! |
@vmfhrmfoaj Can you also rebase on top |
CHANGELOG.md
Outdated
@@ -2,6 +2,9 @@ | |||
|
|||
### master (unreleased) | |||
|
|||
- Complete local bindings declared in map destructuring with namespaced keywords. |
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.
Please, prefix those entries with the link to the PR.
… generating the context `read-string` try to resolve an alias of namespaced keyword and throw 'invalid token' exception if there is no the alias. so, `try-read-replacing-maps` return `nil` if the context is contained the aliased namespace keyword. (except if alias is already added to *ns*) Benchmark before: Evaluation count : 126 in 6 samples of 21 calls. Execution time mean : 5.085000 ms Execution time std-deviation : 141.272913 µs Execution time lower quantile : 4.982329 ms ( 2.5%) Execution time upper quantile : 5.293605 ms (97.5%) Overhead used : 5.443103 ns -------------------------------------------------------------------------------- Benchmark after, string ver `(str/replace "::" ":")`: Evaluation count : 126 in 6 samples of 21 calls. Execution time mean : 5.219457 ms Execution time std-deviation : 213.306958 µs Execution time lower quantile : 5.046182 ms ( 2.5%) Execution time upper quantile : 5.456526 ms (97.5%) Overhead used : 6.702279 ns -------------------------------------------------------------------------------- Benchmark after, regular expression ver: Evaluation count : 120 in 6 samples of 20 calls. Execution time mean : 5.265777 ms Execution time std-deviation : 208.308093 µs Execution time lower quantile : 5.122747 ms ( 2.5%) Execution time upper quantile : 5.522446 ms (97.5%) Overhead used : 5.454686 ns
if use namespaced keywords, can't complete destructured variables Before benchmark: Evaluation count : 126 in 6 samples of 21 calls. Execution time mean : 5.070952 ms Execution time std-deviation : 86.793704 µs Execution time lower quantile : 5.011867 ms ( 2.5%) Execution time upper quantile : 5.208428 ms (97.5%) Overhead used : 5.254489 ns -------------------------------------------------------------------------------- After benchmark: Evaluation count : 120 in 6 samples of 20 calls. Execution time mean : 5.110484 ms Execution time std-deviation : 139.512617 µs Execution time lower quantile : 4.972072 ms ( 2.5%) Execution time upper quantile : 5.263425 ms (97.5%) Overhead used : 6.469988 ns
Thanks! |
First of all, thank you for developing and maintaining 'compliment'.
I found problems related to namespaced keywords:
compliment.context/try-read-replacing-maps
returnnil
if aliased namespace keywords(e.g.::my-ns/keyword
) are contained in context string. (read-str
try to resolve the alias)I changed
try-read-replacing-maps
to replace aliased namespace keyword to namespaced keyword(e.g.:my-ns/keyword
) to avoid the problem.compliment.sources.local-bindings/parse-binding
ignore variables that destructuring the map with namespaced keywords:parse-binding
to handle namespaced keywords.