ANN: Typed Clojure 1.0.17: Enhanced destructuring error messages

2021-08-02 Thread amb...@ambrosebs.com
ncy-information> improves error messages for vector destructuring. Instead of a low-level error referencing gensyms and expanded code, now destructuring is a first-class concept in error messages. Check out the runnable demo <https://github.com/typedclojure/let-error-demo> to see the

Destructuring in Kotlin

2020-03-25 Thread Alan Thompson
I was just reading an article on Kotlin and noticed they have nearly identical destructuring syntax as in Clojure: for ((k, v) in map) { println(“$k -> $v”) } Kotlin can also be compiled into JavaScript ES5.1 to target browsers, just like with ClojureScript. -- You received this mess

Re: Incomplete With Destructuring Lists

2017-05-11 Thread Mars0i
There is also this sort of solution: (def xs (range 9)) (let [ [[a b c] mid3 [d e f]] (partition 3 xs) ] [a b c mid3 d e f]) => (0 1 2 (3 4 5) 6 7 8) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to

Re: Incomplete With Destructuring Lists

2017-05-10 Thread Alan Thompson
args:(1 2 3 4 5 6 7 8 9 10) On Wed, May 10, 2017 at 9:04 PM, Alan Thompson <clooj...@gmail.com> wrote: > Don't try to force the destructuring DSL to do more than it was intended > to do. Just do it manually (or write a macro if you really insist): > > > > (defn foo > [&a

Re: Incomplete With Destructuring Lists

2017-05-10 Thread Alan Thompson
Don't try to force the destructuring DSL to do more than it was intended to do. Just do it manually (or write a macro if you really insist): (defn foo [& args] (let [ [a b c] (take 3 args) mid3 (take 3 (drop 3 args)) [g h i] (drop 6 args) ] (when (< 9 (cou

Incomplete With Destructuring Lists

2017-05-10 Thread Kevin Kleinfelter
Can I destructure a list, assigning the first and last few items individually, while putting several items from the middle into a list? I see that I can assign a list: (let [a '( 1 2 3 4)] ...) I can destructure the list as a whole: (let [[a b c d] '(1 2 3 4)] ...) I can destructure the

Re: Pattern matching Vs destructuring?

2017-01-27 Thread Francis Avila
There are two different concerns in what people refer to as "pattern matching": binding and flow-control. Destructuring only addresses binding. Pattern matching emphasizes flow control, and some binding features typically come along for free with whatever syntax it uses. (But

Re: Pattern matching Vs destructuring?

2017-01-26 Thread 'Alan Forrester' via Clojure
On 27 Jan 2017, at 07:04, Didier <didi...@gmail.com> wrote: > Some languages have pattern matching, and Clojure is said to not have it > (without a library), but it does have destructuring. > > It seems to me that destructuring is the same as pattern matching, except > tha

Pattern matching Vs destructuring?

2017-01-26 Thread Didier
Some languages have pattern matching, and Clojure is said to not have it (without a library), but it does have destructuring. It seems to me that destructuring is the same as pattern matching, except that it can only be used inside function arguments, where as pattern matching can also be used

Re: associative destructuring on a list? (using :keys)

2017-01-09 Thread John Gabriele
Ah! Thank you, Francis! And sorry for the belated reply! I ran into a terse example of it at <https://clojure.org/guides/destructuring#_associative_destructuring> (see "(def options '(:debug true))") and was scratching my head. Now that you explained it though, I r

Re: associative destructuring on a list? (using :keys)

2017-01-06 Thread Francis Avila
A list/seq (not a vector) which is destructured as a map will be first read into a map as by (apply hash-map the-seq) This curiosity exists so the "keyword argument" idiom works: (defn my-options [_ & {:keys [a b] :as options}] options) => #'user/my-options (my-options nil :a 1 :b 2 :c 3) =>

associative destructuring on a list? (using :keys)

2017-01-06 Thread John Gabriele
I've used associative destructing in the usual fashion: some-app.core=> (def m {:a 1 :b 2}) #'some-app.core/m some-app.core=> (let [{:keys [a b]} m] (str a "-" b)) "1-2" but what is going on here: some-app.core=> (def li '(:a 1 :b 2)) #'some-app.core/li ;; Wat?

Re: Creating a spec for destructuring

2017-01-06 Thread Alex Miller
see links in your current styling. > > [image: Inline image 1] > > On Thu, Jan 5, 2017 at 9:18 AM, Alex Miller <a...@puredanger.com> wrote: > >> I thought this might be interesting to some here: >> >> http://blog.cognitect.com/blog/2017/1/3/spec-destructuring &

Re: Creating a spec for destructuring

2017-01-06 Thread Tim Visher
g.cognitect.com/blog/2017/1/3/spec-destructuring > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are modera

Creating a spec for destructuring

2017-01-05 Thread Alex Miller
I thought this might be interesting to some here: http://blog.cognitect.com/blog/2017/1/3/spec-destructuring -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that post

Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-24 Thread Matching Socks
In case it's not clear from the above, {:keys [...]} is a technique for *map* destructuring of associative data structures. (let [{:keys [a b]} {:a 1 :b 2}] [a b]) [1 2] As documented at http://clojure.org/reference/special_forms, :keys takes a vector of the symbols to bind. -- You received

Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Nicola Mometto
that's an implementation detail you should not rely on. it only works to support keyword arguments to functions On 23 Jan 2016 17:36, "Harold" <hhaus...@gmail.com> wrote: > Hello, > > While destructuring yesterday, I encountered this difference: > > > (let [

Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Gregg Reynolds
On Jan 23, 2016 11:36 AM, "Harold" <hhaus...@gmail.com> wrote: > > Hello, > > While destructuring yesterday, I encountered this difference: > > > (let [{:keys [:a :b]} '(:a 1 :b 2)] [a b]) > [1 2] > > > (let [{:keys [:a :b]} [:a 1 :b 2]] [a b])

Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Harold
Hello, While destructuring yesterday, I encountered this difference: > (let [{:keys [:a :b]} '(:a 1 :b 2)] [a b]) [1 2] > (let [{:keys [:a :b]} [:a 1 :b 2]] [a b]) [nil nil] I have read some of the relevant documentation and some related blog posts, but I am still having trouble expl

is destructuring implemented as a macro?

2015-05-13 Thread piastkrakow
/get map__1202 :port) host (clojure.core/get map__1202 :host)] So, if the destructuring is re-written by macroexpand, then I can reasonably assume that destructuring is implemented as a macro, yes? -- You received this message because you are subscribed to the Google Groups Clojure group

Re: is destructuring implemented as a macro?

2015-05-13 Thread Gary Trakhman
map__1202 :tls) user (clojure.core/get map__1202 :user) port (clojure.core/get map__1202 :port) host (clojure.core/get map__1202 :host)] So, if the destructuring is re-written by macroexpand, then I can reasonably assume that destructuring is implemented as a macro, yes? -- You received

Re: is destructuring implemented as a macro?

2015-05-13 Thread Fluid Dynamics
destructuring into something of your own, your best bet is generally to write a macro that expands into a fn or let form and let that handle the destructuring. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email

Re: :keys and :or destructuring where defaults refer to one another

2014-12-12 Thread Michał Marczyk
I created a ticket and posted a patch: http://dev.clojure.org/jira/browse/CLJ-1613 On 12 December 2014 at 08:35, Michał Marczyk michal.marc...@gmail.com wrote: (let [foo 1 bar 2 {:keys [bar foo] :or {foo 3 bar (inc foo)}} {}] {:foo foo :bar bar}) ;= {:foo 3, :bar

:keys and :or destructuring where defaults refer to one another

2014-12-11 Thread Michael Blume
If I make my defaults on a :keys :or destructuring depend on the values of other keys, I *can* get a compile-time error, depending on what order I give the keys https://gist.github.com/MichaelBlume/4891dafdd31f0dcbc727 Is this on-spec behavior? Should the former be allowed but not the latter

Re: :keys and :or destructuring where defaults refer to one another

2014-12-11 Thread Christopher Small
my defaults on a :keys :or destructuring depend on the values of other keys, I *can* get a compile-time error, depending on what order I give the keys https://gist.github.com/MichaelBlume/4891dafdd31f0dcbc727 Is this on-spec behavior? Should the former be allowed but not the latter? Should

Re: :keys and :or destructuring where defaults refer to one another

2014-12-11 Thread adrian . medina
11, 2014 6:11:59 PM UTC-5, Michael Blume wrote: If I make my defaults on a :keys :or destructuring depend on the values of other keys, I *can* get a compile-time error, depending on what order I give the keys https://gist.github.com/MichaelBlume/4891dafdd31f0dcbc727 Is this on-spec behavior

Re: :keys and :or destructuring where defaults refer to one another

2014-12-11 Thread Michael Blume
my defaults on a :keys :or destructuring depend on the values of other keys, I *can* get a compile-time error, depending on what order I give the keys https://gist.github.com/MichaelBlume/4891dafdd31f0dcbc727 Is this on-spec behavior? Should the former be allowed but not the latter? Should both

Re: :keys and :or destructuring where defaults refer to one another

2014-12-11 Thread adrian . medina
Common Lisp has a really well thought approach to parameter lambda lists. If you feel strongly about resolving this ambiguity and enforcing consistency around sequential binding in the destructuring syntax, perhaps that would be a good place to root a design you can flesh out in Jira. Here's

Re: :keys and :or destructuring where defaults refer to one another

2014-12-11 Thread Michał Marczyk
in the destructuring syntax, perhaps that would be a good place to root a design you can flesh out in Jira. Here's a resource you might find interesting as a starting point: http://www.lispworks.com/documentation/HyperSpec/Body/03_dad.htm On Thursday, December 11, 2014 11:55:36 PM UTC-5, Michael Blume wrote

annotating functions that use destructuring in core.typed

2014-10-15 Thread kurofune
:mandatory {:a Number :b String})]) (defn mult-arity [n s] {:a n :b s}) but with functions that use destructuring in their body, I run into problems. ;; Does not work. (ann map-span [Map Fn - Map]) (defn map-span [m f] (into {} (for [[k v] m] [k (f v)]))) clojure.lang.ExceptionInfo

Re: annotating functions that use destructuring in core.typed

2014-10-15 Thread Ambrose Bonnaire-Sergeant
-arity [n s] {:a n :b s}) but with functions that use destructuring in their body, I run into problems. ;; Does not work. (ann map-span [Map Fn - Map]) (defn map-span [m f] (into {} (for [[k v] m] [k (f v)]))) clojure.lang.ExceptionInfo: Type Checker: Found 8 errors :: {:type-error :top

Re: annotating functions that use destructuring in core.typed

2014-10-15 Thread kurofune
(ann plus1 [Number - Number]) (defn plus1 [n] (+ n 1)) ;; Works as expected (ann mult-arity [Number String - (HMap :mandatory {:a Number :b String})]) (defn mult-arity [n s] {:a n :b s}) but with functions that use destructuring in their body, I run into problems. ;; Does not work

Re: annotating functions that use destructuring in core.typed

2014-10-15 Thread Ambrose Bonnaire-Sergeant
String - (HMap :mandatory {:a Number :b String})]) (defn mult-arity [n s] {:a n :b s}) but with functions that use destructuring in their body, I run into problems. ;; Does not work. (ann map-span [Map Fn - Map]) (defn map-span [m f] (into {} (for [[k v] m] [k (f v

Re: annotating functions that use destructuring in core.typed

2014-10-15 Thread kurofune
destructuring in their body, I run into problems. ;; Does not work. (ann map-span [Map Fn - Map]) (defn map-span [m f] (into {} (for [[k v] m] [k (f v)]))) clojure.lang.ExceptionInfo: Type Checker: Found 8 errors :: {:type-error :top-level-error, :errors (#ExceptionInfo

destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread John Gabriele
Why is it that although this works: ~~~clojure (defn foo [ args] (let [{:keys [a b]} args] (str a \~ b))) ;;= #'some-app.core/foo (foo :a 1 :b 2) ;;= 1~2 ~~~ this does not: ~~~clojure (let [{:keys [a b]} [:a 1 :b 2 :c 3]] (str a \~ b)) ;;= ~ ~~~ ? And even stranger, *this* *does* work:

Re: destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread Ben Wolfson
The reason is that in the macroexpansion of let, map-based destructuring has a seq? test which the list passes but the vector doesn't: (clojure.pprint/pprint (macroexpand-1 '(let [{:keys [a b]} [:a 1]] a))) (let* [map__34214 [:a 1] map__34214 (if (clojure.core/seq? map__34214

Re: destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread Ben Wolfson
... the other half of the answer being that when you have rest args with (defn foo [ args] ...), args is bound to a seq. On Wed, Aug 27, 2014 at 11:27 AM, Ben Wolfson wolf...@gmail.com wrote: The reason is that in the macroexpansion of let, map-based destructuring has a seq? test which

Re: destructuring help: `(let [{:keys [...]} ...]` in a `defn` vs in a `let`

2014-08-27 Thread James Reeves
Apparently a list can be destructured as a map, but a vector cannot. The args syntax returns the result as a list, not a vector. - James On 27 August 2014 19:20, John Gabriele jmg3...@gmail.com wrote: Why is it that although this works: ~~~clojure (defn foo [ args] (let [{:keys [a b]}

Re: destructuring let and for

2014-06-11 Thread Francesco Lunelli
. - James On 10 June 2014 16:43, Francesco Lunelli francesc...@gmail.com wrote: Hello everybody, I have a newbie question about destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one

destructuring let and for

2014-06-10 Thread Francesco Lunelli
Hello everybody, I have a newbie question about destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one two three ...) I now only that elements are strings. I need to to take every element

Re: destructuring let and for

2014-06-10 Thread James Reeves
destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one two three ...) I now only that elements are strings. I need to to take every element and use it as the name of a variable inside a let

Re: destructuring let and for

2014-06-10 Thread Francesco Lunelli
have a newbie question about destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one two three ...) I now only that elements are strings. I need to to take every element and use

Re: destructuring let and for

2014-06-10 Thread Paul Gearon
. - James On 10 June 2014 16:43, Francesco Lunelli francesc...@gmail.com wrote: Hello everybody, I have a newbie question about destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one

Re: destructuring let and for

2014-06-10 Thread Francesco Lunelli
about destructuring and assigning and didn't find an answer in documentation or books. I have a list that contains an arbitrary number of elements for example '(one two three ...) I now only that elements are strings. I need to to take every element and use it as the name of a variable

Re: destructuring let and for

2014-06-10 Thread Paul Gearon
a map, but without knowing more about the purpose, it's difficult to say. - James On 10 June 2014 16:43, Francesco Lunelli francesc...@gmail.com wrote: Hello everybody, I have a newbie question about destructuring and assigning and didn't find an answer in documentation or books. I have

improving as- macro by adding destructuring support

2014-05-09 Thread Nahuel Greco
The as- macro doesn't work with destructuring. This is invalid code: (- [1 2] (as- [a b] [a (inc b)] [(inc a) b])) Because it is expanded to: (let [[a b] [1 2] [a b] [a (inc b)] [a b] [(inc a) b]] [a b]) ;; this last expression

clojure key destructuring motivation

2014-01-18 Thread t x
the reason why existing let key destructuring is backwards To me, it seems the fictional leth example is much simpler -- the mental model is just do pattern matching The current let example seems to be: okay, um, so for cat, you look at :cat, then you look at :foo, then you think (:cat (:foo

Re: clojure key destructuring motivation

2014-01-18 Thread Alex Miller
} a] [cat dog bar]) I don't understand the reason why existing let key destructuring is backwards To me, it seems the fictional leth example is much simpler -- the mental model is just do pattern matching The current let example seems to be: okay, um, so for cat, you look at :cat, then you

Re: clojure key destructuring motivation

2014-01-18 Thread Stefan Kanev
On 18/01/14, Alex Miller wrote: I have some sympathy for this view of things as it was a question I had while learning Clojure as well. The general justification for the current behavior is that the thing being bound is always on the left and the expression defining it is always on the

Re: clojure key destructuring motivation

2014-01-18 Thread Matching Socks
Map keys need to be unique. Therefore, it's tidy for the symbol to be the key to the destructuring map. On Saturday, January 18, 2014 2:57:09 PM UTC-5, Alex Miller wrote: I have some sympathy for this view of things as it was a question I had while learning Clojure as well. The general

Re: clojure key destructuring motivation

2014-01-18 Thread Alex Miller
On Saturday, January 18, 2014 2:19:08 PM UTC-6, Stefan Kanev wrote: On 18/01/14, Alex Miller wrote: I have some sympathy for this view of things as it was a question I had while learning Clojure as well. The general justification for the current behavior is that the thing being

Re: Feedback on destructuring code walkthrough? (could not nest :keys inside :keys)

2013-11-23 Thread David James
b2 b]) (foo {:a 1 :b {:b1 2 :b2 3}}) ; = [1 2 3 {:b2 3, :b1 2}] On 22 November 2013 19:06, David James david...@gmail.com javascript: wrote: I made a quick destructuring code walkthrough at https://github.com/xpe/clj-destruct/blob/master/src/destruct/core.cljhttps://www.google.com

Re: Feedback on destructuring code walkthrough? (could not nest :keys inside :keys)

2013-11-23 Thread Karsten Schmidt
No prob, you might also want to check Jay Fields' blog post (one of the most often cited resources) for more destructuring options: http://blog.jayfields.com/2010/07/clojure-destructuring.html On 23 November 2013 18:19, David James davidcja...@gmail.com wrote: Thanks Karsten! I updated

Feedback on destructuring code walkthrough? (could not nest :keys inside :keys)

2013-11-22 Thread David James
I made a quick destructuring code walkthrough at https://github.com/xpe/clj-destruct/blob/master/src/destruct/core.clj I was hoping to show how to nest :keys inside of :keys but failed. Did I overlook something? -- -- You received this message because you are subscribed to the Google Groups

Re: Feedback on destructuring code walkthrough? (could not nest :keys inside :keys)

2013-11-22 Thread Karsten Schmidt
a quick destructuring code walkthrough at https://github.com/xpe/clj-destruct/blob/master/src/destruct/core.clj I was hoping to show how to nest :keys inside of :keys but failed. Did I overlook something? -- -- You received this message because you are subscribed to the Google Groups Clojure

Re: Doubt about Destructuring rest sequences as map key/value pairs

2013-09-29 Thread Daniel Meneses
thanks !! On Saturday, September 28, 2013 9:57:13 PM UTC-3, Ambrose Bonnaire-Sergeant wrote: The or syntax should be {lastname Meneses} Thanks, Ambrose On Sun, Sep 29, 2013 at 8:54 AM, Daniel Meneses Báez dap...@gmail.comjavascript: wrote: I think that the second and third lines in

Re: Doubt about Destructuring rest sequences as map key/value pairs

2013-09-29 Thread Ambrose Bonnaire-Sergeant
No problem. On Mon, Sep 30, 2013 at 9:11 AM, Daniel Meneses dap...@gmail.com wrote: thanks !! On Saturday, September 28, 2013 9:57:13 PM UTC-3, Ambrose Bonnaire-Sergeant wrote: The or syntax should be {lastname Meneses} Thanks, Ambrose On Sun, Sep 29, 2013 at 8:54 AM, Daniel

Doubt about Destructuring rest sequences as map key/value pairs

2013-09-28 Thread Daniel Meneses Báez
I think that the second and third lines in the following example should yield the same output... *user= (defn my-name [ {:keys [name lastname] :or {:lastname Meneses}}] (str name lastname))* *#'user/my-name* *user= (my-name :name Daniel :lastname Meneses)* *Daniel Meneses* *user= (my-name :name

Re: Doubt about Destructuring rest sequences as map key/value pairs

2013-09-28 Thread Ambrose Bonnaire-Sergeant
The or syntax should be {lastname Meneses} Thanks, Ambrose On Sun, Sep 29, 2013 at 8:54 AM, Daniel Meneses Báez dap...@gmail.comwrote: I think that the second and third lines in the following example should yield the same output... *user= (defn my-name [ {:keys [name lastname] :or

Shortcut for variadic map destructuring?

2013-06-06 Thread JvJ
Consider the following: (let [ [{:keys [] :as m}] [:a 1 :b 2 :c 3]] m) == {:a 1 :b 2 :c 3} Is there a shorter form of [{:keys [] :as m}]? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Shortcut for variadic map destructuring?

2013-06-06 Thread JvJ
Well... I'm a dingus. [{:as m}] On Thursday, 6 June 2013 15:23:22 UTC-4, JvJ wrote: Consider the following: (let [ [{:keys [] :as m}] [:a 1 :b 2 :c 3]] m) == {:a 1 :b 2 :c 3} Is there a shorter form of [{:keys [] :as m}]? -- -- You received this message because you are

Re: Shortcut for variadic map destructuring?

2013-06-06 Thread Ambrose Bonnaire-Sergeant
[ {:as m}] On Fri, Jun 7, 2013 at 3:23 AM, JvJ kfjwhee...@gmail.com wrote: Consider the following: (let [ [{:keys [] :as m}] [:a 1 :b 2 :c 3]] m) == {:a 1 :b 2 :c 3} Is there a shorter form of [{:keys [] :as m}]? -- -- You received this message because you are subscribed to

Re: Shortcut for variadic map destructuring?

2013-06-06 Thread Jim - FooBar();
On 06/06/13 20:23, JvJ wrote: Is there a shorter form of [{:keys [] :as m}]? if you don't care about the actual keys just do this: [ {:as m}] HTH, Jim -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Shortcut for variadic map destructuring?

2013-06-06 Thread JvJ
I just realized it after I posted, but thanks for the help anyways. On Thursday, 6 June 2013 15:27:28 UTC-4, Jim foo.bar wrote: On 06/06/13 20:23, JvJ wrote: Is there a shorter form of [{:keys [] :as m}]? if you don't care about the actual keys just do this: [ {:as m}] HTH, Jim

Re: Question about destructuring with :keys :or and :as

2013-05-04 Thread Ryan
. On Friday, May 3, 2013 10:22:59 PM UTC+3, Sean Corfield wrote: The :as key binds the entire _original_ map. The :or defaults apply only to the bound variables extracted from the map. It caught me out when I first used map destructuring but I soon got used

Re: Question about destructuring with :keys :or and :as

2013-05-04 Thread Peter Taoussanis
Hi Ryan, I actually run into this quite often and feel that it's something that's missing from destructuring: http://grokbase.com/t/gg/clojure/128z9e3sqj/possible-to-merge-destructuring-or-defaults-with-as Basically, I'd advocate the addition of a new `:merge-as` destructure option

Re: Question about destructuring with :keys :or and :as

2013-05-04 Thread Ryan
UTC+3, Peter Taoussanis wrote: Hi Ryan, I actually run into this quite often and feel that it's something that's missing from destructuring: http://grokbase.com/t/gg/clojure/128z9e3sqj/possible-to-merge-destructuring-or-defaults-with-as Basically, I'd advocate the addition of a new `:merge

Question about destructuring with :keys :or and :as

2013-05-03 Thread Ryan
Hello all, I have a question regarding the default values when destructuring with :keys Let's assume that we have the following function: *(defn my-function [{:keys [my-key] :or {my-key 5} :as params}] (str my-key value is (:my-key params)))* A few test runs: *user= (my-function {:my

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Anthony Rosequist
all, I have a question regarding the default values when destructuring with :keys Let's assume that we have the following function: *(defn my-function [{:keys [my-key] :or {my-key 5} :as params}] (str my-key value is (:my-key params)))* A few test runs: *user= (my-function {:my

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Ryan
} :as params}] * (str my-key value is my-key))* On Friday, May 3, 2013 1:52:46 PM UTC-5, Ryan wrote: Hello all, I have a question regarding the default values when destructuring with :keys Let's assume that we have the following function: *(defn my-function [{:keys [my-key] :or {my-key 5

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Sean Corfield
The :as key binds the entire _original_ map. The :or defaults apply only to the bound variables extracted from the map. It caught me out when I first used map destructuring but I soon got used to it. On Fri, May 3, 2013 at 12:08 PM, Ryan arekand...@gmail.com wrote: Thanks Anthony for your

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Ryan
binds the entire _original_ map. The :or defaults apply only to the bound variables extracted from the map. It caught me out when I first used map destructuring but I soon got used to it. On Fri, May 3, 2013 at 12:08 PM, Ryan areka...@gmail.com javascript: wrote: Thanks Anthony

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Stanislas Nanchen
out when I first used map destructuring but I soon got used to it. On Fri, May 3, 2013 at 12:08 PM, Ryan areka...@gmail.com wrote: Thanks Anthony for your reply but I was already aware of that. I was hoping for some solution which would took care of the binding if :as was provided

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Ryan
Ah, the default nap is a nice idea :) -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To

Re: Question about destructuring with :keys :or and :as

2013-05-03 Thread Sean Corfield
to the bound variables extracted from the map. It caught me out when I first used map destructuring but I soon got used to it. On Fri, May 3, 2013 at 12:08 PM, Ryan areka...@gmail.com wrote: Thanks Anthony for your reply but I was already aware of that. I was hoping for some solution which would

Re: destructuring vectors with :or

2013-04-13 Thread rrs
[{a :a, b :b, c :c, :as m :or {a 2 b 3}} {:a 5 :c 6}] [a b c m]) -[5 3 6 {:c 6, :a 5}] On Friday, April 12, 2013 6:00:27 PM UTC-4, henry clifford wrote: I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point

Re: destructuring vectors with :or

2013-04-13 Thread henry clifford
Fantastic, thank you! On Friday, April 12, 2013 11:13:23 PM UTC+1, John Hume wrote: You can use a map destructuring form on a vector like so: (let [{x 0 y 1 :or {x 0 y 0}} [7]] [x y]) returns [7 0] On Fri, Apr 12, 2013 at 5:00 PM, henry clifford h.a.cl...@gmail.comjavascript: wrote

destructuring vectors with :or

2013-04-12 Thread henry clifford
I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7}) (let [{:keys [x y] :or {x 0 y 0}} point] (println x: x y: y)) x: 0 y: 7 but I can't get this to work with vectors: (def point [7]) (let [[x y :or [0 0]] point] (println x: x y: y)) what' I'm

Re: destructuring vectors with :or

2013-04-12 Thread John D. Hume
You can use a map destructuring form on a vector like so: (let [{x 0 y 1 :or {x 0 y 0}} [7]] [x y]) returns [7 0] On Fri, Apr 12, 2013 at 5:00 PM, henry clifford h.a.cliff...@gmail.com wrote: I'm trying to use the :or destructuring syntax as seen here applied to a map (def point {:y 7

Re: Map destructuring variations in Pedestal

2013-03-20 Thread Sean Corfield
Pretty sure it's just a typo / bug. I think it should read: {servlet ::servlet type ::type :or {type :jetty} :as service-map} On Tue, Mar 19, 2013 at 10:09 PM, Matching Socks phill.w...@gmail.com wrote: I'm puzzled by two :or syntaxes that are used in io.pedestal.service.http,

Re: Map destructuring variations in Pedestal

2013-03-20 Thread Alan Malloy
Yes. Apparently you can put whatever garbage you want into the `:or` map: each local is looked up in that map to see if it has a default, but nobody ever checks to see if there are unused keys in the defaults map. So `:or {::type :jety}` has no impact at all on the generated code: there is no

Re: nested map destructuring

2013-03-20 Thread Alan Thompson
this---layer 1: {w :weigths, u :uni-probs, b :bi-probs, t :tri-probs} Then, instead of an atomic w, recursively substitute another destructuring form, which will destructure the value of that w (which is also a map). This form is {:keys [w1 w2 w3]}. That gives you complete layer 2: {{:keys [w1

Re: nested map destructuring

2013-03-20 Thread John D. Hume
On Tue, Mar 19, 2013 at 2:58 PM, Jim - FooBar(); jimpil1...@gmail.com wrote: awsome!...the full thing actually is {{:keys [w1 w2 w3]} :weights u :uni-probs b :bi-probs t :tri-probs} You might also consider {:keys [uni-probs bi-probs tri-probs]} {:keys [w1 w2 w3]} :weights} -- -- You received

nested map destructuring

2013-03-19 Thread Jim - FooBar();
Hello all, can anyone help me destructure the following map in order to access directly w1 w2 w3 ? I've been trying for 20 minutes now! (how useless am I? :( ) {:weights {:w1 0.2 :w2 0.3 :w3 0.5} :uni-probs {...} :bi-probs {...} :tri-probs {...}} thanks, Jim -- -- You received this

Re: nested map destructuring

2013-03-19 Thread Marko Topolnik
On Tuesday, March 19, 2013 8:39:26 PM UTC+1, Jim foo.bar wrote: Hello all, can anyone help me destructure the following map in order to access directly w1 w2 w3 ? I've been trying for 20 minutes now! (how useless am I? :( ) {:weights {:w1 0.2 :w2 0.3 :w3 0.5} :uni-probs {...}

Re: nested map destructuring

2013-03-19 Thread Jim - FooBar();
On 19/03/13 19:49, Marko Topolnik wrote: {{:keys [w1 w2 w3]} :weights} awsome!...the full thing actually is {{:keys [w1 w2 w3]} :weights u :uni-probs b :bi-probs t :tri-probs} I always get confused when the order changes like that...thanks for unblocking me Marko :) Jim -- -- You

Re: nested map destructuring

2013-03-19 Thread Marko Topolnik
Think of it in layers, like this---layer 1: {w :weigths, u :uni-probs, b :bi-probs, t :tri-probs} Then, instead of an atomic w, recursively substitute another destructuring form, which will destructure the value of that w (which is also a map). This form is {:keys [w1 w2 w3]}. That gives you

Re: nested map destructuring

2013-03-19 Thread Jim - FooBar();
substitute another destructuring form, which will destructure the value of that w (which is also a map). This form is {:keys [w1 w2 w3]}. That gives you complete layer 2: {{:keys [w1 w2 w3]} :weigths, u :uni-probs, b :bi-probs, t :tri-probs} On Tuesday, March 19, 2013 8:58:43 PM UTC+1, Jim foo.bar

Map destructuring variations in Pedestal

2013-03-19 Thread Matching Socks
I'm puzzled by two :or syntaxes that are used in io.pedestal.service.http, from [io.pedestal/pedestal.service 0.1.1-SNAPSHOT], which is where following along with the Getting Started got me. In one place, it pairs :or with a map whose keys are symbols being bound in the outer form: {routes

args destructuring in functions?

2013-03-06 Thread Dave Sann
a minor thing. which do you prefer? (defn blah [x y zs] ...) , or, (defn blah [x y zs] ...) clojure core usually uses the first form. assoc, conj and so forth I have used this because it seems nicer for the caller (blah x y z1 z2 z3) rather than (blah x y [z1 z2 z3]) However, if you

Re: args destructuring in functions?

2013-03-06 Thread Marko Topolnik
One criterion would be how often you expect to call with zero or one z. If a lot, use ; otherwise prefer calling with an explicit collection. On Wednesday, March 6, 2013 12:45:38 PM UTC+1, Dave Sann wrote: a minor thing. which do you prefer? (defn blah [x y zs] ...) , or, (defn blah [x y

Re: args destructuring in functions?

2013-03-06 Thread Achint Sandhu
I personally think the first (current) approach is better since it ensures that the abstraction is not leaky from a caller's perspective, e,g. as a user I want to be able to type (+ 1 2 3 4 5) instead of (+ 1 2 [3 4 5]). The fact that the last 3 arguments end up as a collection inside the

Re: args destructuring in functions?

2013-03-06 Thread Marko Topolnik
I don't think that's the question here: x and y are each their own kind of argument, followed by zero or more same-kinded arguments. Take dissoc as an example and compare with select-keys. On Wednesday, March 6, 2013 12:54:13 PM UTC+1, Achint Sandhu wrote: I personally think the first

Destructuring Bind on Regex

2013-02-09 Thread JvJ
I wrote this little macro today that lets you do it. However, I feel like it was implemented in a pattern match library or something... but I'm not sure. Someone let me know if I'm re-inventing the wheel. If I'm not, here's the code: (defn re-bind-fn [str re bnds act forms] `(let

map destructuring mismatch between Clojure 1.4.0 and 1.5.0-RC1

2013-01-14 Thread Leonardo Borges
}} '()] message) IllegalArgumentException No value supplied for key: null clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77) I worked around it by doing the destructuring in two steps in my library but I'm wondering is this is intended behaviour? And if so, I'm sure it's been

Re: map destructuring mismatch between Clojure 1.4.0 and 1.5.0-RC1

2013-01-14 Thread Sean Corfield
around it by doing the destructuring in two steps in my library but I'm wondering is this is intended behaviour? And if so, I'm sure it's been discussed somewhere - maybe JIRA? - if someone would be so kind as to point me to the ticke, that'd be much appreciated. Cheers, Leonardo Borges

Re: map destructuring mismatch between Clojure 1.4.0 and 1.5.0-RC1

2013-01-14 Thread Leonardo Borges
}} '()] message) IllegalArgumentException No value supplied for key: null clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77) I worked around it by doing the destructuring in two steps in my library but I'm wondering is this is intended behaviour? And if so, I'm sure it's been

Re: Difference between JVM and CLR when destructuring a lazy sequence

2012-11-27 Thread Frank Failla
1.4.1 release. Several other bug fixes included in this update. -David On Friday, November 16, 2012 8:46:01 AM UTC-6, ffailla wrote: Thank you David for looking into this so quickly. For now I am working around this by not destructuring, but I look forward to the patch. Thanks. -Frank

Re: Difference between JVM and CLR when destructuring a lazy sequence

2012-11-23 Thread dmiller
, November 16, 2012 8:46:01 AM UTC-6, ffailla wrote: Thank you David for looking into this so quickly. For now I am working around this by not destructuring, but I look forward to the patch. Thanks. -Frank On Thursday, November 15, 2012 7:41:39 PM UTC-5, dmiller wrote: The difference

Re: Difference between JVM and CLR when destructuring a lazy sequence

2012-11-16 Thread ffailla
Thank you David for looking into this so quickly. For now I am working around this by not destructuring, but I look forward to the patch. Thanks. -Frank On Thursday, November 15, 2012 7:41:39 PM UTC-5, dmiller wrote: The difference is that the JVM version is correct and the CLR

  1   2   3   4   >