Re: The soul of case

2017-06-24 Thread Alex Miller
Clojure's behavior is the intended behavior in Clojure.

I'll leave the choice of what to do in ClojureScript up to David.

Btw, I believe there actually is a case* in Clojure already which is part of 
the implementation details.

-- 
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: How to call Clojure from Java?

2017-06-24 Thread thelmuth
Thanks for the suggestions! Daniel's code helped me a lot, thanks!

One thing that had me stuck for a while is that you have to have a Clojure 
jar in your classpath. I also worked through a different way, using an 
uberjar of a Clojure project. I posted my guides here 

 
for anyone else trying to do this.

On Thursday, June 1, 2017 at 10:11:25 PM UTC-4, Daniel Compton wrote:
>
> Hi thelmuth
>
> Here's a fully worked example. It calls the Clojure function 
> myco.dashed-namespace.app.core/start!. Save it to 
> src/myco/dashed_namespace/app/Main.java.
>
> package myco.dashed_namespace.app;
>
> import clojure.java.api.Clojure;
> import clojure.lang.IFn;
>
> public class Main {
> public static void main(String[] args) {
> try {
> IFn require = Clojure.var("clojure.core", "require");
> require.invoke(Clojure.read("myco.dashed-namespace.app.core"));
>
> Clojure.var("myco.dashed-namespace.app.core", "start!").invoke();
> }
> catch (Throwable e) {
> System.out.println(e.getMessage());
> }
> }
> }
>
>
> On Fri, Jun 2, 2017 at 1:24 PM James Reeves  > wrote:
>
>> There's a brief section on this on the Clojure website:
>>
>> https://clojure.org/reference/java_interop#_calling_clojure_from_java
>>
>> On 2 June 2017 at 01:35, thelmuth  wrote:
>>
>>> What is the best way to call a Clojure function from Java?
>>>
>>> Most of the resources I have found are either very old or don't go into 
>>> enough detail. I am a Clojure programmer with very little Java background, 
>>> and have been having trouble with the methods I've found, especially 
>>> classpath issues.
>>>
>>> -- 
>>> 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.
>>>
>>
>>
>>
>> -- 
>> James Reeves
>> booleanknot.com
>>
>> -- 
>> 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: The soul of case

2017-06-24 Thread Matching Socks
Amusingly, ClojureScript's "case" works more like the way I always expect 
"case" to work.  A "case" in Clojure that did what I meant with Java 
public-static-final constants would be lovely, lovely.  ClojureScript's 
"case" is tasty candy!  

And now with cljc, those tasty "case" forms are going to migrate to Clojure 
and they are very quietly going to do something completely different.  That 
would be a bad thing and its taxonomic order would be "incidental 
complexity".

Maybe ClojureScript's super-charged "case" could move over to "case*"?

At any rate, I would like to put in either a documentation issue (if it's a 
feature that ClojureScript's "case" does not work like Clojure's) or else a 
defect issue (if it's a bug).  

In a way, this is a question of "easy" vs "simple".  Easy, to let 
ClojureScript accidentally differ (hey, it's better) and just document it. 
 Simple, to have one harmonious core language.

So I am inclined to put it in as a defect, even though I prefer 
ClojureScript's "case". 

-- 
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: Numbers/math in Clojure

2017-06-24 Thread Alex Miller


On Saturday, June 24, 2017 at 3:36:21 AM UTC-5, henrik42 wrote:
>
> Hi,
>
> I'm doing a little write-up on Java basics and comparing some of them
> to Clojure (things like mutable shared state, side effects and so
> on). When I came to "numbers" I was surprised by some of the things I
> found in Clojure.
>
> (== (double 0.5) (float 0.5)) ;; -> true
> (== (double 0.2) (float 0.2)) ;; -> false
>

Due to how single and double precision floats are stored, you'll get these 
same results in Java too. These will store differently imprecise 
representations of the number (remember base 2, not 10).

user=> (Integer/toBinaryString (int (Float/floatToRawIntBits (float 0.2
"10010011001100110011001101"
user=> (Long/toBinaryString (Double/doubleToRawLongBits 0.2))
"001001100110011001100110011001100110011001100110011010"

More:
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
 

> The docs (
> https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/==)
> say, that `==` compares the numbers type-independently. But why are
> the two __representations__ (types?) of the numerical value `0.2`
> different then?
>
> I understand that `(float 0.2)` gets _converted_ to `double` and this
> conversion is done like this (just the way Java does it -- should be
> `f2d` in byte code).
>
> (double (float 0.2)) ;; -> 0.2000298023224
> 
> So that's not equal to `(double 0.2)`. But why not convert `float` to
> `double` like this:
>
> (defn to-double [f]
> (Double. (str f)))
>
> Here we're not converting the (inexact) `float` approximation of `0.2`
> to `double` but we use what human readers perceive as the (exact)
> _numerical value_.
>

The reason for this is that Clojure doesn't support floats - we only read 
fixed precision floating point as doubles, period. How would the reader 
know whether to read single or double precision? It would have to make a 
decision on whether to make a float or a double, which is inherently 
sketchy. The use cases for single precision floats even in Java are almost 
entirely gone at this point. The only time you'd want to use them is if you 
want floating point math with the smallest possible memory (and are willing 
to give up the corresponding reduction in precision). 
 

> This would parallel the way `BigDecimal` literals work in Clojure:
>
> 0.3M ;; -> 0.3M
> (BigDecimal. 0.3) ;; -> 
> 0.299988897769753748434595763683319091796875M
> (BigDecimal. (str 0.3)) ;; -> 0.3M
>

BigInteger and BigDecimal support a string constructor because they are 
arbitrary precision - that's the only way you can represent arbitrarily 
large numbers. If you want arbitrary precision, use those, otherwise they 
are not applicable to the case of floats/doubles. Note that the Clojure 
reader can use the suffix (N or M) in Clojure to determine when to activate 
arbitrary precision reading in this case.
 

>
> When we use numbers in sets and maps, more questions come up:
>
> (into #{} [0.5 (float 0.5)]) ;; -> #{0.5}
> (into #{} [0.2 (float 0.2)]) ;; -> #{0.2 0.2}
>
>
This is under discussion in a ticket at 
http://dev.clojure.org/jira/browse/CLJ-1649. It is definitely a bug with 
float/double hash consistency. My personal vote in this case is that floats 
and doubles should just never compare equals, period. Due to the example up 
top, you're almost never going to get predictable results and you should 
just not use floats. Or at least not use a mix of floats and doubles.
 

> First it seems that `==` is used to check for equality, but I think
> it's not the case.
>
> (= 0.5 (float 0.5)) ;; -> true
>
> Ahh -- seems that `(float 0.5)` gets converted to `double` before
> comparing via `=`.
>
> Getting `#{0.2 0.2}` is bad: we won't be able to read this set literal
> back in.
>
> #{0.2 0.2} ;; -> java.lang.IllegalArgumentException: Duplicate key: 0.2
>
> So my question is: does anyone know about tutorials, docs etc. on
> clojure.org or elsewhere where I can find advices/best practice/a
> "clojure specifications" (like the JLS does it for Java) on this
> topic.
>

Andy Fingerhut has a comprehensive page on equality at 
https://github.com/jafingerhut/thalia/blob/master/doc/other-topics/equality.md. 
I have an extensive rewrite of this destined to be a guide on the Clojure 
site, but it's still a work in progress at this point.
 

>
> Henrik
>

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

Numbers/math in Clojure

2017-06-24 Thread henrik42
Hi,

I'm doing a little write-up on Java basics and comparing some of them
to Clojure (things like mutable shared state, side effects and so
on). When I came to "numbers" I was surprised by some of the things I
found in Clojure.

(== (double 0.5) (float 0.5)) ;; -> true
(== (double 0.2) (float 0.2)) ;; -> false

The docs 
(https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/==)
say, that `==` compares the numbers type-independently. But why are
the two __representations__ (types?) of the numerical value `0.2`
different then?

I understand that `(float 0.2)` gets _converted_ to `double` and this
conversion is done like this (just the way Java does it -- should be
`f2d` in byte code).

(double (float 0.2)) ;; -> 0.2000298023224

So that's not equal to `(double 0.2)`. But why not convert `float` to
`double` like this:

(defn to-double [f]
(Double. (str f)))

Here we're not converting the (inexact) `float` approximation of `0.2`
to `double` but we use what human readers perceive as the (exact)
_numerical value_.

This would parallel the way `BigDecimal` literals work in Clojure:

0.3M ;; -> 0.3M
(BigDecimal. 0.3) ;; -> 
0.299988897769753748434595763683319091796875M
(BigDecimal. (str 0.3)) ;; -> 0.3M

When we use numbers in sets and maps, more questions come up:

(into #{} [0.5 (float 0.5)]) ;; -> #{0.5}
(into #{} [0.2 (float 0.2)]) ;; -> #{0.2 0.2}

First it seems that `==` is used to check for equality, but I think
it's not the case.

(= 0.5 (float 0.5)) ;; -> true

Ahh -- seems that `(float 0.5)` gets converted to `double` before
comparing via `=`.

Getting `#{0.2 0.2}` is bad: we won't be able to read this set literal
back in.

#{0.2 0.2} ;; -> java.lang.IllegalArgumentException: Duplicate key: 0.2

So my question is: does anyone know about tutorials, docs etc. on
clojure.org or elsewhere where I can find advices/best practice/a
"clojure specifications" (like the JLS does it for Java) on this
topic.

Henrik

-- 
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: error in nrepl

2017-06-24 Thread Colin Yates
Spacemacs is worth a look for a very different emacs experience. Used with
emacs from homebrew and macports (at different times :-)). If you are
heavily invested in your own init.el then maybe not as a full time
replacement but it is worth a look for its evil, which-key and hydra config
alone.

On Saturday, 24 June 2017, Peter Hull  wrote:

> On Friday, 23 June 2017 23:14:55 UTC+1, lawrence...@gmail.com
>  wrote:
>>
>>
>> I'm curious if folks think it is easier to work with Emacs on a Linux
>> machine, or on a Mac?
>>
>> I use Emacs on Mac, Linux and Windows. I disagree that it's more
> difficult to use on the Mac vs Linux. On Windows I get my emacs from cygwin
> so there is a bit of 'mental gear shifting' required between path names and
> line endings.
>
> On the Mac I installed homebrew and installed Emacs that way. Once in
> Emacs, I did exactly the same for all three platforms - added MELPA to the
> packages list and then installed cider (and paredit). I can post more
> details if you want but it sounds like you're an Emacs veteran already!
>
> I've used Atom+protorepl on Windows. It gives you a more modern/better
> integrated system but IMO it doesn't have all the features/reliability of
> Emacs+cider. (this might just be down to my unfamiliarity with Atom)
>
> Hope that helps.
>
>
> --
> 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: error in nrepl

2017-06-24 Thread Peter Hull
On Friday, 23 June 2017 23:14:55 UTC+1, lawrence...@gmail.com wrote:
>
>
> I'm curious if folks think it is easier to work with Emacs on a Linux 
> machine, or on a Mac? 
>
> I use Emacs on Mac, Linux and Windows. I disagree that it's more difficult 
to use on the Mac vs Linux. On Windows I get my emacs from cygwin so there 
is a bit of 'mental gear shifting' required between path names and line 
endings. 

On the Mac I installed homebrew and installed Emacs that way. Once in 
Emacs, I did exactly the same for all three platforms - added MELPA to the 
packages list and then installed cider (and paredit). I can post more 
details if you want but it sounds like you're an Emacs veteran already!

I've used Atom+protorepl on Windows. It gives you a more modern/better 
integrated system but IMO it doesn't have all the features/reliability of 
Emacs+cider. (this might just be down to my unfamiliarity with Atom)

Hope that helps.
 

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