Skip to content
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

Implement case* #143

Open
jeaye opened this issue Dec 9, 2024 · 1 comment
Open

Implement case* #143

jeaye opened this issue Dec 9, 2024 · 1 comment
Assignees

Comments

@jeaye
Copy link
Member

jeaye commented Dec 9, 2024

Clojure's special case* form is used for constant type matching on literal values. It's wrapped by a case macro which breaks down the inputs into the necessary bits needed for case*. For example:

user=> (require '[clojure.pprint :as p])

user=> (p/with-pprint-dispatch
  p/code-dispatch
  (p/pprint (macroexpand '(case foo 1 "one" 2 "two"))))

;;;
(let*
  [G__170 foo]
  (case*
    G__170
    0
    0
    (throw
      (java.lang.IllegalArgumentException.
        (clojure.core/str "No matching clause: " G__170)))
    {1 [1 "one"], 2 [2 "two"]}
    :compact
    :int))

It has certain optimizations for when all of the values are integers. For example, if we add a string branch to the above:

user=> (p/with-pprint-dispatch
  p/code-dispatch
  (p/pprint (macroexpand '(case foo 1 "one" 2 "two" "three" :hmmm))))

;;;
(let*
  [G__176 foo]
  (case*
    G__176
    1
    3
    (throw
      (java.lang.IllegalArgumentException.
        (clojure.core/str "No matching clause: " G__176)))
    {0 [1 "one"], 1 [2 "two"], 3 ["three" :hmmm]}
    :compact
    :hash-equiv
    nil))

Resources

@jianlingzhong
Copy link
Contributor

i can look into this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants