Re: [ANN] Deeto - A Java dynamic proxy factory for interface-typed data transfer objects

2019-07-04 Thread henrik42
Yes! I agree. This is for people how want/must stay with Java for reasons. 
There are people in the Clojure community who work on 
Java-Clojure-integration and this is one of man ways to go. I just hope it 
is useful for someone. It could even be a door opener for Clojure and more 
people (like you say) "discover" Clojure.

Am Donnerstag, 4. Juli 2019 02:10:21 UTC+2 schrieb gvim:
>
> Sounds like everything I escaped from when I discovered Clojure. 
>
> gvim 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/d93f0f74-7878-451b-bd94-88a034bbd40b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] Deeto - A Java dynamic proxy factory for interface-typed data transfer objects

2019-07-03 Thread henrik42
Hi everyone,

I'm pleased to announce the release of Deeto 0.1.0 [1]

Deeto is a Clojure library for Java developers. With Deeto you can
define your data transfer object types via interfaces in Java. You do
not need to implement these interfaces. Instead you can ask Deeto to
analyze (via reflection) the interface class and then give you a
factory for it.

Deeto returns Java dynamic proxys which implements `Cloneable` and
`Serializable`. The proxy has sane `equals`, `hashCode` and `clone`
implemetations.

It's available now on Clojars.

Henrik

[1] https://github.com/henrik42/deeto/tree/0.1.0

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/51f21a20-ae63-449d-a126-5d5545ab876a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling Java from Clojure

2019-06-12 Thread henrik42
I hacked just that a few days ago to support Java development at work: 
https://github.com/henrik42/deeto Not released yet but could be a starter 
in that direction.
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/997b6c66-866d-493f-99fc-da2ce63f8b5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Calling Java from Clojure

2019-06-11 Thread henrik42
If you're willing to use Spring you can create Clojure-based Spring Beans 
[1] and let Spring inject (autowire) them into your Java-based 
Spring-Beans. And if you like you could use Spring just as a factory that 
you invoke. I would still define interfaces (that you want to use from 
Java) in Java, so that IDE autocompletion, generics etc. work as excepted. 
HTH
Henrik

[1] https://github.com/henrik42/spring-break

Example:





Am Montag, 10. Juni 2019 17:34:25 UTC+2 schrieb eglue:
>
> > I find the glue code is actually small in practice (I've done a couple 
> of real systems this way). This particular example is a little weird 
> because it's just making a domain object, but generally you're writing the 
> glue to provide a factory method for a facade. Below the facade, the 
> Clojure code can make new objects just fine, so you're staying in Clojure 
> for the rest of it.
>
> Very helpful, thanks!
>
> On Monday, June 10, 2019 at 8:20:44 AM UTC-5, Alex Miller wrote:
>>
>>
>> On Mon, Jun 10, 2019 at 12:04 AM eglue  wrote:
>>
>>> This is great, Alex, thanks. (Sorry, I deleted from underneath you and 
>>> reposted to fix the title before I saw your reply...)
>>>
>>> The latter option, writing interfaces and classes in Java and calling w/ 
>>> the glue code is a great option.
>>>
>>> However one big motivator for people moving from Java to langs like 
>>> Scala and Kotlin is being able to implement those bean/record types, eg, 
>>> with such little fanfare & boilerplate (eg in Clojure, using defrecord is 
>>> so concise). 
>>>
>>
>> The problem with wanting the Clojure-y version from Java is that those 
>> interfaces are generic and weird from the Java side. So either you get 
>> bean-like code familiar to Java users or generic collection/keyword 
>> interfaces that will be weird to use from Java. I heard your goal as "be 
>> friendly from Java", which means, making bean-like interfaces. On the 
>> Clojure side, it's pretty easy to macro-ize the creation of those over 
>> defrecords or whatever, so it could still be  a lot less macro work, just 
>> depends how far you want to go with it. You don't get all the benefits of 
>> Clojure from Java; you have to be in Clojure for the many related design 
>> decisions to compound together. There's no magic solution to that (other 
>> than "just use Clojure" :).
>>  
>>
>>> And you can sometimes end up with a handful of these, so the 'glue code' 
>>> isn't quite so small. Also gen-class and definterface I find similarly 
>>> nice. 
>>>
>>
>> I find the glue code is actually small in practice (I've done a couple of 
>> real systems this way). This particular example is a little weird because 
>> it's just making a domain object, but generally you're writing the glue to 
>> provide a factory method for a facade. Below the facade, the Clojure code 
>> can make new objects just fine, so you're staying in Clojure for the rest 
>> of it.
>>  
>>
>>> I wonder if there's a path to improve what you're calling option #2. 
>>> Specifically the needing to AOT compile *everything*. It seems I should 
>>> only have to AOT/precompile the surface area that my Java consumer wants to 
>>> link with. At runtime perhaps there'd be some creative way to leave out the 
>>> AOT classes (which would just have been used for static-time compiling) and 
>>> when the JVM tries to load those classes some agent could interject and do 
>>> the dynamic Clojure loading?
>>>
>>
>> Seems like you're taking the hardest path and trying to make it harder. I 
>> just don't see the point in running at this one, sorry. My experience is 
>> that the approach above works great and has none of these issues.
>>  
>>
>>>
>>>
>>> On Sunday, June 9, 2019 at 11:21:28 PM UTC-5, Alex Miller wrote:
>>>>
>>>> Looks like the title for this is backwards if I understand the intent, 
>>>> should be calling Clojure from Java, right?
>>>>
>>>> Java code is going to invoke methods on classes (that's all it knows 
>>>> how to do). You have several options:
>>>>
>>>> 1) Use the Clojure Java API to invoke the Clojure runtime - here you're 
>>>> leveraging the Clojure runtime's Java impl core to call into Clojure 
>>>> (Stu's 
>>>> example)
>>>> 2) Use protocols, records, and/or genclass to actually produce Java 
>>>> classes (your example, I think). 
>>>> 3) Define your i

[Q] How to release with Leiningen and `with-profile`?

2019-04-05 Thread henrik42
I'd like to do a `lein with-profile +local-repo release` and
`lein with-profile +clojars release`. This way I want to control
which repo the deploy goes to.

I tried but it didn't work. Here you find my attempt: 
https://github.com/henrik42/buttle/blob/master/project.clj#L92

Looking at the sources of the `release`, `do` and `with-profile`
tasks I realized that the `release` task re-loads `project.clj`
for each task it invokes. And it has to. Otherwise it would
not "see" then change/effects of
["change" "version" "leiningen.release/bump-version"]. And that's
the reason why a release via `do` does not work.

So I'm stuck. Releasing via `with-profile` and `do` does not work
since `do` does not re-load `project.clj`. And releasing via
`with-profile` and `release` does not work because `release` has
no concept of a profile and `with-profile` does not work on
`release` because `release` re-loads `project.clj`
without "applying" the currently active profiles.

My current solution is to split up the release steps into three
seperate `do` tasks (release-prepare!, release-deploy! and
release-finish!). With each `lein` invokation the `project.clj`
gets loaded and things work fine: 
https://github.com/henrik42/buttle/blob/master/project.clj#L50

But I'd like to do this in one lein invokation.

In https://clojurians-log.clojureverse.org/leiningen/2016-03-04.html 
(around dmuylwyk 
<https://clojurians-log.clojureverse.org/leiningen/2016-03-04.html>17:03:35 
<https://clojurians-log.clojureverse.org/leiningen/2016-03-04/1457113235.000175>)
 
this topic is discussed also.

Any idea? Maybe there is a better way to do the trick with the
repos?

Regards, 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: [Q] Deploying two artefacts/jars with same group/artefactid via Leiningen

2019-04-05 Thread henrik42
@Francis Great that works. Thank's! 

The deploy task expects a repo argument in this case though. So I came up 
with this: 
https://github.com/henrik42/buttle/blob/1.0.0/plugin/leiningen/deploy_driver.clj
 


With this I can use this in project.clj 
https://github.com/henrik42/buttle/blob/master/project.clj#L39-L44

"deploy-driver" ["deploy-driver" ;; 
calls Buttle's plugin/leiningen/deploy_driver.clj
 ":leiningen/repository" ;; 
pseudo repository -- see plugin/leiningen/deploy_driver.clj
 "buttle/buttle" ;; 
group/artefact-id
 ":leiningen/version";; 
pseudo version number -- see plugin/leiningen/deploy_driver.clj
 "driver";; 
classifier
 "target/uberjar/buttle-driver.jar"] ;; 
file -- see :uberjar-name

"deploy-all" ["do" "deploy," "uberjar," "deploy-driver"] ;; 
depoy everything to snapshots/releases depending on version




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


[Q] Deploying two artefacts/jars with same group/artefactid via Leiningen

2019-03-28 Thread henrik42
Hi,

I have an uberjar that I want to deploy to clojars. Part of
building the uberjar is building the "standard" lib-jar of the
same project.

Now I'd like to release/deploy both with the same group/artefactid to
clojars. The uberjar should get the :classifier "app".

So after that people could lein depend on the lib-jar and can download
the "app" via browser/wget/etc.

I've tried different things (e.g. lein-package) with no luck.

The problem is that deploying them "one at a time" re-deploys pom.xml and 
that fails. 
So deployen two jars must be aware of this and deploy pom.xml only once.

Any idea?

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


[ANN] buttle 0.1.0 -- A proxying JDBC driver with hooks

2019-03-21 Thread henrik42
Hello,

I just did my very first release to clojars. 

https://github.com/henrik42/buttle

*Buttle* is a proxying JDBC driver with hooks. It can be used like any 
other JDBC driver and lets you do testing, debugging, monitoring etc.

Hope someone finds this usefull.

Sincerely,

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: [Q] How to load Clojure as part of Wildfly module?

2019-02-07 Thread henrik42
Rastko - thanks for the reply. My 
/modules/buttle/main/module.xml looks like this:



  

  
  

 
  
 

And the driver in standalone.xml:


  


The loading of my classes incl. clojure.lang.RT works "in
principle". Only when Clojure uses the TCCL to load clojure/core.clj things 
fail. To see what's
happening I changed
java/buttle/SetContextClassLoaderInStaticInitializer.java to:

package buttle;
public class SetContextClassLoaderInStaticInitializer {
static {
ClassLoader tccl = 
Thread.currentThread().getContextClassLoader();
System.out.println("tccl = " + tccl);
System.out.println("tccl sees clojure/core.clj at " + 
tccl.getResource("clojure/core.clj"));
ClassLoader myCl = 
SetContextClassLoaderInStaticInitializer.class.getClassLoader();
System.out.println("myCl = " + myCl);
System.out.println("myCl sees clojure/core.clj at " + 
myCl.getResource("clojure/core.clj"));

Thread.currentThread().setContextClassLoader(SetContextClassLoaderInStaticInitializer.class.getClassLoader());
}
}

I get:

tccl = ModuleClassLoader for Module "org.jboss.as.controller" version 
4.0.0.Final from local module loader @6adca536
   (finder: local module finder @357246de (roots: 
C:\henrik\wildfly-12.0.0.Final\modules,C:\henrik\wildfly-12.0.0.Final\modules\system\layers\base))
tccl sees clojure/core.clj at null
myCl = ModuleClassLoader for Module "buttle" from local module loader 
@6adca536 (finder: local module finder @357246de
   (roots: 
C:\henrik\wildfly-12.0.0.Final\modules,C:\henrik\wildfly-12.0.0.Final\modules\system\layers\base))
myCl sees clojure/core.clj at 
jar:file:/C:/henrik/wildfly-12.0.0.Final/modules/buttle/main/./buttle-standalone.jar!/clojure/core.clj

I checked that my class and clojure.lang.RT are loaded with the same 
classloader. So the TCCL which Wildfly puts into
place cannot load clojure/core.clj. But the (module) classloader which 
loaded my class and clojure.lang.RT CAN load it. That's
why I came up with the idea of replacing the TCCL before 
clojure.lang.RT runs.

I believe that the way Wildfly uses the different classloaders is absolutly 
on purpose. In [1] you find
arguments for why libraries should not use the TCCL for certain things. And 
one could argue, that Clojure
is doing it the wrong way.

I believe that the existence of clojure.core/*use-context-classloader* is 
due to someone realizing that there are
cases when you cannot use the TCCL (like in mine). In my case though I just 
can't set that var because of the chicken-egg-problem
as I pointed out.

I think that adding additional dependencies or adding exports won't
change the Module-"org.jboss.as.controller"-classloader. But I'll check 
tomorrow.

One solution that comes to mind is to change clojure.lang/RT so that the 
*use-context-classloader* var is not initialized to
true but to (Boolean/parseBoolean (System/getProperty 
"clojure.use-context-classloader" "true"))

Henrik

[1] https://developer.jboss.org/wiki/ModuleCompatibleClassloadingGuide

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


[Q] How to load Clojure as part of Wildfly module?

2019-02-06 Thread henrik42
Hi,

I'm working on a "proxying JDBC driver" in Clojure [1]. Everything is
working fine. But I had one problem with the way Clojure
(i.e. clojure.lang.RT) manages its classloader.

When Wildfly loads my UBERJAR which contains Clojure and
loads/instanciates my gen-class `buttle.jdbc.Driver` then its static
initializer will load `clojure.lang.RT`. At this point the current
thread's context classloader (TCCL; which is put into place by
Wildfly) does NOT point to the one that is loading my code and the
TCCL in-fact does not "see" my classes.

So when Clojure/RT then tries to find `clojure/core.clj` it fails
because Clojure uses the TCCL for loading [2]. I could try to set
`clojure.core/*use-context-classloader*` to false but this leads to a
chicken-egg-problem since for doing that, `clojure.lang/RT` would have
to be loaded in the first place. 

So my question is: is there a nice way out of this?

The workaround I came up with was to compile a Java class [3] which is
the super class of my gen class [4]. And since static initializers are
called in order super-class->derived-class the static initializer of
the super-class is used to set the TCCL to the one that loads my code
base. After that Clojure finds clojure/core.clj without problems.

Any ideas on how to do without this hack?

Henrik

[1] https://github.com/henrik42/buttle/
[2] 
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L2174
[3] 
https://github.com/henrik42/buttle/blob/master/java/buttle/SetContextClassLoaderInStaticInitializer.java
[4] https://github.com/henrik42/buttle/blob/master/src/buttle/driver.clj#L29

-- 
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: [Q] Transparently call functions remotely via nREPL?

2018-04-29 Thread henrik42
Hi,

I ended up using https://github.com/technomancy/robert-hooke -- like this:

,,,(:require [clojure.tools.nrepl :refer :all])

(defn remote-eval [conn code]
  (let [{:keys [value err]} (-> (client conn 1000)
(message {:op :eval
  :code code})
(combine-responses))]
(if err (throw (RuntimeException. err))
(read-string (last value)

(defn remote-wrapper [conn-fn v]
  (fn [_ & args]
(remote-eval
 (conn-fn)
 (format "(apply %s/%s [%s])"
 (-> v meta :ns) (-> v meta :name)
 (apply pr-str args)

(defn -main [& args]
  (let [conn-fn ,,,]
(hooke/add-hook #'a-fn
(remote-wrapper conn-fn #'a-fn))
(hooke/add-hook #'b-fn
(remote-wrapper conn-fn #'b-fn))
,,,


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


[Q] Transparently call functions remotely via nREPL?

2018-04-10 Thread henrik42
Hi,
I'm calling some functions a,b and c via ring/compojure. I would like to be 
able to switch to "remote invocation of a, b and c via nREPL" without 
changing my ring/compojure routes. I know I can just code that into a, b 
and c,(not good, not-dry) but I was wondering if there is a lib that 
supports this use-case out-of-the-box.

Any ideas?

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

2017-06-25 Thread henrik42
Alex,

Am Samstag, 24. Juni 2017 13:38:55 UTC schrieb Alex Miller:
>
>
> 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/
>

Thanks for your reply. Yes, I know. Here 
https://github.com/henrik42/java-quiz#numberquiz I wrote down some of the 
"interesting cases".

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

Oh, I thought because there is the float-function floats are supported. 
Clojure could use "0.2f" to print/read floats and still use double "0.2" as 
the default (but float's "Infinity" may be challenging ;-)
 
Java uses f2d when comparing float vs. double and when mixing floats and 
double for +/-/etc. All I'm saying is that Clojure *could* use (Double. 
(str f)) instead of f2d in these cases. That would make (= (double 0.2) 
(Double. (str (float 0.2 ;; -> true

Talking about infinity: #{Double/POSITIVE_INFINITY} ;; -> #{Infinity} But 
#{Infinity} ;; -> Exception: Unable to resolve symbol: Infinity in this 
context. Is there a way to deal with this at the moment?


> 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.
>
 
And throw an exception when doing so? Or is it GIGO?

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

I'll read that. Thanks.

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.


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: Component and company with Spring?

2017-04-14 Thread henrik42
I did the opposite - build Spring beans with clojure - 
https://github.com/henrik42/spring-break#defining-clojure-based-spring-beans

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


[Q] How to consume stdout/stderr from remote nREPL session while session call is still running?

2016-07-02 Thread henrik42
Hi,

I'm using an nREPL server as an sshd replacement for Windows. I'm doing 
things like unzip files, copy files, calling shell (bat/cmd/git bash) 
scripts local to the nREPL process. The scripts write to stdout/stderr. 
Some of the scripts produce **A LOT** of output so I'm not using 
clojure.java.shell/sh 
but java/lang/Runtime.exec(). I consume stdout and stderr via futures 
asynchronously to the exec() and write them to stdout/stderr of the nREPL 
process.

But this way I can't see the output on the calling nREPL client side.

So my question is: is there a "standard way" to consume data synchronously 
to the nREPL session-call in order to use the data on the nREPL client side?

I thought of using a small timeout when doing the call, and if it has not 
completed then do a seperate call to the server to "download" the data 
which I  would "cache" on the server side (via bounded buffers/core.async 
so that I do not run out of heap in case the client is too slow 
downloading). 

Any better idea?

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: How can find something inside heavily nested data structure ?

2015-08-23 Thread henrik42
OK,  so in this special case you one would just use

(def s
  [{n {id a} d 2 children [{n {id c} d 4 children 
nil}]} {n {id b} d 3 children nil}])

(some
 (fn [x]
   (and (map? x)
(some
 #{{id c}}
 (vals x
 (tree-seq coll? seq s))

-- 
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 can find something inside heavily nested data structure ?

2015-08-22 Thread henrik42
I like using tree-seq and core.match when working on instaparse ASTs - like 
this:

(require ['clojure.core.match :as 'm])

(def s
  [{n {id a} d 2 children [{n {id c} d 4 children 
nil}]} {n {id b} d 3 children nil}])

;; top-down-traversal
(defn nodes [x]
  (tree-seq coll? seq x))

;; target pred
(defn sel-pred [n]
  (and (map? n)
   (some
#{{id c}}
(vals n
(some
 (fn [x]
   (m/match x
(_ :guard #(sel-pred %)) x 
:else nil))
 (tree-seq coll? seq s))

The guard is a little clumbsy but as far as I can see match does not 
support map-matches with binding-keys like {k {id c}}.

-- 
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: [BUG?] loading Clojure source files from various data sources (classloading)

2015-06-06 Thread henrik42
Hi,

I hacked a small example. 
https://github.com/henrik42/stuff/blob/master/require-example/java/RequireExample.java
Testes with 1.5.1. 

- 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: [BUG?] loading Clojure source files from various data sources (classloading)

2015-05-23 Thread henrik42
Hi Alex,

I did some experimenting with Clojure and RMI and tried some things with 
classloading.
The READE at https://github.com/henrik42/rmi-examples is long-ish - sorry. 
At the end I used 
(defmacro compile-with-cl [body]
  (.addURL @Compiler/LOADER (java.net.URL. 
http://127.0.0.1:8080/class-server/;))
  `(~@body))
to add an URL to the current Compiler/LOADER which did the trick for what I 
tried to do.
In the comments above the code I describe the problem you're having.
Hope that helps.

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


Help: Markdown in Leiningen project :description not recognized by codox

2015-04-13 Thread henrik42
Hi,

I'd like to use Markdown in the description of my Leiningen project.clj:

(defproject foo 0.1.0-SNAPSHOT
  :description  *foo* is my project
  :plugins [[codox 0.8.11]]
  :codox {:defaults {:doc/format :markdown}}
[...])

But its not working. Markdown in function descriptions is working fine.

Is this by design or a bug? Any idea?

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


Delivering HTML documentation to end-users via uberjar

2015-04-09 Thread henrik42
Hi,

I'd like to ship my app *incl. documentation* as an uberjar to end-users 
and give them access to the docs via HTTP.
I plan to use codox/marginalia/markdown-clj to produce the HTML in lein 
build and then build the uberjar incl. the generated HTML.

The app will have a CLI but as a plus I'd like to offer something like

  java -jar uber.jar view-docs 

which should run an HTTP Server and start-up the users default browser and 
connect that to the HTTP Server (with no-proxy).

Is there a simple out-of-the-box way to do that? Or should I just use jetty 
and ring?
Any ideas?

- 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: XPATH/XSLT like access to Clojure data structures?

2015-02-28 Thread henrik42
Thanks. But I'm looking for something that may
(a) clojure.walk a clojure data structure
(b) let me use clojure.match rules to say what I'm interested in (like 
xpath does) and
(c) use zippers to 'mutate'.
- 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: Extending the LispReader with embeded language lorms

2015-02-10 Thread henrik42
@Luc: I see your points. Thanks for the reply.

Just to make it clear: all I suggest is to integrate 
https://github.com/henrik42/extended-lisp-reader/blob/master/src/extended_lisp_reader/core.clj
into clojure.core - i.e. make #[...]-forms and the delegation to user code 
official.
The rest of my lib is just examples of how this feature *could* be used.

So we're talking about ~15 lines of code.

But again - this might open up a way that we do not want to go in the end.

Time will tell.


-- 
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: Extending the LispReader with embeded language lorms

2015-02-09 Thread henrik42
Not anybody? I'm a little puzzled: is this feature so useless? I thought 
embedding stuff like CSV data in Clojure code as is could be a nice 
feature.
https://github.com/henrik42/extended-lisp-reader#parsing-csv
No need to rewrite it in Clojure syntax/string literals or other forms.

I think after having tagged literals (which still stick to Clojure 
forms/syntax) 
it could be the next step in building DSLs with Clojure.

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.


Extending the LispReader with embeded language lorms

2015-01-31 Thread henrik42
Hi,

I would like to be able to include non-Lisp-ish DSLs in my clojure code 
(like bash HERE documents) e.g. for copypasting CSV data into the code 
without having to go through an external file and consume that. 

So I hacked an experiment that does the parsing and embeding (transforming 
to Clojure target form is missing in the examples).
If you're interested have a look at 
https://github.com/henrik42/extended-lisp-reader

What do you think? 

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: Q: How to parse stream of text (from java.io.Reader) via instaparse with minimal input consuption

2015-01-31 Thread henrik42
Hi,
I finally came up with a simple function that incremenally consumes the 
input stream, building the head of the input and calls an instaparse parser 
when it encounters a ]. If this fails, the function recurs.
This function is not even dependent on instaparse directly.
You can find the source at 
https://github.com/henrik42/extended-lisp-reader/blob/master/src/extended_lisp_reader/stream_parser.clj
In 
https://github.com/henrik42/extended-lisp-reader/blob/master/src/extended_lisp_reader/instaparse_adapter.clj
 
you find (parser-for) that builds an instaparse parser that parses input 
text from a stream/Reader.
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: Extending the LispReader with embeded language lorms

2015-01-31 Thread henrik42
*LOL* Can anybody change the title to embeded language forms? :-)

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


Q: How to parse stream of text (from java.io.Reader) via instaparse with minimal input consuption

2015-01-06 Thread henrik42
Hi all,

I want to parse a stream of text which comes from a java.io.Reader with 
https://github.com/Engelberg/instaparse.

But the stream of text will only start with what can be parsed by my 
grammar. The rest of the text stream must be 
consumed/parsed with some other grammar. I know of instparse's :total parse 
which can be used to parse as
much as possible and it will give you what could not be parsed.
But the text comes from a stream. And further processing will consume this 
(statefull) stream/Reader. I cannot just slurp the Reader,
give instaparse the String and then process the String for the 
not-parsed-part. And I cannot unread that much (it's a PushbackReader).

So my question is: is there a way to use instaparse with a Reader/Stream in 
such a way, that instaparse will consume
exactly those Chars/Bytes that are covered by the resulting parse-tree 
and leave any following data un-read in the Reader?
(Since it is a PushbackReader with buffersize=1 I could accept a 
1-char-lookahead read)

Any idea?

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.


[UPDATE] Spring/Clojure integration / changing Clojure references via JMX attributes

2014-11-10 Thread henrik42
Hello again,

just in case anybody is following this - I added stuff that lets you 
publish your mutable references (atom, ref, var) as JMX attributes so that 
you may use jconsole to change things at runtime. 

https://github.com/henrik42/spring-break#changing-mutable-state-references-via-jmx-attributes

Publishing is as easy as


bean name=clj_states parent=clojure_fact
constructor-arg value=
(require 'spring-break.jmx)
(spring-break.jmx/make-mbean 
  :my_mbean
  (atom 42 
:validator number? 
:meta {:attr-name (name :an_atom) 
   :attr-description (name :a_description) }))
 /
  /bean


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


[UPDATE] Spring/Clojure integration / Clojure functions via JMX

2014-10-18 Thread henrik42
Hi folks,
I added code that lets you call your clojure functions via JMX operations.

https://github.com/henrik42/spring-break#jmxmbeans

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


[ANN] Spring/Clojure integration

2014-10-03 Thread henrik42
Hi, i've been using Spring for Java development for a while now and wanted 
to share my ideas of how Clojure might fit into that. I know that Clojure 
does not need DI but I'd like to use Clojure for logging, debugging, 
performance measurement etc. within a Java-based app. If you're interested 
have a look at https://github.com/henrik42/spring-break I'm still writing 
on it. Feedback is very much appreciated. 

-- 
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: Working on a patch to add Clojure for Spring dynamic language support

2014-09-22 Thread henrik42
Hi Adan,

not sure if it helps, but defining Spring beans that call Clojure code is 
straight forward:

bean id=hello_world 
class=clojure.lang.Compiler 
factory-method=load
constructor-arg
  bean class=java.io.StringReader
constructor-arg value='Hello world!' /
  /bean
/constructor-arg
  /bean

You can find more examples at https://github.com/henrik42/spring-break
I've played around with the Spring scpting API but as far as I can tell it
won't let you define BeanFactoryPostProcessor that Spring picks up when
it starts up the application context. So I tried to get away without using 
that.
What do you 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.