A local var for case without let?

74 views
Skip to first unread message

Pankaj Doharey

unread,
Oct 8, 2018, 8:05:21 PM10/8/18
to Clojure Dev

A common pattern while using 'case' is to set a temporary var using 'let'.


(let [lst '(1 2)]
  (case lst
    vector? (println "Vector : " lst )
    list? (println "A list : " lst )
    (println "Something else")))

Can we not have a case without a let like this :
(case [lst '(1 2)]
  vector? (println "Vector : " lst )
  list? (println "A list : " lst )
  (println "Something else")))

Can you think of a scenario where this can be a conflict?
Please do suggest if you think it is a good/bad idea.
I think it would a a nice syntactic convenience.

Gary Trakhman

unread,
Oct 8, 2018, 8:24:21 PM10/8/18
to cloju...@googlegroups.com
It's definitely the wrong idea for `case`, I don't think your sample code does what you think it does, but see the cond-let discussion from a week ago: https://groups.google.com/d/msg/clojure/Rq5_exjIxv0/yr5sue59AwAJ

--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.

Pankaj Doharey

unread,
Oct 8, 2018, 8:31:08 PM10/8/18
to Clojure Dev
Ok its a bad idea and condp covers the use case i was shooting for. Thanks.
Reply all
Reply to author
Forward
0 new messages