Re: rand-nth on empty collections

2015-09-30 Thread Mark Engelberg
On Wed, Sep 30, 2015 at 12:14 PM, Mark Engelberg 
wrote:

> I also think it makes perfect sense for rand-nth to throw an error on an
> empty collection.  That's because the first step is it needs to generate a
> random number between 0 and the length of the collection (0), which is
> impossible.  So it should throw an error.  Note that it is the *random
> generation of the index*, not the nth that conceptually is throwing the
> error.
>

To be clear, when I say that nth "conceptually is throwing the error", I
just mean that's how I rationalize Clojure's behavior.  That's not really
what's going on.  (rand-int 0) returns 0 (which it probably shouldn't,
given that the input is meant to be an exclusive upper bound).  So in fact,
the error is thrown by clojure.lang.RT.nthFrom, which is surprising.

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread Mark Engelberg
To me, the current behavior of nth makes sense because I know that the way
you traditionally write nth on a seq / linked list is to call rest n times
and then call first.  Since Clojure's rest and first on nil (or the empty
list) return nil, then I would expect nth to return nil when called on an
empty sequence for any n.  In other words, the behavior of nth makes
complete sense in the context of first and rest returning nil (which is
different from the philosophy of languages like Scheme, but is a feature
people get along with just fine in Clojure).

I also think it makes perfect sense for rand-nth to throw an error on an
empty collection.  That's because the first step is it needs to generate a
random number between 0 and the length of the collection (0), which is
impossible.  So it should throw an error.  Note that it is the *random
generation of the index*, not the nth that conceptually is throwing the
error.

To me, the only weird part is that rand-nth doesn't throw an error on nil.
In this context, I expect nil to be treated as an empty sequence.

Clojure has other inconsistencies relating to nil, so I wouldn't generally
make assumptions rand-nth's handling of nil in my code, but it's pretty
easy to write your code in such a way that you are using `seq`-ified linked
lists, and then later make some change so that things are getting passed
around before `seq` has been called on them, which would cause rand-nth to
break.  So this inconsistency is not ideal.

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: macro help

2015-09-30 Thread Michael Blume
 #foo gensyms don't survive across a 'break' in quoting

you can do

`(let [foo# bar]
  (other stuff
(foo# ...)))

but you can not do

`(let [foo# bar]
   ~(for [i s]
   `(foo# ...)))

or anything like that. The workaround is to create a gensym explicitly
using (gensym), let that, and splice it in wherever you need the gensym.

On Wed, Sep 30, 2015 at 1:29 PM Colin Yates  wrote:

> Hi all,
>
> I am banging my head against the wall - I think it is obvious but I have
> started too long:
>
> The use-case is that I want a form which takes a set of children. The form
> also takes in some form-wide state, like the form-wide validation, the
> values for each item etc. I want the macro, for each child, to decorate
> that child by extracting the validation errors and value from the form-wide
> state.
>
> So, assuming:
>  - validation looks like {:name "Duplicate name" :age "You must be at
> least 0"}
>  - form-values looks like {:name "a-duplicate-user" :age -1}
>
> then my form might look like:
>
> (form {:editing? true :values form-values :validation validation-report
> :on-change handle-form-change}
>   [form/text {:id :name}]
>   [form/number {:id :age}])
>
> After the macro I want the following code:
>
> [:div.form.horizontal
>   {:class "editing"}
>   [form/text {:id :name :value "a-duplicate-user" :errors "Duplicate name"
> :on-click (fn [e] (handle-form-change :name (-> e .target .value])]
>   [form/number {:id :age :value "-1" :errors "You must be at least 0"
> :on-click (fn [e] (handle-form-change :age (-> e .target .value))]]
>
> However, ideally the macro would _not_ emit the contents of the input as
> literals but would emit code that inspects the provided parameters at
> run-time (i.e. rather than :value "a-duplicate-user" I would much prefer
> :value (-> state values :name) as that will allow me to pass in an atom for
> example.
>
> I have tried so many variations and evaluating the state (e.g. (:editing?
> state)) works fine as the emitted code has the destructured values, but
> that doesn't work for an atom.
>
> Here is my attempt at trying to emit code that interrogates the provided
> parameter.
>
> (defmacro form [state & elements]
>   (let [state# state]
> `[:div.form.horizontal
>   {:class (if (:editing? state#) "editing" "editable")}
>   ~@(map (fn [[_ {:keys [id]} :as child]]
>(update child 1 assoc
>:editing? (:editing? state#)
>:value `(-> (:values state#) 'deref (get ~id))
>:on-change `(fn [e#]
>  (js/console.log "E: "
> (cljs.core/clj->js e#))
>  ((:on-change state#) ~id (-> e#
> .-target .-value)
>  elements)]))
>
> The error I am getting is that there is such var as the gen-sym's state#
> in the namespace.
>
> The generic thing I am trying to do is remove the boilerplate from each of
> the items in the form.
>
> Any and all suggestions are welcome.
>
> Thanks!
>
> --
> 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 unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


macro help

2015-09-30 Thread Colin Yates
Hi all,

I am banging my head against the wall - I think it is obvious but I have 
started too long:

The use-case is that I want a form which takes a set of children. The form 
also takes in some form-wide state, like the form-wide validation, the 
values for each item etc. I want the macro, for each child, to decorate 
that child by extracting the validation errors and value from the form-wide 
state.

So, assuming:
 - validation looks like {:name "Duplicate name" :age "You must be at least 
0"}
 - form-values looks like {:name "a-duplicate-user" :age -1}

then my form might look like:

(form {:editing? true :values form-values :validation validation-report 
:on-change handle-form-change}
  [form/text {:id :name}]
  [form/number {:id :age}])

After the macro I want the following code:

[:div.form.horizontal
  {:class "editing"}
  [form/text {:id :name :value "a-duplicate-user" :errors "Duplicate name" 
:on-click (fn [e] (handle-form-change :name (-> e .target .value])]
  [form/number {:id :age :value "-1" :errors "You must be at least 0" 
:on-click (fn [e] (handle-form-change :age (-> e .target .value))]]

However, ideally the macro would _not_ emit the contents of the input as 
literals but would emit code that inspects the provided parameters at 
run-time (i.e. rather than :value "a-duplicate-user" I would much prefer 
:value (-> state values :name) as that will allow me to pass in an atom for 
example.

I have tried so many variations and evaluating the state (e.g. (:editing? 
state)) works fine as the emitted code has the destructured values, but 
that doesn't work for an atom.

Here is my attempt at trying to emit code that interrogates the provided 
parameter.

(defmacro form [state & elements]
  (let [state# state]
`[:div.form.horizontal
  {:class (if (:editing? state#) "editing" "editable")}
  ~@(map (fn [[_ {:keys [id]} :as child]]
   (update child 1 assoc
   :editing? (:editing? state#)
   :value `(-> (:values state#) 'deref (get ~id))
   :on-change `(fn [e#]
 (js/console.log "E: " 
(cljs.core/clj->js e#))
 ((:on-change state#) ~id (-> e# 
.-target .-value)
 elements)]))

The error I am getting is that there is such var as the gen-sym's state# in 
the namespace.

The generic thing I am trying to do is remove the boilerplate from each of 
the items in the form.

Any and all suggestions are welcome. 

Thanks!

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread 'Jan-Paul Bultmann' via Clojure
Throwing an exception is probably the right thing to do if it's supposed to 
closely model the behavior of `nth`, but it wonder if it's the most usefull 
behavior in practice.
I would guess that it introduces `not-empty` checks everywhere, instead of only 
for the cases where you want to be shure that the nil returned is actually an 
element of the collection.

cheers Jan

> On 30 Sep 2015, at 20:18, Mark Engelberg  wrote:
> 
>> On Wed, Sep 30, 2015 at 12:14 PM, Mark Engelberg  
>> wrote:
>> I also think it makes perfect sense for rand-nth to throw an error on an 
>> empty collection.  That's because the first step is it needs to generate a 
>> random number between 0 and the length of the collection (0), which is 
>> impossible.  So it should throw an error.  Note that it is the *random 
>> generation of the index*, not the nth that conceptually is throwing the 
>> error.
> 
> To be clear, when I say that nth "conceptually is throwing the error", I just 
> mean that's how I rationalize Clojure's behavior.  That's not really what's 
> going on.  (rand-int 0) returns 0 (which it probably shouldn't, given that 
> the input is meant to be an exclusive upper bound).  So in fact, the error is 
> thrown by clojure.lang.RT.nthFrom, which is surprising.
> 
>  
> -- 
> 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 unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ANN Flambo 0.7.1 is released

2015-09-30 Thread Soren Macbeth
Hallo,

Flambo is a Clojure DSL for Apache Spark supporting Spark's core, streaming 
and SQL/DataFrame APIs. 0.7.1 targets Spark 1.5.x, but should be compatible 
back to at least 1.3.x. We use flambo to write all of our production Spark 
jobs at Yieldbot and consider it to be up very stable and performant. 

API codox documentation and literate source is available [1]. The source 
code is available on Github [2].

[1] http://yieldbot.github.io/flambo/
[2] http://github.com/yieldbot/flambo

Cheers

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


rand-nth on empty collections

2015-09-30 Thread Marc O'Morain
Hi all,

I was surprised by the fact that rand-nth thrown when called on an empty
collection - see http://dev.clojure.org/jira/browse/CLJ-925

This behaviour is strange, since passing nil to rand-nth returns nil,
whereas in my experience, other Clojure functions treat nil and empty
collections in the same way (compare with next/rest/first, etc).

http://dev.clojure.org/jira/browse/CLJ-925 was marked as Completed without
comment – is this the intended behaviour? If so, would you accept a patch
to update the docstring to make it clear that the function will throw an
exception when passed an empty collection?

Thanks,

Marc

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread Marc O'Morain
I think Mailbox app might have messed with the quoting in my last reply. I hope 
it makes sense. 




I'm not suggesting that the function be changed - Clojure's API compatibility 
between versions is amazing and a fine example of great engineering. 




Reading other people's input on this thread has made it clear to my what I find 
surprising - rand-nth does not behave like `first` when called on an empty 
collection, and in my mind asking for the first element of a sequence and 
asking for a random element of that sequence are similar operations. 




I do see the point of view that nth throws on out-of-bounds access, so rand-nth 
should too, but in that case I would expect rand-nth to throw too. 




I would like to see that subtlety mentioned in the doc string. 




Thanks Alex & all!

On Wed, Sep 30, 2015 at 3:14 PM, Alex Miller  wrote:

> rand-nth cannot return a random element if there are no elements to return, 
> so I do not find this surprising. Returning nil would be an invalid answer 
> in my opinion.
> The rand-nth doc string implies that rand-nth will inherit the semantics of 
> nth for the specified collection. nth will generally throw on an invalid 
> index (and all indexes are invalid for an empty collection).
> For nil, the docstring for nth does not mention nil explicitly, so I would 
> treat this as undefined behavior unless you consider it as a degenerate 
> sequence. 
> The code (in RT.nthFrom()) explicitly handles this case and effectively 
> treats nil as an infinite indexed source of nils, rather than as an empty 
> sequence. In my own opinion (but maybe not Rich's), it seems to make more 
> sense to take the sequence interpretation and say that on nil, nth should 
> throw instead.
> So that might be a valid ticket. I'm not sure what, if any, negative 
> consequences would arise out of existing uses of nth that rely on this 
> behavior though. Given the number of things built on nth, it may be 
> impossible to change this even if it made sense to.
> Alex
>  
> On Wednesday, September 30, 2015 at 6:38:49 AM UTC-5, Marc O'Morain wrote:
>>
>> Hi all,
>>
>> I was surprised by the fact that rand-nth thrown when called on an empty 
>> collection - see http://dev.clojure.org/jira/browse/CLJ-925 
>> 
>>
>> This behaviour is strange, since passing nil to rand-nth returns nil, 
>> whereas in my experience, other Clojure functions treat nil and empty 
>> collections in the same way (compare with next/rest/first, etc).
>>
>> http://dev.clojure.org/jira/browse/CLJ-925 was marked as Completed 
>> without comment – is this the intended behaviour? If so, would you accept a 
>> patch to update the docstring to make it clear that the function will throw 
>> an exception when passed an empty collection?
>>
>> Thanks,
>>
>> Marc
>>
> -- 
> 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 unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Clojure Javadoc API Documentation" needs to be rebuilt.

2015-09-30 Thread crocket
I wanted to refer to such interfaces as clojure.lang.ISeq in javadoc since 
clojure API doc doesn't have interfaces.
If I download clojure javadoc from maven, I can find clojure.lang.ISeq, but 
such javadoc is not directly accessible on web browsers.

On Wednesday, September 30, 2015 at 10:56:36 PM UTC+9, Alex Miller wrote:
>
> Correct. The javadoc is built and pushed as part of the build process so 
> should always be up to date with the latest release.
>
> On Tuesday, September 29, 2015 at 12:48:21 PM UTC-5, Gary Verhaegen wrote:
>>
>> This is the whole official API, as defined since Clojure 1.6 (prior to 
>> that, there was no official Java API). All other Java classes in the 
>> clojure codebase are considered internal implementation. Here is the 
>> relevant part of the 1.6 release notes: 
>>
>> https://github.com/clojure/clojure/blob/master/changes.md#21-java-api 
>>
>> On 29 September 2015 at 16:46, Andy Fingerhut  
>> wrote: 
>> > Others can confirm, but I think that is the entire API, callable from 
>> Java, 
>> > that is documented and supported by Clojure.  Everything is reachable 
>> from 
>> > there if you know which Clojure Vars you want to use. 
>> > 
>> > Andy 
>> > 
>> > On Tue, Sep 29, 2015 at 7:31 AM, crocket  wrote: 
>> >> 
>> >> http://clojure.github.io/clojure/javadoc/ contains only two classes. 
>> >> 
>> >> -- 
>> >> You received this message because you are subscribed to the Google 
>> >> Groups "Clojure" group. 
>> >> To post to this group, send email to clo...@googlegroups.com 
>> >> Note that posts from new members are moderated - please be patient 
>> with 
>> >> your first post. 
>> >> To unsubscribe from this group, send email to 
>> >> clojure+u...@googlegroups.com 
>> >> For more options, visit this group at 
>> >> http://groups.google.com/group/clojure?hl=en 
>> >> --- 
>> >> You received this message because you are subscribed to the Google 
>> Groups 
>> >> "Clojure" group. 
>> >> To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> >> email to clojure+u...@googlegroups.com. 
>> >> For more options, visit https://groups.google.com/d/optout. 
>> > 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> > Groups "Clojure" group. 
>> > To post to this group, send email to clo...@googlegroups.com 
>> > Note that posts from new members are moderated - please be patient with 
>> your 
>> > first post. 
>> > To unsubscribe from this group, send email to 
>> > clojure+u...@googlegroups.com 
>> > For more options, visit this group at 
>> > http://groups.google.com/group/clojure?hl=en 
>> > --- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "Clojure" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to clojure+u...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
For maximum flexibility I wanted to use a multimethod, defined like this: 


(defmulti intent
  (fn [& args]
(apply discern args)))

This is how discern is defined: 

(defn- discern
  
  ([this-users-conversation]
   {:pre [(map? this-users-conversation)]}
   (:intent this-users-conversation)) 

  ([this-users-conversation salesforce-object-name]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (string? name-of-attribute)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute 
name-of-intent]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (keyword? name-of-attribute)
  (string? name-of-intent)]}
   name-of-intent))

but then I call the multimethod like this:

(intent this-users-conversation "Opportunity" :Name 
"query-salesforce-for-attribute")

and I get: 

:class clojure.lang.ArityException,
:message "Wrong number of args (4) passed to: query/fn--65",

Should I give up on this idea, or is there a way to make this work? 





-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread Marc O'Morain
I also think it makes perfect sense for rand-nth to throw an error on an empty 
collection.  That's because the first step is it needs to generate a random 
number between 0 and the length of the collection (0), which is impossible.  So 
it should throw an error.  Note that it is the *random generation of the 
index*, not the nth that conceptually is throwing the error.







​

​Throwing an exception doesn't feel like idiomatic Clojure to me. In my 
experience Clojure throws on type errors, and returns nil to indicate failure 
or absence. 

​

​first and next don't throw when you ask for non-existing elements of a 
collection - they return nil to indicate absense. Similarly get and get-in 
return nil rather than throwing when the provided key is not associated with a 
value in an associative data structure. 




​That's why I found it odd that rand-nth throws.

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner

Oh, never mind, I'm a total idiot. At some point I confused myself by using 
the ":keys" directive. I was able to take Sean's example, apply 
destructuring, and get defmethods like this: 

(defmethod discern "this-users-objects" 
  [{:keys [salesforce-credentials]} salesforce-object-name]
  (:records
   (salesforce/with-version 34.0 
 (salesforce/soql (str "Select Id, Name From " salesforce-object-name) 
salesforce-credentials

(defmethod discern "new-opportunity"
  [{:keys [salesforce-credentials parsed-fields]}]
  (salesforce/with-version 34.0
(salesforce/so->create "Opportunity" (fcm/opportunity-map 
parsed-fields) salesforce-credentials)))

Which works perfectly.





On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:   on behalf of Lawrence 
> Krubner 
> Reply-To:   
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (keyword? name-of-attribute) 
> >  (string? name-of-intent)]} 
> >   name-of-intent)) 
> > 
> > 
> >but then I call the multimethod like this: 
> > 
> >(intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
> > 
> > 
> >and I get: 
> > 
> >:class clojure.lang.ArityException, 
> >:message "Wrong number of args (4) passed to: query/fn--65", 
> > 
> > 
> >Should I give up on this idea, or is there a way to make this work? 
> > 
> > 
>
>

-- 
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 unsubscribe from this group, send email to

Re: can I use varargs in a multimethod?

2015-09-30 Thread Gary Trakhman
It works for me, for '(intent {} "yes" :yes "WAT")'

I get the error: IllegalArgumentException No method in multimethod 'intent'
for dispatch value: WAT  clojure.lang.MultiFn.getFn (MultiFn.java:156)

You're probably being bitten by a different issue.  It's impossible to
redefine the dispatch function within the definition of the multimethod
after the first call to 'defmulti'.  In order to do so, you would have to
first ns-unmap that var.

An alternative for development is to use the dispatch function's Var as the
dispatch function:
(defn intent-dispatch [& args]
(apply discern args))
(defmulti intent #'intent-dispatch)


On Wed, Sep 30, 2015 at 8:33 PM Lawrence Krubner 
wrote:

> For maximum flexibility I wanted to use a multimethod, defined like this:
>
>
> (defmulti intent
>   (fn [& args]
> (apply discern args)))
>
> This is how discern is defined:
>
> (defn- discern
>
>   ([this-users-conversation]
>{:pre [(map? this-users-conversation)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (string? name-of-attribute)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute
> name-of-intent]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (keyword? name-of-attribute)
>   (string? name-of-intent)]}
>name-of-intent))
>
> but then I call the multimethod like this:
>
> (intent this-users-conversation "Opportunity" :Name
> "query-salesforce-for-attribute")
>
> and I get:
>
> :class clojure.lang.ArityException,
> :message "Wrong number of args (4) passed to: query/fn--65",
>
> Should I give up on this idea, or is there a way to make this work?
>
>
>
>
>
> --
> 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 unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner

> It's impossible to redefine the dispatch function within
>  the definition of the multimethod after the first call to 'defmulti'. 

That is a funny way to word it. I think you are saying that there is no way 
to have the multiple arities? 




On Wednesday, September 30, 2015 at 8:45:25 PM UTC-4, Gary Trakhman wrote:
>
> It works for me, for '(intent {} "yes" :yes "WAT")'
>
> I get the error: IllegalArgumentException No method in multimethod 
> 'intent' for dispatch value: WAT  clojure.lang.MultiFn.getFn 
> (MultiFn.java:156)
>
> You're probably being bitten by a different issue.  It's impossible to 
> redefine the dispatch function within the definition of the multimethod 
> after the first call to 'defmulti'.  In order to do so, you would have to 
> first ns-unmap that var.
>
> An alternative for development is to use the dispatch function's Var as 
> the dispatch function:
> (defn intent-dispatch [& args]
> (apply discern args))
> (defmulti intent #'intent-dispatch)
>
>
> On Wed, Sep 30, 2015 at 8:33 PM Lawrence Krubner  > wrote:
>
>> For maximum flexibility I wanted to use a multimethod, defined like this: 
>>
>>
>> (defmulti intent
>>   (fn [& args]
>> (apply discern args)))
>>
>> This is how discern is defined: 
>>
>> (defn- discern
>>   
>>   ([this-users-conversation]
>>{:pre [(map? this-users-conversation)]}
>>(:intent this-users-conversation)) 
>>
>>   ([this-users-conversation salesforce-object-name]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)]}
>>(:intent this-users-conversation))
>>
>>   ([this-users-conversation salesforce-object-name name-of-attribute]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)
>>   (string? name-of-attribute)]}
>>(:intent this-users-conversation))
>>
>>   ([this-users-conversation salesforce-object-name name-of-attribute 
>> name-of-intent]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)
>>   (keyword? name-of-attribute)
>>   (string? name-of-intent)]}
>>name-of-intent))
>>
>> but then I call the multimethod like this:
>>
>> (intent this-users-conversation "Opportunity" :Name 
>> "query-salesforce-for-attribute")
>>
>> and I get: 
>>
>> :class clojure.lang.ArityException,
>> :message "Wrong number of args (4) passed to: query/fn--65",
>>
>> Should I give up on this idea, or is there a way to make this work? 
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I use varargs in a multimethod?

2015-09-30 Thread Sean Corfield
Your example works for me as follows:

user> (defn- discern
  

  ([this-users-conversation]
   {:pre [(map? this-users-conversation)]}
   (:intent this-users-conversation)) 

  ([this-users-conversation salesforce-object-name]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (string? name-of-attribute)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute 
name-of-intent]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (keyword? name-of-attribute)
  (string? name-of-intent)]}
   name-of-intent))

#'user/discern

user> (defmulti intent

  (fn [& args]
(apply discern args)))

#'user/intent

user> (defmethod intent nil [& args] (str "I got nil plus " args))

#object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"]

user> (defmethod intent "query-salesforce-for-attribute" [& args] (str "SQFFA " 
args))

#object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"]

user> (defmethod intent :default [& args] (str "WAT? " args))

#object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"]

user> (def this-users-conversation {})

#'user/this-users-conversation

user> (intent this-users-conversation "Opportunity" :Name 
"query-salesforce-for-attribute")

"SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")"

user> (intent this-users-conversation "Opportunity" "Name")

"I got nil plus ({} \"Opportunity\" \"Name\")"

user> (intent {:intent "do-something"} "Opportunity" "Name")

"WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")"




Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood






From:   on behalf of Lawrence Krubner
Reply-To:  
Date:  Wednesday, September 30, 2015 at 5:33 PM
To:  Clojure
Subject:  can I use varargs in a multimethod?


>For maximum flexibility I wanted to use a multimethod, defined like this: 
>
>
>(defmulti intent
>  (fn [& args]
>(apply discern args)))
>
>
>This is how discern is defined: 
>
>(defn- discern
>  
>  ([this-users-conversation]
>   {:pre [(map? this-users-conversation)]}
>   (:intent this-users-conversation)) 
>
>  ([this-users-conversation salesforce-object-name]
>   {:pre [(map? this-users-conversation)
>  (string? salesforce-object-name)]}
>   (:intent this-users-conversation))
>
>  ([this-users-conversation salesforce-object-name name-of-attribute]
>   {:pre [(map? this-users-conversation)
>  (string? salesforce-object-name)
>  (string? name-of-attribute)]}
>   (:intent this-users-conversation))
>
>  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent]
>   {:pre [(map? this-users-conversation)
>  (string? salesforce-object-name)
>  (keyword? name-of-attribute)
>  (string? name-of-intent)]}
>   name-of-intent))
>
>
>but then I call the multimethod like this:
>
>(intent this-users-conversation "Opportunity" :Name 
>"query-salesforce-for-attribute")
>
>
>and I get: 
>
>:class clojure.lang.ArityException,
>:message "Wrong number of args (4) passed to: query/fn--65",
>
>
>Should I give up on this idea, or is there a way to make this work? 
>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: No recent activity for core.async?

2015-09-30 Thread Rangel Spasov
We've been using the library very actively from both Clojure and 
ClojureScript and have no problems with it - no reasons to worry about the 
alpha label I think :).


On Saturday, September 26, 2015 at 2:49:22 AM UTC-7, Rafik NACCACHE wrote:
>
> core.async didn't move since more than a year.
>
> Is any new release coming soon? I actually use this library intensively, 
> and the fact it is staying alpha for more than a year starts giving me some 
> shivers :)
>
> Thank you for any updates !!
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
In a let statement I can do this: 

(let [[this-users-conversation salesforce-object-name name-of-attribute] 
args]

I would like to do this destructuring in my defmethods, but if I do this: 

(defmethod discern "find-user-credentials"
  [[this-users-conversation salesforce-object-name name-of-attribute]]

or:

(defmethod discern "find-user-credentials"
  [this-users-conversation salesforce-object-name name-of-attribute]

I get: 

:class clojure.lang.ArityException,
 :message "Wrong number of args (2) passed to: intent/fn--64",

Is there any way to do the destructuring as part of the definition of 
defmethod, or do I have to do it in a let statement? 






On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:   on behalf of Lawrence 
> Krubner 
> Reply-To:   
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (keyword? name-of-attribute) 
> >  (string? name-of-intent)]} 
> >   name-of-intent)) 
> > 
> > 
> >but then I call the multimethod like this: 
> > 
> >(intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
> > 
> > 
> >and I get: 
> > 
> >:class clojure.lang.ArityException, 
> >:message "Wrong number of args (4) passed to: query/fn--65", 
> > 
> > 
> >Should I give up on this idea, or is there a way to make this work? 
> > 
> > 
>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com

Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
Sean,

Thank you. That saves me hours of mistakes. 



On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:   on behalf of Lawrence 
> Krubner 
> Reply-To:   
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (keyword? name-of-attribute) 
> >  (string? name-of-intent)]} 
> >   name-of-intent)) 
> > 
> > 
> >but then I call the multimethod like this: 
> > 
> >(intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
> > 
> > 
> >and I get: 
> > 
> >:class clojure.lang.ArityException, 
> >:message "Wrong number of args (4) passed to: query/fn--65", 
> > 
> > 
> >Should I give up on this idea, or is there a way to make this work? 
> > 
> > 
>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
I guess I could get rid of the multimethod and instead do something like 
this: 

   ((symbol (:intent this-users-conversation)))

but that seems like a hack.


On Wednesday, September 30, 2015 at 8:33:36 PM UTC-4, Lawrence Krubner 
wrote:
>
> For maximum flexibility I wanted to use a multimethod, defined like this: 
>
>
> (defmulti intent
>   (fn [& args]
> (apply discern args)))
>
> This is how discern is defined: 
>
> (defn- discern
>   
>   ([this-users-conversation]
>{:pre [(map? this-users-conversation)]}
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (string? name-of-attribute)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (keyword? name-of-attribute)
>   (string? name-of-intent)]}
>name-of-intent))
>
> but then I call the multimethod like this:
>
> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute")
>
> and I get: 
>
> :class clojure.lang.ArityException,
> :message "Wrong number of args (4) passed to: query/fn--65",
>
> Should I give up on this idea, or is there a way to make this work? 
>
>
>
>
>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread Mikera
Personally I think nth is broken and should throw an exception when passed 
nil (which should be interpreted as an empty sequence)

=> (nth nil 10)
nil
=> (nth '() 10)
IndexOutOfBoundsException   clojure.lang.RT.nthFrom (RT.java:885)
=> (nth [] 10)
IndexOutOfBoundsException   clojure.lang.PersistentVector.arrayFor 
(PersistentVector.java:157)

We want to throw exceptions with invalid arguments surely? Otherwise errors 
just propagate and it gets harder to trace root causes of bugs.

Following this logic, rand-nth should throw an exception in all these cases 
too.


On Thursday, 1 October 2015 06:11:36 UTC+8, Marc O'Morain wrote:
>
> I think Mailbox app might have messed with the quoting in my last reply. I 
> hope it makes sense. 
>
> I'm not suggesting that the function be changed - Clojure's API 
> compatibility between versions is amazing and a fine example of great 
> engineering. 
>
> Reading other people's input on this thread has made it clear to my what I 
> find surprising - rand-nth does not behave like `first` when called on an 
> empty collection, and in my mind asking for the first element of a sequence 
> and asking for a random element of that sequence are similar operations. 
>
> I do see the point of view that nth throws on out-of-bounds access, so 
> rand-nth should too, but in that case I would expect rand-nth to throw too. 
>
> I would like to see that subtlety mentioned in the doc string. 
>
> Thanks Alex & all!
>
>
>
> On Wed, Sep 30, 2015 at 3:14 PM, Alex Miller  > wrote:
>
>> rand-nth cannot return a random element if there are no elements to 
>> return, so I do not find this surprising. Returning nil would be an invalid 
>> answer in my opinion.
>>
>> The rand-nth doc string implies that rand-nth will inherit the semantics 
>> of nth for the specified collection. nth will generally throw on an invalid 
>> index (and all indexes are invalid for an empty collection).
>>
>> For nil, the docstring for nth does not mention nil explicitly, so I 
>> would treat this as undefined behavior unless you consider it as a 
>> degenerate sequence. 
>>
>> The code (in RT.nthFrom()) explicitly handles this case and effectively 
>> treats nil as an infinite indexed source of nils, rather than as an empty 
>> sequence. In my own opinion (but maybe not Rich's), it seems to make more 
>> sense to take the sequence interpretation and say that on nil, nth should 
>> throw instead.
>>
>> So that might be a valid ticket. I'm not sure what, if any, negative 
>> consequences would arise out of existing uses of nth that rely on this 
>> behavior though. Given the number of things built on nth, it may be 
>> impossible to change this even if it made sense to.
>>
>> Alex
>>  
>> On Wednesday, September 30, 2015 at 6:38:49 AM UTC-5, Marc O'Morain wrote:
>>>
>>> Hi all,
>>>
>>> I was surprised by the fact that rand-nth thrown when called on an empty 
>>> collection - see http://dev.clojure.org/jira/browse/CLJ-925 
>>> 
>>>
>>> This behaviour is strange, since passing nil to rand-nth returns nil, 
>>> whereas in my experience, other Clojure functions treat nil and empty 
>>> collections in the same way (compare with next/rest/first, etc).
>>>
>>> http://dev.clojure.org/jira/browse/CLJ-925 was marked as Completed 
>>> without comment – is this the intended behaviour? If so, would you accept a 
>>> patch to update the docstring to make it clear that the function will throw 
>>> an exception when passed an empty collection?
>>>
>>> Thanks,
>>>
>>> Marc
>>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: rand-nth on empty collections

2015-09-30 Thread Alex Miller
Just for kicks, I built with nth throwing an exception on nil instead of 
returning nil and all tests passed, so that's at least promising that 
changing nth on nil would be possible.

On Wednesday, September 30, 2015 at 9:14:22 AM UTC-5, Alex Miller wrote:
>
> rand-nth cannot return a random element if there are no elements to 
> return, so I do not find this surprising. Returning nil would be an invalid 
> answer in my opinion.
>
> The rand-nth doc string implies that rand-nth will inherit the semantics 
> of nth for the specified collection. nth will generally throw on an invalid 
> index (and all indexes are invalid for an empty collection).
>
> For nil, the docstring for nth does not mention nil explicitly, so I would 
> treat this as undefined behavior unless you consider it as a degenerate 
> sequence. 
>
> The code (in RT.nthFrom()) explicitly handles this case and effectively 
> treats nil as an infinite indexed source of nils, rather than as an empty 
> sequence. In my own opinion (but maybe not Rich's), it seems to make more 
> sense to take the sequence interpretation and say that on nil, nth should 
> throw instead.
>
> So that might be a valid ticket. I'm not sure what, if any, negative 
> consequences would arise out of existing uses of nth that rely on this 
> behavior though. Given the number of things built on nth, it may be 
> impossible to change this even if it made sense to.
>
> Alex
>
>>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Clojure Javadoc API Documentation" needs to be rebuilt.

2015-09-30 Thread Alex Miller
Correct. The javadoc is built and pushed as part of the build process so 
should always be up to date with the latest release.

On Tuesday, September 29, 2015 at 12:48:21 PM UTC-5, Gary Verhaegen wrote:
>
> This is the whole official API, as defined since Clojure 1.6 (prior to 
> that, there was no official Java API). All other Java classes in the 
> clojure codebase are considered internal implementation. Here is the 
> relevant part of the 1.6 release notes: 
>
> https://github.com/clojure/clojure/blob/master/changes.md#21-java-api 
>
> On 29 September 2015 at 16:46, Andy Fingerhut  > wrote: 
> > Others can confirm, but I think that is the entire API, callable from 
> Java, 
> > that is documented and supported by Clojure.  Everything is reachable 
> from 
> > there if you know which Clojure Vars you want to use. 
> > 
> > Andy 
> > 
> > On Tue, Sep 29, 2015 at 7:31 AM, crocket  > wrote: 
> >> 
> >> http://clojure.github.io/clojure/javadoc/ contains only two classes. 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> >> Groups "Clojure" group. 
> >> To post to this group, send email to clo...@googlegroups.com 
>  
> >> Note that posts from new members are moderated - please be patient with 
> >> your first post. 
> >> To unsubscribe from this group, send email to 
> >> clojure+u...@googlegroups.com  
> >> For more options, visit this group at 
> >> http://groups.google.com/group/clojure?hl=en 
> >> --- 
> >> You received this message because you are subscribed to the Google 
> Groups 
> >> "Clojure" group. 
> >> To unsubscribe from this group and stop receiving emails from it, send 
> an 
> >> email to clojure+u...@googlegroups.com . 
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@googlegroups.com 
>  
> > Note that posts from new members are moderated - please be patient with 
> your 
> > first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com  
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Clojure" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to clojure+u...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: rand-nth on empty collections

2015-09-30 Thread Alex Miller
rand-nth cannot return a random element if there are no elements to return, 
so I do not find this surprising. Returning nil would be an invalid answer 
in my opinion.

The rand-nth doc string implies that rand-nth will inherit the semantics of 
nth for the specified collection. nth will generally throw on an invalid 
index (and all indexes are invalid for an empty collection).

For nil, the docstring for nth does not mention nil explicitly, so I would 
treat this as undefined behavior unless you consider it as a degenerate 
sequence. 

The code (in RT.nthFrom()) explicitly handles this case and effectively 
treats nil as an infinite indexed source of nils, rather than as an empty 
sequence. In my own opinion (but maybe not Rich's), it seems to make more 
sense to take the sequence interpretation and say that on nil, nth should 
throw instead.

So that might be a valid ticket. I'm not sure what, if any, negative 
consequences would arise out of existing uses of nth that rely on this 
behavior though. Given the number of things built on nth, it may be 
impossible to change this even if it made sense to.

Alex
 
On Wednesday, September 30, 2015 at 6:38:49 AM UTC-5, Marc O'Morain wrote:
>
> Hi all,
>
> I was surprised by the fact that rand-nth thrown when called on an empty 
> collection - see http://dev.clojure.org/jira/browse/CLJ-925 
> 
>
> This behaviour is strange, since passing nil to rand-nth returns nil, 
> whereas in my experience, other Clojure functions treat nil and empty 
> collections in the same way (compare with next/rest/first, etc).
>
> http://dev.clojure.org/jira/browse/CLJ-925 was marked as Completed 
> without comment – is this the intended behaviour? If so, would you accept a 
> patch to update the docstring to make it clear that the function will throw 
> an exception when passed an empty collection?
>
> Thanks,
>
> Marc
>

-- 
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 unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.