Re: clojure.spec - Using :pre conditions (or not)?

2016-09-16 Thread joakim . tengstrand
I agree with you that an IllegalArgumentException is preferable 
to AssertionError.
The reason that I used AssertionError was that I wanted to keep the same 
behaviour as when using s/valid? (it throws an AssertionError).
Maybe only s/assert should throw AssertionError and s/valid? should throw 
something else?

/Joakim

On Friday, September 16, 2016 at 7:52:55 AM UTC+2, Mamun wrote:
>
>
> When function is throwing exception because of argument. I would prefer to 
> throw IllegalArgumentException not AssertionError. 
>
>
> (defn check [type data]
>   (if (sp/valid? type data)
> true
> (throw (IllegalArgumentException. (sp/explain type data)
>
>
> Br,
> Mamun
>
>
> On Friday, September 16, 2016 at 7:20:53 AM UTC+2, joakim.t...@nova.com 
> wrote:
>>
>> I came up with this solution:
>>
>> (ns spec-test.core
>>   (:require [clojure.spec :as s]))
>>
>> (s/def :user/name string?)
>> (s/def :common/user (s/keys :req [:user/name]))
>>
>> ;; with this little helper function...
>> (defn check [type data]
>>   (if (s/valid? type data)
>> true
>> (throw (AssertionError. (s/explain type data)
>>
>> ;; I can use it in my :pre condition
>> (defn aname [user]
>>   {:pre [(check :common/user user)]}
>>   (-> user :user/name))
>>
>> ;; when I call name with an illegal arguement...
>> (aname {:x "Elon"})
>>
>> ;; ...it not fails and returns a better error message:
>> CompilerException java.lang.AssertionError: null, 
>> compiling:(/Users/joakimtengstrand/IdeaProjects/spec-test/src/spec_test/core.clj:19:1)
>> val: {:x "Elon"} fails spec: :common/user predicate: (contains? % :user/name)
>>
>>
>> With this solution I don't need to enable assertions, and the code is 
>> neat and less verbose!
>>
>> /Joakim
>>
>> On Thursday, September 15, 2016 at 3:11:32 PM UTC+2, Shantanu Kumar wrote:
>>>
>>> Hi Joakim,
>>>
>>> You might be interested in Paul Stadig's library 
>>> https://github.com/pjstadig/assertions that leverages Java's `-ea` 
>>> (enable-assertions, which you may want to keep enabled in dev) command-line 
>>> flag. If you have a bunch of things together to assert, you may want to use 
>>> the `when-assert` macro for wholesale optimization: 
>>> https://github.com/pjstadig/assertions/blob/0.2.0/src/pjstadig/assertions.clj#L13
>>>
>>>
>>> Shantanu
>>>
>>> On Thursday, 15 September 2016 16:50:17 UTC+5:30, joakim.t...@nova.com 
>>> wrote:

 Ok, thanks!

 In the Java world, the assertions is also something that need to be 
 turn on explicitly.
 In that sence, they are kind of not mandatory to be executed (or at 
 least signals that to the reader of the code).

 I would be happier if you guys could add another method, that I can use 
 in my :pre conditions, that leverage
 the same amount of details in the error messages, but that is always 
 "turned on".

 In the meanwhile, I will use s/assert ;-)

 BR,
 Joakim Tengstrand


 On Wednesday, 14 September 2016 15:59:09 UTC+2, Alex Miller wrote:
>
> Another option that has been added since the guide was written is 
> s/assert which seems closer to what you're suggesting.
>
> (defn name [user]
>   {:pre [(s/assert :common/user user)]}
>   (-> user :user/name))
>
> ;; need to enable assertion checking - this can also be enabled 
> globally with system property clojure.spec.check-asserts
> (s/check-asserts true)
>
> (name {:user/name "Elon"})
> "Elon"
>
> (name {:x "Elon"})
> ExceptionInfo Spec assertion failed
> val: {:x "Elon"} fails predicate: (contains? % :user/name)
> :clojure.spec/failure  :assertion-failed
>   clojure.core/ex-info (core.clj:4725)
>
> Rather than use it in a precondition, you can also use s/assert 
> directly in the code.
>
> On Wednesday, September 14, 2016 at 7:37:24 AM UTC-5, 
> joakim.t...@nova.com wrote:
>>
>> (ns spec-test.core
>>   (:require [clojure.spec :as s]))
>>
>> (s/def :user/name string?)
>> (s/def :common/user (s/keys :req [:user/name]))
>>
>> ; first version of name (using :pre)
>> (defn name [user]
>>   {:pre [(s/valid? :common/user user)]}
>>   (-> user :user/name))
>>
>> ; This statement works ok and returns "Elon":
>> (name {:user/name "Elon"})
>>
>> ; but this statement...
>> (name {:x "Elon"})
>>
>> ;...will throw:
>> CompilerException java.lang.AssertionError:
>> Assert failed: (s/valid? :common/user user)
>>
>> ; ...but then I don't get as much information
>> ; about the error as if I would have called:
>> (s/explain :common/user {:x "Elon"})
>>
>> ;...which also contains the predicate:
>> val: {:x "Elon"} fails spec: :common/user
>> predicate: (contains? % :user/name)
>>
>> ; (second version of name - more verbose)
>> ; or do I need to wite it like this:
>> (defn name [user]
>>   (let [parsed (s/confo

Re: Clojure support for Visual Studio Code

2016-09-16 Thread Andrey Lisin
Hi Ikuru,

I've just checked and dragging and dropping works for me on Ubuntu 16.04, 
could you try it again? Another option is to open the extension file with 
"File -> Open" menu.

Not sure I understand your question correctly, but to make the extension 
work you need to add cider-nrepl to a list of dependencies. The simplest 
way to archive it to write the code below into you ~/.lein.profiles.clj

Введите код..{:user {:plugins [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}.

-- 
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 support for Visual Studio Code

2016-09-16 Thread Andrey Lisin
Sorry for the mess in the previous message. This code should be put into 
~/.lein/profiles.clj

{:user {:plugins  [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
   :dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}



пятница, 16 сентября 2016 г., 17:32:54 UTC+6 пользователь Andrey Lisin 
написал:
>
> Hi Ikuru,
>
> I've just checked and dragging and dropping works for me on Ubuntu 16.04, 
> could you try it again? Another option is to open the extension file with 
> "File -> Open" menu.
>
> Not sure I understand your question correctly, but to make the extension 
> work you need to add cider-nrepl to a list of dependencies. The simplest 
> way to archive it to write the code below into you ~/.lein.profiles.clj
>
> Введите код..{:user {:plugins [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
> :dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}.
>

-- 
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.


clojure.spec - suggestion on how to simplify :pre and :post conditions by using specs.

2016-09-16 Thread joakim . tengstrand


(ns spec-test.core
  (:require [clojure.spec :as s]))

(s/def :user/name string?)
(s/def :core/user (s/keys :req [:user/name]))

; A helper method to get better error messages.
; Also imagine that clojure.spec has a similar s/check
; function that looks similar to this one
; (used in our user-name function):
(defn check [type data]
  (if (s/valid? type data)
true
(throw (AssertionError. (s/explain type data)


; ...how about if we could write our :pre and :post conditions like this:
(defn user-name [user :core/user]
  (-> user :user/name)) :user/name

; ...so that they expands into this:
(defn user-name [user]
  {:pre [(s/check :core/user user)]}
  {:post [(s/check :user/name user)]}
  (-> user :user/name))



; And if you have other :pre or :post conditions,
; then extend the existing ones:
(defn user-name [user :core/user number]
  {:pre [pos? number]}
  (-> user :user/name))

; ...becomes:
(defn user-name [user number]
  {:pre [pos? number
 (s/valid? :core/user user)]}
  (-> user :user/name))

; a call to the function
(user-name {:user/name "Bill"} 3)


; Maybe it will be hard to find a nice syntax that works for the post condition,
; but the :pre condition should be doable I think!

-- 
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.spec - suggestion on how to simplify :pre and :post conditions by using specs.

2016-09-16 Thread joakim . tengstrand
I think a natural place of the :post condition shold be after the argument 
brackets (and that should be possible to implement I think):

(defn user-name [user :core/user] :user/name
  (-> user :user/name))


On Friday, September 16, 2016 at 1:34:47 PM UTC+2, joakim.t...@nova.com 
wrote:
>
> (ns spec-test.core
>   (:require [clojure.spec :as s]))
>
> (s/def :user/name string?)
> (s/def :core/user (s/keys :req [:user/name]))
>
> ; A helper method to get better error messages.
> ; Also imagine that clojure.spec has a similar s/check
> ; function that looks similar to this one
> ; (used in our user-name function):
> (defn check [type data]
>   (if (s/valid? type data)
> true
> (throw (AssertionError. (s/explain type data)
>
>
> ; ...how about if we could write our :pre and :post conditions like this:
> (defn user-name [user :core/user]
>   (-> user :user/name)) :user/name
>
> ; ...so that they expands into this:
> (defn user-name [user]
>   {:pre [(s/check :core/user user)]}
>   {:post [(s/check :user/name user)]}
>   (-> user :user/name))
>
>
>
> ; And if you have other :pre or :post conditions,
> ; then extend the existing ones:
> (defn user-name [user :core/user number]
>   {:pre [pos? number]}
>   (-> user :user/name))
>
> ; ...becomes:
> (defn user-name [user number]
>   {:pre [pos? number
>  (s/valid? :core/user user)]}
>   (-> user :user/name))
>
> ; a call to the function
> (user-name {:user/name "Bill"} 3)
>
>
> ; Maybe it will be hard to find a nice syntax that works for the post 
> condition,
> ; but the :pre condition should be doable I think!
>
>

-- 
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: [CfP] :clojureD 2017

2016-09-16 Thread Stefan Kamphausen
Hi,

On Friday, September 16, 2016 at 6:16:14 AM UTC+2, Mars0i wrote:
>
> Glad that this is happening.
> You might want to add the date to the CFP and Schedule pages.  I only 
> found it on the Press page.
>
 
Thanks for your feedback.  I've added the date to the CfP page.  Did you 
look for it on the front page, btw? ;-)

Cheers,
stefan

-- 
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: [CfP] :clojureD 2017

2016-09-16 Thread Mars0i


On Friday, September 16, 2016 at 8:14:49 AM UTC-5, Stefan Kamphausen wrote:
>
> Hi,
>
> On Friday, September 16, 2016 at 6:16:14 AM UTC+2, Mars0i wrote:
>>
>> Glad that this is happening.
>> You might want to add the date to the CFP and Schedule pages.  I only 
>> found it on the Press page.
>>
>  
> Thanks for your feedback.  I've added the date to the CfP page.  Did you 
> look for it on the front page, btw? ;-)
>

I looked across the top of the page for anything that seemed like a link to 
a page that might have the dates.  Since you mention the home page, I tried 
clicking on the graphic at the upper left, and found it, but that just 
looked like a graphic.  I never occurred to me that it was a link.  

-- 
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.


Formatting output of pretty print using cljfmt

2016-09-16 Thread Amogh Talpallikar
I have CIDER installed with cljfmt support.

I have a bunch of auto-generated clojure files with formatting done via 
pretty-print with badly formatted let statements. 

(let
[a
  1
  b
  2
  c
  3
  d
  4]
  (println a b c d))

Is it possible for cljfmt to format it like

(let [a 1
 b 2
 c 3
 d 4]
  (println a b c d))
 

-- 
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: Formatting output of pretty print using cljfmt

2016-09-16 Thread James Reeves
cljfmt doesn't currently have opinions on whether things are on one line or
spread out over several lines. From cljfmt's perspective:

[a
 b
 c]

Is as valid as

[a b c]

- James

On 16 September 2016 at 14:34, Amogh Talpallikar <
amogh.talpalli...@gmail.com> wrote:

> I have CIDER installed with cljfmt support.
>
> I have a bunch of auto-generated clojure files with formatting done via
> pretty-print with badly formatted let statements.
>
> (let
> [a
>   1
>   b
>   2
>   c
>   3
>   d
>   4]
>   (println a b c d))
>
> Is it possible for cljfmt to format it like
>
> (let [a 1
>  b 2
>  c 3
>  d 4]
>   (println a b c d))
>
>
> --
> 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 support for Visual Studio Code

2016-09-16 Thread Michael Ball
Ok was just able to try it out briefly on OSX.

- Installation went smoothly, no problems.

- Explicit docs/instructions on how to start and connect to the repl would 
be good. I was able to get it connected but it was unclear if the repl 
should be started from within VS code, or from a terminal then only connect 
to it from VS code.

- The commands in the command pallet could be prefixed with a "clj: " or 
perhaps "clojure: " or something like that. Other plugins I've used(e.g. 
elm) do this so it's easy  to know which commands are associated with the 
extension and which are part of the editor.

- code completion is working just fine.

- Docstrings don't seem to work for thread first  (-> xxx)? I also noticed 
that it took some time after initial repl connect for the docstrings to 
become available, probably some indexing delay because my laptop is 
old+slow, initially they showed "Docstring not found". Also the docstring 
not found message pops up for all characters on hover of mouse over things 
such as parenthesis.

- I found a command to eval the entire file which worked good. Is there a 
way to send selected expressions to a repl yet?

- If I had one feature request it would be for inline results a-la 
LightTable. Any plans for something like that?


Overall this is a great start, thank you very much for getting the ball 
rolling and building this extension!




On Thursday, September 15, 2016 at 10:03:40 AM UTC-7, Michael Ball wrote:
>
> This looks great, will definitely try it out this weekend!
>
>
> On Thursday, September 15, 2016 at 4:17:38 AM UTC-7, Andrey Lisin wrote:
>>
>> Hey guys,
>>
>> I've been working on Clojure support for Visual Studio Code text editor 
>> for a while. The first version is very close to the point when it can be 
>> published to Visual Studio Code marketplace, but I would like to test it a 
>> bit more before. Maybe there are Visual Studio Code uses here who can try 
>> the extension and give feedback.
>>
>> Features extension supports:
>>
>> - code completion
>> - interaction with REPL
>> - go to definition
>> - documentation hints
>>
>> The extension can be obtained from its GitHub page (
>> https://github.com/avli/clojureVSCode/releases). Download the vsix file 
>> and drag-and-drop it to the Visual Studio Code. The extension relies on 
>> cider-nrepl, so don't forget to add it to the dependencies list. To connect 
>> to nREPL use "Connect to nREPL" command from the command palette. More 
>> information is available on the extension's GitHub page.
>>
>> Hope it be useful for someone.
>>
>>

-- 
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.