Re: [ANN] Discontinuing 4clojure.com

2021-07-05 Thread Gary Verhaegen
Thanks a lot for keeping it running for so long! 4clojure was really
instrumental in my Clojure journey.

On Sun, 4 Jul 2021 at 22:26, Alan Malloy  wrote:

> TL;DR: Turning off 4clojure.com by the end of July 2021
>
> Hello, 4clojure problem solvers. You've probably noticed SSL errors on
> 4clojure.com over the last week. The old decrepit system 4clojure runs on
> has finally gotten out of date enough that I can't even figure out how to
> get it recent enough that SSL certs will auto-renew anymore.
>
> In principle I could start from scratch on a new server and move 4clojure
> over, but I won't. 4clojure has been piggybacking along on a server that I
> use for personal reasons, and over the years I have less and less reason to
> keep paying for that server - it's now pretty much just 4clojure costing me
> an embarrassing amount of money every month because I haven't wanted to
> disappoint the community by shutting it down. This SSL thing is just what
> made me finally pull the trigger.
>
> I don't have a specific EOL date in mind, but sometime near the end of the
> month, since that's the billing cycle. Until that time, 4clojure still
> works, as long as you don't mind clicking through the security warnings -
> it really is still me hosting the site, and since the connection is still
> HTTPS (albeit with an invalid cert) I think that means your data is still
> safe. If you have solutions to problems you're proud of, you've still got
> some time to print them out and put them up on your refrigerator.
>
> I'm not seeking new maintainers. I'd feel uncomfortable handing over a
> database with so many email addresses and password hashes in it to anyone.
> The service has had a good run - just over a decade since the first
> release
> .
> I hope you enjoyed it during that time.
>
> --
> 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/385cdef8-fa40-47ba-b5b1-0b3a7cc34935n%40googlegroups.com
> 
> .
>

-- 
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/CAGqyAaqMztmQqLdax2Z-d-qOS_qaQqsMFvykosDVe655hkQ8mw%40mail.gmail.com.


Re: How to get a value of a var in Java

2021-06-18 Thread Gary Verhaegen
The official Clojure API for Java is defined here
 and
only supports importing Clojure vars under the IFn interface. In other
words, you can only import Clojure functions, not Clojure values, through
that API. What you are trying to do is not supported.

That does not mean it's impossible. If you control the Clojure side, the
easiest approach is to just make a function and call that through the
official API. If for some reason that's not an option, you can try gen-class
, which may be faster.

If you can't change the Clojure side, you'll have to use undocumented APIs.
The Clojure.var

call
will return a Var

(cast
to the IFn

interface), which has a deref()

method that should get you the underlying value. This is undocumented so it
may break and all that, but it really looks like all you need to do is cast
that IFn back to a Var (or an IDeref
,
as Chris suggested).

Overall, I'd strongly recommend going through the documented API and just
add a no-arg function.

On Fri, 18 Jun 2021 at 12:53, ru  wrote:

> Dear Clojure users and team!
> Citation 1 from Clojure documentation:
>
> "Calling Clojure From Java..
> IFn plus = Clojure.var("clojure.core", "+");
> plus.invoke(1, 2);.."
>
> With functions all well but with def..
>
> Citation 2:
>
> "(def *symbol* *doc-string*? *init*?)
>
> Creates and interns or locates a global var
>  with the name of *symbol* and a
> namespace of the value of the current namespace (*ns*). "
>
> I can not figure out how to get the value of the symbol, created with def
> construct in Clojure and, for example, print it with System.out.println in
> Java.
>
> I tried everything, nothing works! :(
>
> Any help would be greatly appreciated.
>
> Sincerely,
>
>   Ru
>
>
>
>
>
> --
> 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/fcbd3883-705a-4180-9b99-7ccad64a09afn%40googlegroups.com
> 
> .
>

-- 
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/CAGqyAap%3D9hSErWXirxYAcp8uHVDc91LSJ5bQkKwOxFad6KjG_Q%40mail.gmail.com.


Re: How to Programmatically Create Unqualified Keywords?

2018-03-22 Thread Gary Verhaegen
I think there's some confusion here between the keyword and its textual 
representation.

The root issue is that the keyword function is, in a way, too lenient in its 
error checking: it will allow you to create keywords that are not valid 
according to the language definition. The Clojure reader is a bit more 
restrictive, though it too will allow a number of exceptions to the official 
definition on the main Clojure website.

For example, the reader will accept keywords with # or . in their name, which 
is used by some libraries to represent css ids and classes. These two 
characters are not valid in the name of a keyword as per the language 
definition.

The keyword function will let you create a keyword whose name starts with a 
colon, or whose name contains a space. These are not accepted by the reader and 
definitely do not match the language definition.

When you manually write ::hello in a Clojure file, the reader will interpret 
that as :user/hello, i.e. a keyword with user as its namespace and hello as its 
name. Neither the slash nor the colon are part of the keyword itself; they are 
just part of the syntax Clojure uses to represent keywords in a textual form.

With the keyword function, if you call (keyword ":hello"), you get a keyword 
that has ":hello" as a name. That is not valid data for that function, but it 
can be created in memory. There is, however, no syntax in Clojure that can 
correctly represent that keyword textually. If you try to print it, you will 
see ::hello, but that is fundamentally different from you writing ::hello. In 
other words you have created a keyword that does not roundtrip: if you print it 
and then read it, you will not get the same value again.

Similarly if you use the keyword function to create a keyword with a space, you 
will not be able to read it back as its textual representation will look like a 
keyword and a symbol.

> On 21 Mar 2018, at 15:09, Mauricio Aldazosa  
> wrote:
> 
> 
> 
>> On Wed, Mar 21, 2018 at 7:48 AM, Nick Mudge  wrote:
>> I see what you mean.  All keywords are namespaced, so there really is no 
>> such thing as a no-namespaced keyword. Thank you.
> 
> You can have keywords without a namespace:
>  
> user> (clojure-version)
> 1.9.0
> user> (keyword "bar" "foo")
> :bar/foo
> user> (namespace (keyword "bar" "foo"))
> bar
> user> (keyword "foo")
> :foo
> user> (namespace (keyword "foo"))
> nil
> -- 
> 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: If Clojure is to blame for the majority of the startup time, why doesn't ClojureScript proportionally slow down the JavaScript startup time also?

2018-01-24 Thread Gary Verhaegen
I've read a mot of discussions around that but have never myself looked into 
the details, so the following may be completely wrong.

My understanding is slightly different: the JVM does not actually load a class 
before it is first accessed by running code. What takes a long time for the JVM 
and not for JS engines, I think, is not loading the code, but creating objects.

For Clojure to run, all of your functions need to exist as objects in memory. 
Java bytecode does not have any mechanism to describe objects, so when Clojure 
starts up, it has to first load the code that defines the classes, then load 
the code that creates instances of those classes, and then execute that code to 
actually get the function objects. Only then can it start even thinking about 
looking at your own code. AOT thus just saves on parsing string files into 
Clojure lists, but it cannot really help with the problem that all of these 
objects still have to be created again from scratch at each start up.

The javascript engines have a way of representing objects directly (aka json), 
so this is much less of a problem: a lot of that object creation can be done at 
compile time and the js engine can just load objects in memory directly from 
the js file. You can go further (like Lumo does) by preloading these objects in 
memory directly as part of the executable bundle, skipping the part where you 
need to parse a string.

So in my understanding it mostly boils down to the ability to define objects 
directly, so they can just be loaded in memory, versus having to load and 
execute code to create the objects.

> On 24 Jan 2018, at 09:09, Didier  wrote:
> 
> So if that is true, then the slow startup times are to blame on Java. I 
> understand that Clojure does a lot of extra stuff at startup that a plain 
> Java main method would not, but those extra things Clojure does are slow, 
> because of the way the JVM handles them, where as they are quite fast on V8 
> or other JavaScript engines.
> 
>> On Friday, 14 July 2017 16:24:33 UTC-7, Gary Trakhman wrote:
>> My mental model explains most of this away due to the different load 
>> patterns of java vs v8.  In JVM clojure, functions are essentially 1:1 with 
>> classes, so in a functional language and standard lib, that's a lot of 
>> classes.  Java will eagerly classload your entire app and deps before doing 
>> any work.  V8 takes an upfront hit on parsing into javascript, but the JS 
>> target fits the structure of clojure itself much more closely.  More time 
>> (not sure how much compared to JVM) will be spent JITing hot code paths, but 
>> that won't show up in the startup cost.
>> 
>> You can get JVM clojure REPL startup a little faster by AOT compiling all 
>> your deps, but it's generally not worth it in a development flow.
>> 
>> I think lumo does some extra tricks to keep this upfront cost down that are 
>> v8-specific: 
>> https://anmonteiro.com/2016/11/the-fastest-clojure-repl-in-the-world/
>> 
>>> On Fri, Jul 14, 2017 at 6:20 PM Didier  wrote:
>>> This link: 
>>> https://dev.clojure.org/display/design/Improving+Clojure+Start+Time says 
>>> that the Java startup time is ~94 ms, while Clojure boot time is ~640 ms. 
>>> That's a ~680% increase.
>>> 
>>> On my machine the java start time is: ~1042 ms, and the Clojure start time 
>>> is around ~3108 ms. A ~298% increase.
>>> 
>>> When I time the startup time of lumo against node, I get ~1190 ms for node, 
>>> and ~1523 ms for lumo. A ~128% increase only.
>>> 
>>> Does Clojure perform more initialization then ClojureScript? And would that 
>>> explain the much higher overhead Clojure has on top of the JVM, versus 
>>> ClojureScript?
>>> -- 
>>> 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 

Re: Officially support Vert.x

2018-01-10 Thread Gary Verhaegen
It’s not clear what the "do" is supposed to mean in those defns (unless there’s 
some deep dark magic going on, they are currently not doing anything and you 
can just remove them), and you very likely want "let" instead of "def" for the 
local variables.

def in Clojure does not follow lexical scoping rules; it’s always a global name.

> On 10 Jan 2018, at 10:25, Feuer Au  wrote:
> 
> And here is the simple example "Hello from Vert.x!" like other languages on 
> the Vert.x official frontpage:
> (ns examples.simple-http-server)
> 
> (require
>  '[io.vertx.clojure.core.core :as core]
>  '[io.vertx.lang.clojure.vertx :as vertx]
>  '[io.vertx.lang.clojure.http-server :as server]
>  '[io.vertx.lang.clojure.http-server-request :as request]
>  '[io.vertx.lang.clojure.http-server-response :as response])
> 
> (defn handle-request [req]
>   do
>   (def response (request/response req))
>   (response/put-header response "content-type" "text/plain")
>   (response/end response"Hello from Vert.x!"))
> 
> (defn start [vertx]
>   do
>   (def http-server (vertx/create-http-server vertx))
>   (server/request-handler http-server (core/handler handle-request))
>   (server/listen http-server 8080))
> Pretty straight forward, but we could make it better
> e.g. combine different namespaces into one single would be nice 
> and we got pure functions in different namespaces 
> hmmm, it looks nice.
> -- 
> 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: Lazy sequences (once again?)

2018-01-08 Thread Gary Verhaegen
It really boils down to understanding garbage collection: memory that cannot be 
reached anymore is freed. In the first code sample, when running (last r), the 
compiler has detected that r is never used afterwards, so it clears the local 
variable. This means that while last is walking through the sequence one 
element at a time, the JVM can detect that all of the elements it has seen so 
far cannot be accessed anymore (Clojure seqs do not generally have any "back" 
pointer), so the GC is free to delete them. On the other hand, in the second 
code sample, when the call to (last r) is running, Clojure needs to keep a 
reference to r around so that it can later on call (first r), which prevents 
any garbage collection from happening, as r points to the first element, which 
points to the second, etc. up until wherever (last r) has gone so far. So you 
need to realize the full seq in memory.

Now to answer your question: lazy seqs are a functional programming tool. 
Mixing them with side effecting code is dangerous. How is that relevant? Well, 
your question only makes sense if you assume that your function x is 
side-effecting; if it isn’t the answer is simply to not call it at all and call 
y directly, as you wouldn’t be doing anything with the result of x anyway.

As long as you have a clear idea of the order of evaluation, you should be fine.

> On 8 Jan 2018, at 07:20, Edward Knyshov  wrote:
> 
> Hi I recently started to dig into lazy sequences processing in clojure 
> because I need to process huge amount of data that doesn't fit in memory.
> I found a few articles and examples describing the way lazy seqs work in 
> clojure. But so far all I got myself is a paranoia.
> Now everywhere I look in the code I have a feeling that it's gonna retain my 
> sequence in memory.
> It seems like realization of lazy clojure sequences is very unclear sometimes 
> and you can't reason about it.
> 
> For example:
> 
> (let [r (range 1e9)]
>(first r)
>(last r))
> ;;=> 9
> 
> (let [r (range 1e9)]
>(last r)
>(first r))
> ;;=> java.lang.OutOfMemoryError: GC overhead limit exceeded
> 
> I got this example from here 
> https://github.com/danielmiladinov/joy-of-clojure/blob/master/src/joy-of-clojure/chapter6/laziness.clj
> I tried it myself and it works as it's commented above.
> But how in the world does it work internally?
> How can I reason about this code in more complex example where instead of 
> function first there is some function x and instead of function last there is 
> some function y.
> I can't come up with some clear rule of thumb that would help me to be 
> confident that my code works well on lazy collections without running it and 
> checking whether it throws OOME or not..
> I would appreciate if anyone could point me to any discussion/article/paper 
> that makes things more clear?
> -- 
> 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: [ANN] Git Deps for Clojure!

2018-01-08 Thread Gary Verhaegen
Have you considered adding an equivalent to lein’s pedantic option, i.e. an 
option that would die on ambiguous versions rather than make a choice, thereby 
forcing users to make that choice explicit as a top-level entry? (Or through 
exclusions etc.)

As an aside, is it even possible on the JVM to have multiple versions of a 
dependency loaded? Wouldn’t the last version loaded override all the common 
classes, leaving you with a sort of hybrid that doesn’t correspond to any 
single version? I’d really like a dependency system that makes each dep’s 
transitive dependencies only visible to itself, so there would never be any 
reason to resolve dependencies.

Also, how realistic do you think it is today to expect all of our transitive 
dependencies to be developed according to that growth mindset you mention? It’s 
one thing to adopt it in my code, but quite another to assume it’s followed 
correctly by all of the underlying Java libs.

> On 8 Jan 2018, at 01:24, Alex Miller  wrote:
> 
> 
>> On Sun, Jan 7, 2018 at 6:53 PM, Nathan Fisher  wrote:
>>  
>> I strongly agree with your decision of “pick the latest”. While I do 
>> understand multiple active versions can make it easier for a developer I 
>> don’t think that’s the “right” decision. Besides I can only imagine how much 
>> of a pain it would be to implement reliably. I’d expect if I specify a 
>> patched version of struts that a transitive dependency wouldn’t have the 
>> ability to override that for its own purpose.
> 
> I guess I didn't mention that top-level deps always win, so if desired you 
> are always able to decide the specific version in your project.
> 
> -- 
> 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 spec generate and instrument in cascade

2018-01-07 Thread Gary Verhaegen
A Google search for "clojure spec generate" turned up this for me on
the first page of results:
https://github.com/stathissideris/spec-provider

It may or may not fit your use-case, but scanning through the README
it seems at least related to what you're looking for.

On 7 January 2018 at 18:25, Azzabi Ahmed  wrote:
> Hi all, so usually I structure my application as black box, that takes some 
> input and gives output, I usually validate inputs before starting with them 
> in my system boundaries, which I think clojure spec is good for since it also 
> allows to document what my application accept or expect. Now my question is 
> there a library that allows to deduct/infer specs then I call instrument to 
> validate that following called methods respect the specs.
>
> Example
>
> If I have function foo that takes some input that I already wrote specs for, 
> then foo will call bar with some part of the input. Is their a lib to infer 
> bar specs based on foo specs and calls ? Also that then I can instrument and 
> check if all code calls are consistent ?

-- 
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: core.async consumer + producer working by chunk?

2018-01-05 Thread Gary Verhaegen
On 5 January 2018 at 19:44, Rob Nikander  wrote:

> Hi,
>
> I’m wondering if there is a core.async design idiom for this situation...
>
> - A buffered channel
> - One producer feeding it
> - A bunch of consumers pulling from it.
> - Producer should wake up and fill the channel only when it’s empty. In
> other words, the producer should work in chunks.
>
> My first idea is to have two channels. The second will be used by
> consumers to signal the producer that the primary channel is empty. But I'm
> wondering if there is a better way.
>
> The motive for this is that the producer is doing a DB query that is more
> efficient in bulk. `select ... limit 50` rather than `select ... limit 1`
> 50 times.
>
> Rob
>

What about simply having the producer put items one by one on the channel?

(ns t.core
  (:require [clojure.core.async :as async]))
(defn ap
  "atomic print"
  [m]
  (print (str (pr-str m) "\n")))
(defn produce-next-batch
  [s]
  (let [m (+ s 10)]
[(range s m) m]))
(defn chunked-producer
  [init-state]
  (let [result-chan (async/chan)]
(async/go
  (loop [[batch cursor] (produce-next-batch init-state)]
(ap {:produced batch})
(doseq [elem batch]
  (async/>! result-chan elem))
(recur (produce-next-batch cursor
result-chan))
(defn run-consumer
  [ch id n]
  (async/go
(dotimes [_ n]
  (ap {:id id :received (async/> [c1 c2 c3]
 (mapv async/

-- 
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: Advice on Shell Scripting with new "clojure" binary

2018-01-05 Thread Gary Verhaegen
On 4 January 2018 at 23:26, Delon Newman  wrote:
> Also, any additional advice with respect to using Clojure for shell
> scripting would be appreciated.

Unless you have a specific reason to prefer the JVM to Node as a
platform for your script, I'd encourage you to take a look at Planck
and Lumo for shell scripting. Being based on Node allows them to start
up much faster, which may or may not be important to your use-case.

http://planck-repl.org
https://github.com/anmonteiro/lumo

-- 
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: Port graphs: What would Rich Hickey do?

2018-01-04 Thread Gary Verhaegen
Unfortunately most of the contexts were fairly specific and a few
years ago, so I don't remember all of the details, and mostly in the
context of private research that I'm not at liberty to share. Some of
the results have been published (though not my specific work) by a
then-colleague of mine; you can find his papers by googling "amine
ghrab graph olap".

On 4 January 2018 at 18:19, Ben Kovitz <bkov...@gmail.com> wrote:
> On Thursday, January 4, 2018 at 4:01:41 AM UTC-5, Gary Verhaegen wrote:
>
>> Have you considered encoding your port graph into a normal graph?
>
>
> That was the first idea I had, and I quickly rejected it as adding
> complication. The consideration that led me to port graphs in the first
> place was that when, say, I have a node for "plus", and it has neighbor
> nodes for "operand" and "sum", which other nodes connect to, an easy bug is
> that when the "plus" is deleted, its "operand" and "sum" nodes might not get
> deleted—leaving the graph in an invalid state. I figured it would be best to
> just absorb those connection nodes into the "plus" node in the form of a
> list of "ports", and include the port labels in the edges. Then deleting the
> "plus" automatically deletes the ports, you can easily query for "what nodes
> are connected to the plus" (where you want to skip connection nodes), and
> generally there are fewer ways to make mistakes in the code.
>
> However, following Christopher Small's suggestion to check out the Datomic
> APIs, I'm now thinking that a layer to map the port graphs to simplicial
> ("normal", undirected) graphs might actually be the simplest thing. Nodes,
> ports, and edges are easily represented by nodes in a simplicial graph. This
> escapes the "type headache" that led me to start this thread, since all
> edges in the port graph are just plain nodes in the simplicial graph,
> whether they're port-to-port edges, port-to-edge edges, or edge-to-edge
> edges. The layer of indirection might cost some performance—and performance
> does matter here, since this program is extremely CPU-bound—but it's more
> important to preëmpt bugs by keeping code simple.
>
> And now you make this interesting point, which I hadn't previously
> considered:
>
>> That would require you to define a mapping, but would then allow you to
>> fairly easily reuse theorems, algorithms and libraries by having them
>> operate on the encoded graph, with a hopefully thin layer of translation.
>
>
> I could even use ubergraph to represent the simplicial graph, and thereby
> get access to all code that follows the loom protocols.
>
>> I have seen this approach of encoding graphs into other graphs work out
>> pretty well in other contexts.
>
>
> Do you remember any of those other contexts? Maybe I could check one out and
> learn something from it.
>
>> If you’re shopping around for ideas as to how to define data manipulation
>> API, it may be worth taking some time looking at Specter too.
>
>
> Thanks for this suggestion, too. I'm now checking it out.
>
> --
> Ben Kovitz
> http://pages.iu.edu/~bkovitz/
>
> --
> 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: [ANN] rocks.clj/z 0.1.0-SNAPSHOT (alpha)

2018-01-04 Thread Gary Verhaegen
To (possibly) clarify, I think what Tim meant was more along the lines
of "have your code depend on the java.nio package, which means it will
die at compile time on Java 1.6 and lower with a
ClassNotFountException, and therefore say in the README that this
requires Java 1.7+".

On 4 January 2018 at 13:34, Tim Visher  wrote:
> On Thu, Jan 4, 2018 at 12:04 AM, Edward Knyshov  wrote:
>>
>> Thanks :)
>>
>> I haven't considered using nio Zip FileSystem just because I never heard
>> of it, but I'll definitely check it out.
>>
>> Regarding targeting to java 7, should something like this set up targeting
>> properly?
>>
>> :javac-options ["-target" "1.7" "-source" "1.7"]
>
>
> Not really. That's for compiling java code. I think that may interact in
> some way with AOT as well but I'm honestly not sure. A library really
> shouldn't AOT anything anyway (most things shouldn't :) ).
>
> What I meant by targeting wasn't compilation but requiring a minimum java
> version of 1.7, as the java.nio.file package was only added in 1.7 iiuc.
>
> In contrast, clojure itself only requires 1.6.
>
> --
>
> In Christ,
>
> Timmy V.
>
> https://blog.twonegatives.com
> https://five.sentenc.es
>
> --
> 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: Port graphs: What would Rich Hickey do?

2018-01-04 Thread Gary Verhaegen
If you’re shopping around for ideas as to how to define data manipulation API, 
it may be worth taking some time looking at Specter too.

Have you considered encoding your port graph into a normal graph? That would 
require you to define a mapping, but would then allow you to fairly easily 
reuse theorems, algorithms and libraries by having them operate on the encoded 
graph, with a hopefully thin layer of translation.

One possible encoding based on what you’ve described could be to turn nodes and 
edges in the port graph into nodes in the encoded graph, and ports in the port 
graph into edges in the encoded graph. It’s hard to say how well that specific 
transform would work in your case without more details about your type of graph 
and somewhat more considerate thinking than I’ve given this, but I have seen 
this approach of encoding graphs into other graphs work out pretty well in 
other contexts.

> On 2 Jan 2018, at 20:11, Christopher Small  wrote:
> 
> > ...noticed that the attribute names in the datoms are a lot like the port 
> > labels in port graphs. A port label is essentially an attribute key whose 
> > value is the edges incident to it. And when you chain data patterns in 
> > Datalog queries, that's a lot like navigating through a graph.
> 
> That's very much in line with what I was thinking you might want to do in 
> this setting.
> 
> You should also take a look at the entity api. It let's you traverse the 
> graph via these entity objects which behave more or less like a dictionary of 
> the av pairs associated with a particular entity in the database. Importantly 
> though, when an attribute points to another entity (a reference attribute), 
> it is returned as yet another of these entity objects, letting you traverse 
> the graph using get, in a pretty similar fashion to what you're describing.
> 
> http://docs.datomic.com/entities.html
> 
> You may also check out the pull api. It let's you pull facts out of the graph 
> as regular old maps by specifying what attributes & paths you wish to pull 
> out of the graph. The result is that you can read from the underlying graph 
> database as though it was a document store, but where the documents are 
> dynamically computed/queried from the graph based on the pull expression you 
> provide. You can also use pull expressions inside the `:find` clause of 
> either a DataScript of Datomic datalog query, which is often a convenient way 
> of specifying both a set of entities (via a datalog query) and statement of 
> facts to pull about them.
> 
> http://docs.datomic.com/pull.html
> 
> Collectively, these three interfaces give you quite a lot of expressiveness 
> and flexibility in how you query/traverse your data.
> 
> 
> 
>> On Tue, Jan 2, 2018 at 12:31 PM, Ben Kovitz  wrote:
>> Christopher Small,
>> 
>> Your suggestion to look into Datomic definitely turned up a new idea. I went 
>> through the Datalog tutorial at http://www.learndatalogtoday.org (which is 
>> excellent, by the way), and noticed that the attribute names in the datoms 
>> are a lot like the port labels in port graphs. A port label is essentially 
>> an attribute key whose value is the edges incident to it. And when you chain 
>> data patterns in Datalog queries, that's a lot like navigating through a 
>> graph.
>> 
>> The new, hopefully simple, easy-to-use, and not error-prone idea is to use 
>> the clojure.lang.IPersistentMap  interface to query and update graphs. 
>> Nodes, edge, attribute names, port labels, and a few "reserved keywords" 
>> like :adj-nodes and :edge, could navigate the graph as if it were an 
>> ordinary nested map with get-in, assoc-in, and the like, without ever 
>> needing to wrap anything inside a record to tell what it is. Here are some 
>> sample queries and what they could return:
>> 
>> (get-in g [node port-label :adj-nodes])
>>   a coll of all the nodes with an edge to [node port-label]
>> (get-in g [node port-label :adj-node])
>>   one node with an edge to [node port-label], or nil
>> (get-in g [node port-label])
>>   true or false, according to whether node has a port named port-label
>> (get-in g [node k])
>>   value of node's attr k
>> (get-in g [edge k])
>>   value of edge's attr k
>> (get g node-or-edge)
>>   the entire map of attrs associated with node-or-edge, or nil if it does 
>> not exist
>> (get-in g [node k1 k2 k3])
>>   treat node's attrs as a nested map
>> (get-in [node port-label :edges])
>>   a coll of all the edges that link to [node port-label]
>> (get-in [node port-label :edge])
>>   a single edge that links to port-label, or nil
>> (get-in [node port-label1 port-label2])
>>   coll of all nodes that link to [node port-label1] from a port named 
>> port-label2
>> 
>> And here are some function calls that would return a modified graph:
>> 
>> (assoc-in g [node k] v)
>>   sets node attr k to v
>> (assoc-in g [edge k] v)
>>   sets edge attr k to v  (and similarly for multiple keys)
>> 

Re: Call custom Clojure function with dependencies from Java

2017-12-30 Thread Gary Verhaegen
On 29 December 2017 at 18:19, Pablo J. Villacorta 
wrote:

> Thanks! You are right, I have tried another minimal statement and does not
> throw any exception... looks like the statement on that repo is not correct
> either (I don't know what's wrong with it), but don't know how to output
> proper error messages. According to the repo,
>
> (xs/validate-statement-data statement-str) ;; => returns statement edn
>
> but I do not know what edn stands for. Moreover, I always have the
> argument as a plain string, not as an object as in this
> example.
> I have read also this:
>
> (xs/errors->data (xs/statement-checker bad-statement :en ;; ltag is
> optional, defaults to :en
> ;; => {"actor" "Missing required key", "id" "Not a string: 123"}
>
> but I am unclear of the meaning of -> and how to use that from Java. Looks
> like statement-checker is for objects, not for strings?
>
> I have a minimal working example here: https://github.com/
> olbapjose/xapi-clojure
>
> Regards and happy new year!
>

Disclaimer: I am not familiar with this library at all, so there's a little
bit of guesswork on my part.

>From the README, it looks like validate-statement-data accepts either
Clojure data (a.k.a. "edn", a combination of nested maps and vectors) or a
string that can be parsed as JSON. It will throw an exception if the data
given is not valid, and otherwise return the data, i.e. it will return its
argument unchanged if you pass in Clojure data, but if you pass it a
string, it will parse that to Clojure data and then (assuming no validation
error) it will return the (parsed) data. In Java terms this would be the
kind of signature you'd expect in so-called "fluent" APIs.

statement-checker seems to have essentially the same underlying semantics,
but be designed for a more imperative API: it returns null if the given
data is valid, and an error otherwise. This seems to be the same
java.lang.Exception that would be thrown by validate-statement-checker, but
it is simply returned instead of being thrown. So this is designed for a
usage pattern where you want to have an explicit if statement rather than a
try/catch.

Because Exception objects are not that great to work with, the library
supplies a errors->data function that extracts some additional descriptive
data from the exception. The -> is just part of the normal, valid
characters for identifiers in Clojure, so this is just the name of the
function with no special (language-level) semantics; the intention here is
that this function transforms an error into data, so the -> is meant to
represent an arrow. You can read it as "error to data". (I don't really see
a reason why statement-checker doesn't just return the error data, rather
than wrapping it in an exception, though I'm sure the author had some
reason for designing it this way.)

EDN stands for "extensible data notation"; more details here:
https://github.com/edn-format/edn

However, in this context I think the author simply means "Clojure data"
when he writes "edn". Clojure data is composed of nested maps and vectors,
that respectively implement java.lang.Map and java.lang.List.

-- 
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: [ANN] Clojure 1.9.0 is now available!

2017-12-30 Thread Gary Verhaegen
What version of clojure.tools.logging are you using?

> On 30 Dec 2017, at 02:05, Luc  wrote:
> 
> I went through the compiler code, it has to do with a bad local binding 
> expression.
> 
> It crashes in the same way in the REPL with this minimal defrecord:
> 
> (defrecord NoopJob [name job-controller-channel env job-state parameters 
> job-output]
>   impl/GatewayJob
>   (start-job! [this]
> (log/error "NoopJob job died unexpectedly !")))
> 
> No try catch, no core.async, ...
> So there's something going on in log/error macro expansion versus the 
> defrecord expansion.
> 
> I attached two files, the macro expansions of defrecord and the log/error 
> macro.
> 
> Alex if you prefer I can open a ticket. If nothing obvious comes out that's 
> were it will end up anyway.
> I'll toy with the combined macro expanded code this weekend to see if I can 
> narrow this a bit more.
> 
> I have been using the same logging API for years now (since 2009). I really 
> want to know what's broken.
> I have two dozen projects to upgrade to 1.9 :) It's bizarre at best.
> 
> Thank you,
> Luc P.
> 
>> On Saturday, 30 December 2017 00:17:47 UTC, Luc wrote:
>> Hi Alex,
>> 
>> here it is, I did not get through the compiler source code yet, it might be 
>> obvious to you:
>> 
>> java.lang.UnsupportedOperationException: Can't type hint a primitive local, 
>> compiling:(yabug/jobs/noop.clj:21:9)
>> Exception in thread "main" java.lang.UnsupportedOperationException: Can't 
>> type hint a primitive local, compiling:(yabug/jobs/noop.clj:21:9)
>> at clojure.lang.Compiler.analyze(Compiler.java:6792)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$VectorExpr.parse(Compiler.java:3253)
>> at clojure.lang.Compiler.analyze(Compiler.java:6775)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3881)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:6991)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3881)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:6991)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
>> at clojure.lang.Compiler$TryExpr$Parser.parse(Compiler.java:2334)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
>> at clojure.lang.Compiler$NewInstanceMethod.parse(Compiler.java:8431)
>> at clojure.lang.Compiler$NewInstanceExpr.build(Compiler.java:7937)
>> at 
>> clojure.lang.Compiler$NewInstanceExpr$DeftypeParser.parse(Compiler.java:7813)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
>> at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6420)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
>> at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5460)
>> at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4022)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3813)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6330)
>> at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
>> at clojure.lang.Compiler.analyze(Compiler.java:6773)
>> at clojure.lang.Compiler.analyze(Compiler.java:6729)
>> at clojure.lang.Compiler.compile1(Compiler.java:7604)
>> at clojure.lang.Compiler.compile(Compiler.java:7676)
>> at clojure.lang.RT.compile(RT.java:413)
>> at clojure.lang.RT.load(RT.java:458)
>> at clojure.lang.RT.load(RT.java:426)
>> at 

Re: Officially support Vert.x

2017-12-29 Thread Gary Verhaegen
Is vert.x an absolute (external) requirement, or is that a tool you want to
use to achieve some goal? If the latter, maybe there are other tools in the
Clojure ecosystem that you could use instead?

On 29 December 2017 at 13:49, Toby Crawley  wrote:

> The short answer is no, there is no Clojure support for Vert.x 3 that I
> know of.
>
> The longer answer: I wrote the Clojure language module for Vert.x 2, which
> had a pretty low usage rate, partially because core.async was released
> around the same time. When Vert.x 3 was being written, the Vert.x team
> asked me if I wanted to build a Clojure module for it. I declined because I
> didn't think there was enough interest to warrant the effort, and because
> Vert.x 3 moved to a code generation system for language modules that was
> geared towards object-oriented languages, which would have been difficult
> to use for generating a Clojure api.
>
> - Toby
>
>
> On Thu, Dec 28, 2017 at 10:53 PM, Feuer Au  wrote:
>
>> Hi All,
>>
>> Curious about Vert.x is officially supported?
>>
>> We tried to use some new languages on JVM e.g. Scala, Kotlin etc.
>>
>> and be interested in using some relatively purely functional programming
>> languages and so far Clojure is our best bet
>>
>> but unfortunately couldn't find native Clojure api on Vert.x but got
>> official support for Kotlin
>>
>> so just wonder is there any official support for Vert.x in Clojure?
>>
>> Cheers!
>> --
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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: [ANN] Clojure 1.9.0 is now available!

2017-12-29 Thread Gary Verhaegen
Can you try deleting code until the error disappears, and try to get to a
minimal reproducing case that way? Does it still happen if the protocol and
record are in the same ns? Does it still happen if you remove the reset!
and >!! forms?

Is that whole code within a custom macro? The name e# for the exception
seems to suggest this is part of a syntax-quote?

On 29 December 2017 at 01:13, Luc  wrote:

> Hi,
>
> I am baffled. I switched a project from 1.8 to 1.9.0 upgrading also other
> dependencies
> (latest version fo core.async, ...) via lein ancient.
>
> As usual I ran an AOT pass to make sure I don't have anything fishy before
> running the code.
>
> I got  this from the AOT pass:
>
> java.lang.UnsupportedOperationException: Can't type hint a primitive local
>
> Oupse... I Reverted to 1.8 w/o reverting the dependency changes. it AOTed
> w/o a glitch.
>
> I narrowed it at:
>
> (:ns )
> (defprotocol GatewayJob
>   (start-job! [this] "Start the given job")
>   ...)
>
> (:ns )
> (defrecord NoopJob [name job-controller-channel env job-state parameters
> job-output]
>   impl/GatewayJob
>   (start-job! [this]
>...
> (try
>   
>   (catch Exception e#
>  (reset! job-state :failed) (>!! job-controller-channel [this
> :new-state :failed :error e#])
> (log/error (format "NoopJob job died unexpectedly !") e#) ))) <-
> Here
>
> error is a macro which expands here to:
>
> (clojure.tools.logging/log* logger__458__auto__ :error nil
> (clojure.core/print-str "NoopJob job died unexpectedly !"))
>
> The (try (catch...) compiles w/o problems outside of the protocol
> implementation. It bombs a soon as it is
> embedded in a protocol implementation. 3 instances in three different
> namespaces same behavior and same
> code pattern (try .. catch .. reset! >!! ...
>
> I have been toying with this for an hour but I need some new direction(s)
> to eventually nail it.
> I dived in the list of changes of 1.9 but my search didn't come up with
> anything relevant yet.
>
> Anything changed in the defrecord macro expansion that could explain this ?
> Something related to core.async ? (it works with 1.8 w/o reverting the
> other dependencies however)
> A malpractice in the code structure that was tolerated so far ?
>
> I looked at the macro expansion of the defrecord but did not find anything
> wrong on the surface.
>
> Note that I did not yet attempt to run this project from source. That's
> forthcoming but I would expect
> it to crash at runtime..
>
> Any idea is welcomed.
>
> Thank you,
> Luc P.
>
> --
> 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: spec key aliasing or different specs for same keyword

2017-12-29 Thread Gary Verhaegen
You could always extract specific keys from the payload and validate that,
something like:

(GET "/..." req
  (let [b (:body req)
data {:my/result (:resultCount b)
  :my/other-key (get-in b [:some :path])}]
(my-business-logic data)))

i.e. spec what your code (my-business-logic here) expects, not the API call
itself.

On 28 December 2017 at 19:09, Jonathon McKitrick 
wrote:

> Yes, the namespacing is great, so I have no issue with that. I would just
> rather use snake-case in Clojure than camel-case. Since the payload has
> 'resultCount' I'd like to map that to a spec named result-count instead.
>
> I think I figured out part of the answer:
>
> (s/def :my/result int?)
> (s/def :your/result pos-int?)
> (s/def ::test-spec-1 (s/keys :req-un [:my/result]))
> (s/def ::test-spec-2 (s/keys :req-un [:your/result]))
>
> I see here that I can have an unqualified keyword as part of a qualified
> spec name. I think that's what I want.
>
> On Thursday, December 28, 2017 at 12:26:59 PM UTC-5, adrian...@mail.yu.edu
> wrote:
>>
>> Avoiding global name collision is the reason why specs are named with
>> namespace-qualified keywords. I am confused by your last sentence though.
>> Do you mean Clojure namespaces or the namespace component of the keyword
>> itself? There is no requirement in clojure.spec that the namespace of the
>> specs you def be coupled to the Clojure namespace they happen to be defined
>> in. If you are actually asking about how to write specs for unqualified
>> keys in a map there is a built-in facility to do that as well:
>> clojure.spec.alpha/keys has a :req-un and :opt-un argument.
>>
>> On Thursday, December 28, 2017 at 11:28:18 AM UTC-5, Jonathon McKitrick
>> wrote:
>>>
>>> I have one spec question covering two scenarios.
>>>
>>> 1. Suppose I want to spec a payload from a third-party API that has the
>>> keyword ':resultCount' in it. Does that mean my specs for that item must
>>> have the same name?
>>>
>>> 2. Supposed I have a few payloads from that API and each has a keyword
>>> ':result' but the spec for each will be different. Other than using an
>>> entirely different namespace, how can I map the :result keyword to
>>> different specs?
>>>
>>> Thanks!
>>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] Clojure 1.9.0 is now available!

2017-12-26 Thread Gary Verhaegen
The spec is correct; your code is wrong and I don't know how you got your
expansion there.

$ lein try org.clojure/clojure 1.9.0
nREPL server started on port 55018 on host 127.0.0.1 - nrepl://
127.0.0.1:55018
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_144-b01
Docs: (doc function-name-here)
  (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (defmulti mycomp (fn [v] v))
#'user/mycomp
user=> (defmacro defcomp [m]
  #_=>   `(defmethod mycomp ~m
  #_=>  [_]
  #_=>  ~m
  #_=> )
  #_=>   )
#'user/defcomp
user=> (defcomp :test)

CompilerException java.lang.RuntimeException: Can't use qualified name as
parameter: user/_, compiling:(null:1:1)
user=> (macroexpand '(defcomp test))
(. user/mycomp clojure.core/addMethod test (clojure.core/fn [user/_] test))
user=>

The problem is that you have not protected the _, so it gets expanded to
the local namespace (user/_ in my case here, com.mxsys.psql.component/_ in
yours). You want:

user=> (defmacro defcomp [m] `(defmethod mycomp ~m [~'_] ~m))
#'user/defcomp
user=> (defcomp :test)
#multifn[mycomp 0x545609d8]
user=> (macroexpand '(defcomp :test))
(. user/mycomp clojure.core/addMethod :test (clojure.core/fn [_] :test))
user=>

Notice how the underscore is escaped as ~'_ to escape from the syntax quote
and place a literal underscore symbol.

-- 
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: Call custom Clojure function with dependencies from Java

2017-12-26 Thread Gary Verhaegen
On 26 December 2017 at 14:54, Pablo J. Villacorta 
wrote:

> Thank you so much guys.
>
> Yes, it is an error launched by the library, but with a statement that
> should be valid since I copied it from the github page of the project. It
> seems that the "@cec1ce2" means something but I don't know...
> it is exactly this input statement: https://github.com/
> yetanalytics/xapi-schema/blob/master/README.org#validate-a-
> statement-from-a-json-string-clojurescript
>

The code you showed in your email explicitly calls

myfunction.invoke("some string");

which is the equivalent of the Clojure code

(xs/validate-statement-data "some string")

which is documented to throw an Exception by the README, in the Usage
section:

(let [bad-statement (dissoc statement "actor")]
  (xs/validate-statement-data bad-statement)) ;; => throws Exception or
js/Error

If you look at the code for xs/validate-satement-data, you can see that it
pretty much reduces to calling xs/validate-statement, which itself looks
like:

(defn validate-statement [s]
  (if-let [error (statement-checker s)]
(throw #?(:clj (Exception. (str error))
  :cljs (js/Error. (str error
s))

See
https://github.com/yetanalytics/xapi-schema/blob/master/src/xapi_schema/core.cljc#L24-L29
for more context.

So what I think has happened is that you have given an invalid string to
the function ("some string"), so it is throwing a java.lang.Exception with,
as its message, the result of calling clojure.lang/str on the error
returned by the schema library. That error is a Java object of a class that
clojure.lang/str doesn't know about, so it falls back to calling the Java
method toString. As the schema.utils.NamedError class does not implement
(override) toString, this falls back to java.lang.Object#toString(), which
prints the name of the class followed by some random-looking hex value that
is supposed to be somehow linked to the place of the object in memory
(except that number doesn't change when the GC moves the object, so it's
more some sort of identity than an address).

If you also get a stack trace when you do pass expectedly valid data to the
function, can you prepare a minimal Github project with the code that
fails? I can't see anything wrong in your descriptions so far so I'd need
to look at the exact code you're trying to run to help you further.

-- 
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: Call custom Clojure function with dependencies from Java

2017-12-24 Thread Gary Verhaegen
schema.utils.NamedError does not look like a loading error; is there any chance 
that could be an error thrown by the library? Are you positive "some string" is 
a valid argument to validate-statement-data?

A cursory look at the README of xapi-schema seems to indicate that function 
will throw an exception if the input is not valid. I suspect it's working as 
intended.

> On 24 Dec 2017, at 17:35, Justin Smith  wrote:
> 
> If you require a namespace that requires another namespace, this will all be 
> resolved and loaded automatically as long as all the namespace files can be 
> found on the classpath.
> 
> I suspect that what you showed here is not the full error output, it seems to 
> be missing the information we would need to know what actually went wrong 
> here.
> 
>> On Sun, Dec 24, 2017 at 8:31 AM Pablo J. Villacorta  
>> wrote:
>> Hi all,
>> 
>> I am totally new to Clojure. From Java I am trying to call a Clojure 
>> function which belongs to a wider project and has dependencies. I have 
>> compiled the Clojure project to an uber jar running lein uberjar, the 
>> imported the jar into my Java project, and then did
>> 
>> IFn require = Clojure.var("clojure.core", "require");
>> require.invoke(Clojure.read("xapi-schema.core"));
>> 
>> and then
>> 
>> IFn myfunction = Clojure.var("xapi-schema.core", "validate-statement-data");
>> myfunction.invoke("some string");
>> 
>> but since myfile.core has dependencies (I see some "require" sentences in 
>> the Clojure code of that file), I wonder if I have to manually read all the 
>> dependent clojure files in the project (which are a lot), or there's a 
>> better way to do this from Java. The error I am getting is:
>> 
>> java.lang.Exception: schema.utils.NamedError@cec1ce2
>> 
>>  at xapi_schema.core$validate_statement.invokeStatic(core.cljc:27)
>>  at xapi_schema.core$validate_statement.invoke(core.cljc:24)
>>  at 
>> xapi_schema.core$validate_statement_data_STAR_.invokeStatic(core.cljc:40)
>>  at xapi_schema.core$validate_statement_data_STAR_.invoke(core.cljc:38)
>>  at xapi_schema.core$validate_statement_data.invokeStatic(core.cljc:44)
>>  at xapi_schema.core$validate_statement_data.invoke(core.cljc:43)
>>  at clojure.lang.Var.invoke(Var.java:379)
>>  at 
>> StatementValidatorXAPITest.testClojureValidator(StatementValidatorXAPITest.java:133)
>> 
>> where schema.utils is one of the files that I did not read explicitly from 
>> Java. 
>> 
>> Thank you so much in advance and Merry Christmas to everyone!
>> 
>> 
>> 
>> 
>> -- 
>> 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.

-- 
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: Unexpected performace of transducers

2017-12-18 Thread Gary Verhaegen
Yes.

> On 17 Dec 2017, at 15:56, Matan Safriel <dev.ma...@gmail.com> wrote:
> 
> Thanks Gary, Alex, Didier, I learned a lot from your replies.
> As per iota, I assume we're talking about this library of course.
> 
> 
> On Sun, Dec 17, 2017 at 2:40 PM, Gary Verhaegen <gary.verhae...@gmail.com> 
> wrote:
> The iota library implements a reducible object on top of files. It may be 
> worth trying out for your use-case.
> 
>> On 17 Dec 2017, at 00:32, Alex Miller <a...@puredanger.com> wrote:
>> 
>> 
>> 
>>> On Saturday, December 16, 2017 at 2:39:14 PM UTC-6, Matan wrote:
>>> Hi, 
>>> 
>>> As this thread seems to have been going down this path, I am joining it 
>>> after having spent some time fiddling the source code of some clojure.core 
>>> transducers and familiarizing with how to create, compose and use 
>>> transducers in transducing processes. By the way I think the reference 
>>> could be more explicit about the relationship between transducers, 
>>> transducing processes and contexts for applying transducers (as is, IMO a 
>>> lot of ambiguity arises, causing a lot of confusion in getting started). 
>>> So, it was noted earlier in this thread by Alex Miller:
>>> 
>>>> You're starting from a lazy sequence, not a self-reducible collection. 
>>>> That's not wrong, but it's removing a key transduce/reduce power to work 
>>>> with reducible colls.
>>> 
>>> I think that's also the case with applying any transducer to a file input 
>>> (?!) and I am therefore wondering about:
>>> I didn't fully grasp the difference between self-reducible collections v.s. 
>>> other ones (in this context, and in general). 
>>> Can you please delineate?
>> I'm referring primarily to collections that implement their own reduce() 
>> method (like vectors and lists) vs seqs.
>>> Roughly how much performance lag do we get when not working a transduction 
>>> from a (self) reducible collection, and moreso why exactly? 
>> Vectors and lists are concrete, have all their own data available, and can 
>> directly iterate through the data in a tight loop. Seqs must be realized and 
>> this entails object creation, synchronization, and object destruction 
>> overhead per element (or for chunked seqs, per chunk). 
>> 
>> Some collections can be iterated like a seq OR reduce themselves (vectors, 
>> lists, seqs on arrays, and the collection produced by range, cycle, repeat, 
>> and iterate).
>>> Should we typically choose a different vehicle for stream processing from 
>>> large files, over using transducers? My current use case is 
>>> stream-processing from large files.
>> Stream processing is just another means of producing values. The question is 
>> really in how you represent the stream. Seqs have some inherent overhead. 
>> Presumably you don't want to read the entire stream and put it in a 
>> collection. The trick then is to create an object that is reducible, not a 
>> seq, and reads the stream. Probably the easiest way is to use something 
>> Iterable that can provide an iterator over the stream. The CollReduce 
>> protocol is extended to Iterable so this is already built in. Then 
>> reduce/transduce over the iterable.
>> 
>> An eduction combines a reducible collection and a transformation 
>> (transducer) into a collection that delays its execution until the point 
>> where you reduce it (this has some of the same utility as a lazy sequence in 
>> delaying execution). 
>> 
>> How exactly you want to iterate over reading the stream depends on what 
>> you're doing (Java provides streams, readers, and channels for a variety of 
>> different use cases). In any case you want to have an Iterator 
>> implementation (hasNext() and next()) that can provide the "next" item. 
>> Things like Apache Commons IOUtils can give you line iterators over a reader 
>> for example. 
>> -- 
>> 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

Re: Unexpected performace of transducers

2017-12-17 Thread Gary Verhaegen
The iota library implements a reducible object on top of files. It may be worth 
trying out for your use-case.

> On 17 Dec 2017, at 00:32, Alex Miller  wrote:
> 
> 
> 
>> On Saturday, December 16, 2017 at 2:39:14 PM UTC-6, Matan wrote:
>> Hi, 
>> 
>> As this thread seems to have been going down this path, I am joining it 
>> after having spent some time fiddling the source code of some clojure.core 
>> transducers and familiarizing with how to create, compose and use 
>> transducers in transducing processes. By the way I think the reference could 
>> be more explicit about the relationship between transducers, transducing 
>> processes and contexts for applying transducers (as is, IMO a lot of 
>> ambiguity arises, causing a lot of confusion in getting started). So, it was 
>> noted earlier in this thread by Alex Miller:
>> 
>>> You're starting from a lazy sequence, not a self-reducible collection. 
>>> That's not wrong, but it's removing a key transduce/reduce power to work 
>>> with reducible colls.
>> 
>> I think that's also the case with applying any transducer to a file input 
>> (?!) and I am therefore wondering about:
>> I didn't fully grasp the difference between self-reducible collections v.s. 
>> other ones (in this context, and in general). 
>> Can you please delineate?
> I'm referring primarily to collections that implement their own reduce() 
> method (like vectors and lists) vs seqs.
>> Roughly how much performance lag do we get when not working a transduction 
>> from a (self) reducible collection, and moreso why exactly? 
> Vectors and lists are concrete, have all their own data available, and can 
> directly iterate through the data in a tight loop. Seqs must be realized and 
> this entails object creation, synchronization, and object destruction 
> overhead per element (or for chunked seqs, per chunk). 
> 
> Some collections can be iterated like a seq OR reduce themselves (vectors, 
> lists, seqs on arrays, and the collection produced by range, cycle, repeat, 
> and iterate).
>> Should we typically choose a different vehicle for stream processing from 
>> large files, over using transducers? My current use case is 
>> stream-processing from large files.
> Stream processing is just another means of producing values. The question is 
> really in how you represent the stream. Seqs have some inherent overhead. 
> Presumably you don't want to read the entire stream and put it in a 
> collection. The trick then is to create an object that is reducible, not a 
> seq, and reads the stream. Probably the easiest way is to use something 
> Iterable that can provide an iterator over the stream. The CollReduce 
> protocol is extended to Iterable so this is already built in. Then 
> reduce/transduce over the iterable.
> 
> An eduction combines a reducible collection and a transformation (transducer) 
> into a collection that delays its execution until the point where you reduce 
> it (this has some of the same utility as a lazy sequence in delaying 
> execution). 
> 
> How exactly you want to iterate over reading the stream depends on what 
> you're doing (Java provides streams, readers, and channels for a variety of 
> different use cases). In any case you want to have an Iterator implementation 
> (hasNext() and next()) that can provide the "next" item. Things like Apache 
> Commons IOUtils can give you line iterators over a reader for example. 
> -- 
> 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: Map Keywords are functions, why not vector elements?

2017-11-14 Thread Gary Verhaegen
If you're going to call that for multiple elements of the same vector, it's
worth thinking about doing some work upfront so that each look-up is faster:

(defn indices [vect]
  (->> vect
   (map-indexed vector)
   (reduce (fn [acc [idx el]]
 (update acc el (fnil conj []) idx))
   {})))
(indices [1 "is" 1 :same]){1 [0 2], "is" [1], :same [3]}


would walk through the vector only once and create a map of value -> list
of indices.

On 14 November 2017 at 05:49, Sean Corfield  wrote:

> I don’t think anyone addressed your question about finding all the indices
> in a vector where the element matches a given search value?
>
>
>
> There are a number of ways to tackle that (given it’s going to be a linear
> search). Since you want the indices, you are either going to need to track
> them directly or use map-indexed to produce them automatically.
>
>
>
> (defn indices [x l] ; produces a vector
>
>   (loop [i 0 l l r []]
>
> (if (seq l)
>
>   (recur (inc i) (rest l) (if (= x (first l)) (conj r i) r))
>
>   r)))
>
>
>
> (defn indices [x l] ; produces a lazy sequence
>
>   (keep identity (map-indexed (fn [i v] (when (= x v) i)) l)))
>
>
>
> (defn indices [x l] ; produces a vector
>
>   (transduce (comp (map-indexed vector)
>
>(filter (comp (partial = x) second))
>
>(map first))
>
>  conj
>
>  []
>
>  l))
>
>
>
> Hopefully that’ll give you some options to think about…
>
>
>
> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>
> --
> *From:* clojure@googlegroups.com  on behalf of
> Stephen Feyrer 
> *Sent:* Monday, November 13, 2017 5:19:32 PM
> *To:* clojure@googlegroups.com
> *Subject:* Re: Map Keywords are functions, why not vector elements?
>
> Hi Alex, Didier,
>
> Thanks for your patience.
>
> That covers everything which I can think of and a fair bit more :)  I have
> a bit of reading and thinking to do now.
>
> Again, thank you.
>
>
> --
> Rule of thumb simple question, complicated answer
>
> Stephen.
>
> On 13 November 2017 at 22:09, Didier  wrote:
>
>> Yo are looking for indexOf (.indexOf vector value).
>>
>> (.indexOf ["a" "b"] "b")
>> => 1
>>
>> (.indexOf ["a" "b" "b"] "b")
>> => 1
>>
>> Note how indexOf searches for the index of the first value which matches
>> value.
>>
>> To do what you ask, is a query over a vector, which requires a search on
>> each element. This will take O(N) time. For a small list like in your
>> example its probably good enough and not an issue.
>>
>> If you want the name of the horse in a given position, that's a key
>> lookup, which is ~O(1) time. You can use get:
>>
>> (get ["a" "b"] 1)
>> => "b"
>>
>> If you really needed performance, you would need to combine a LinkedList
>> and a map. Some datastructures do it for you under the hood, like Apache
>> LinkedMap, amalloy ordered, java LinkedHashMap, etc.
>>
>> Its possible to also just use sorted-map-by in a closure. But this only
>> works if you're not going to add/update things to the datastructure after
>> first creation.
>>
>> See the example on clojuredocs: https://clojuredocs.org/clojur
>> e.core/sorted-map-by#example-542692d5c026201cdc327094
>>
>> --
>> 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.
>
> --
> You received this message because you are subscribed to the Google
> 

Re: hashmap keys

2017-11-12 Thread Gary Verhaegen
Retrieving a value from a hashmap goes through the following steps:

1) Compute the hashcode of the supplied key.
2) Navigate through the map's internal tree structure to the bucket that
should contain this hashcode (the complexity of this step depends on the
number of different hashcodes stored in the map, not on the complexity of
the key you're searching for).
3) If that bucket is empty, return the provided "missing" value (default:
nil).
4) If the bucket is not empty, for each item in the bucket (all of them
have the same hashcode):
5) Compare for pointer equality; if equal, return the associated value
6) Compare for true equality; if equal, return the associated value
7) Return the provided "missing" value.

So, yes, if you use complex, deeply nested keys _and_ you retrieve the
associated value through using newly-created, value-equal instances of
those keys, it will be a bit slow because you'll have to recompute the
hashcode of the supplied key each time you build it again, and then you'll
still need to traverse the supplied key and the existing copy in the
hashmap for true equality.

In practice, it will most likely be much faster than the worst case because
you will not rebuild the full key from scratch each time, and Clojure value
equality is aware of structural sharing (i.e. if there is a subtree of the
nested keys you're comparing that is actually equal, Clojure will not need
to traverse that part). Due to the way Clojure works with immutable values,
the most likely scenario is that you will have built that key once, and use
the same key (same object in memory) in the hasmap as in the code that
retrieves it; it's also likely that you will have just that one key for
that hashcode value in the map. In that situation, in order to retrieve the
key you just need one hashcode retrieval (it's been cached on first
computation, when you added the key to the map), then one traversal to the
correct bucket (that's typically a O(log32 N) depth), then one pointer
equality check; all of that will be very fast and independent of the
complexity of the key.

Note that the above assumes your keys are Clojure values; if they are
arbitrary Java objects the equality comparison defaults to Java's .equals
so it may be a bit different; also, most Java objects do not cache their
hashcodes.

On 12 November 2017 at 08:35, Jay Porcasi  wrote:

> thank you very much for the clarification
> so no magic there :-)
> using big nested structures as keys is gonna slow down things a bit
>
> but how caching can help?
>
> On Friday, November 10, 2017 at 12:29:41 PM UTC+7, tbc++ wrote:
>>
>> Most Clojure collections cache their hashcode, so that improves things
>> quite bit. Also, very large collections are rarely used as *keys* in other
>> maps. Most of the time key collections are one or two values. This means
>> that what we're really talking about is combining the hash values of a few
>> values, and that's pretty fast.
>>
>> So sure, the initial hash of one million symbols inside a vector may take
>> a fair amount of time, but I've never seen that in the wild.
>>
>> Timothy
>>
>>
>> --
> 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: difference between first & peek; rest & pop

2017-11-10 Thread Gary Verhaegen
Using a dynamic language doesn't mean you should not think in terms of
(abstract) types; it only means that you're note relying on the compiler to
check types for you. If anything, that should encourage you to be more
disciplined in your thought processes (as you don't have anything else to
rely on).

first, rest, next and conj are part of the sequence abstraction; use them
when you're logically manipulating a sequence.

peek, pop and conj can be part of either the stack abstraction (if used on
lists or vectors) or the queue abstraction (if used on persistent queues).

Because Clojure is highly polymorphic, some names, like conj, can be (and
are) reused across abstractions, because they have very similar meanings
(e.g. "add something" for conj). You still have to know what context you're
using them in in order to understand exactly what they're going to do (e.g.
conj on a vector or on a seq across the same vector will not do the same
thing).

On 10 November 2017 at 12:49, Justin Smith  wrote:

> first and rest are defined in terms of position, and work on anything that
> can be treated as an ordered collection
>
> peek and pop work in terms of "natural insertion order" and only work with
> things that behave like a stack - (so not lazy-seqs, strings, etc.)
>
> lists push and pop from the front, vectors push and pop from the end,
> queues push to one end, pop from the other
>
> On Thu, Nov 9, 2017 at 6:06 PM Ethan Brooks 
> wrote:
>
>> Also, pop throws an exception on the empty list whereas rest returns ().
>>
>> On Thursday, May 30, 2013 at 12:43:14 AM UTC-4, Seven Hong wrote:
>>>
>>> Hi all,
>>>
>>> Could some one explain what's the difference between first and peek,
>>> rest and pop? For me it looks like they behave exactly same on sequences..
>>>
>>> Thanks!
>>>
>>> Best,
>>>
>>> Seven Hong
>>>
>> --
>> 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.
>

-- 
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: (resolve (symbol f)) works at the REPL but not in an uberjar

2017-10-13 Thread Gary Verhaegen
>From the description of your problem, it's not really clear to me why you
insist on using strings. Why not use the functions directly? Functions can
serve as keys in maps. Granted, it's a bit ugly to print. You could also
build a map of string to function yourself. Not sure what the performance
of that would be compared to going through resolve every time; I would bet
on "faster" but without much confidence.

On Friday, 13 October 2017,  wrote:

> Is there a way I can avoid hard-coding " "denormalize.pull-from-mysql"" ?
> I guess it doesn't matter, but it does seem a little inelegant.
>
>
> On Thursday, October 12, 2017 at 9:54:36 PM UTC-4, Justin Smith wrote:
>>
>> you can use (symbol "denormalize.pull-from-mysql" "f") instead
>>
>> On Thu, Oct 12, 2017 at 6:34 PM  wrote:
>>
>>> Nevermind. I found that this works, though I think it is ugly and
>>> inelegant:
>>>
>>>  resolved-f (resolve (symbol (str "denormalize.pull-from-mysql/"
>>> f)))
>>>
>>>
>>> On Thursday, October 12, 2017 at 9:27:06 PM UTC-4, lawrence...@gmail.com
>>> wrote:

 At the REPL, this works perfectly:

  > (defn get-users [] [:susan :kwan])
  >
  > (defn what-is-this-function [f] ((resolve (symbol f

  > (what-is-this-function "get-users")
  >[:susan :kwan]

 In an uberjar this does not work. I read somewhere that the runtime
 name-space is different than the REPL namespace and different from the
 namespace that exists while the compiler compiles the code.

 So how do I resolve the symbol correctly?

 I have functions that call a MySQL database, and each function is named
 after a database table. Most of the mechanics of the call are the same, the
 only thing different is the SQL. So I have functions such as "company" and
 "user" and "product". I also have a function called (select). I call select
 with one of the other functions, given as a string:

 (select "product")

 Inside of (select) I need to turn "product" into a resolved symbol that
 I can call.

 Afterwards, I store the results in a map in an atom. I want to use the
 database names as the keys. So "product" should be the key that holds the
 results of the function "product".

 But what I need to do to correctly resolve the string to a function?





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

-- 
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: Is there a better way to get to `Classname[].class` ?

2017-10-10 Thread Gary Verhaegen
What Alex suggested is probably the best approach here. Note: there's a typo in 
my message, the name of the class needs to be as Alex says for the type hint 
too, i.e. the L and ; are essential for this to work.

> On 9 Oct 2017, at 18:31, pericles macedo <periclesmac...@gmail.com> wrote:
> 
> Hey Gary, thanks for the help
> I'm not sure if a type hint would work in this case, as the attribute expect 
> a class literal, and not a variable of that specific class. Thanks for the 
> example though, I didn't know that was a valid type hint.
> About what I'm trying to do, I'm using a gitlab api gem 
> (https://github.com/timols/java-gitlab-api), and I need to do some java 
> interop with it.
> I'm trying to get a list of projects filtered by name, but the call java does 
> doesn't build the search attribute, so I just get all projects, not filtered 
> by name.
> I'm able to get on java by using something like 
> `connection.retrieve().getAll(buildUrl(project), GitlabProject[].class);`. 
> The getAll expects a string, and a class literal.
> If the return from gitlab wasn't an array, I could just use GitlabProject on 
> clojure, and that would give me a result. As it's an array, I get an error 
> showing it can't build a GitlabProject out of ARRAY_START.
> 
> My solution to make that call was 
> (def get-project  
>  
> (memoize  
> 
>   (fn [project]   
>
> (-> connection
>
> .retrieve 
>   
> (.getAll (build-url project) (array-class-for 
> GitlabProject)) 
>   
>
> (defn array-class-for [class-name]
>     
>   (class (make-array class-name 1)))
> 
> 
> 
>> On Monday, October 9, 2017 at 9:20:37 AM UTC-7, Gary Verhaegen wrote:
>> You can generally use ^"[fully.qualified.ClassName" as the type hint, if 
>> that's what you're trying to do. I'm not quite sure of the benefits of 
>> typing an array when it's not a primitive one, though.
>> 
>> What are you trying to accomplish, if we zoom back a little bit? Maybe 
>> there's a better way to do whatever you're trying to do.
>> 
>>> On 9 Oct 2017, at 16:36, pericles macedo <pericle...@gmail.com> wrote:
>>> 
>>> Hey Guys,
>>> I wanted to know if there is a better way to get to the same result as 
>>> `GitlabProject[].class`
>>> after some digging around, I got to this array of class definition by doing 
>>> something like `(class (make-array GitlabProject 1))`. But I don't know if 
>>> there is a better way to get to this same result. 
>>> In Java, this array of class is sent as an attribute that is used to build 
>>> the array of objects that is returned. like: `retrieve().getAll(tailUrl, 
>>> GitlabProject[].class);`
>>> 
>>> 
>>> Thanks for your time,
>>> Pericles Dantas
>>> -- 
>>> 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/cloj

Re: Help with strange test output when deftest used inside a macro

2017-10-10 Thread Gary Verhaegen
is is looking for specific patterns and, if it can't find a known one, defaults 
to assuming its argument is a random predicate and prints that.

So what's happening here is the syntax quote expands (resolves) = to 
clojure.core/= and thus it doesn't match the pattern for = anymore.

So you'd need for = to not be expanded and stay as exactly the = symbol after 
macroexpansion. There are various ways to achieve that, but I can't think of a 
generic, elegant one. In the trivial example you posted you can just replace = 
with ~'=, I think, though that might not be so easy on more complex macros.

You can also take a look at the assert-expr and report multimethods in 
clojure.test.

> On 9 Oct 2017, at 22:32, Timothy Baldridge  wrote:
> 
> The problem isn't the macro, it's your use of syntax quoting. `(= x y) gets 
> expanded at read-time into `(clojure.core/= x y)`. Not much you can do about 
> that. Although I'd suggest perhaps changing your code a bit to not require 
> macros. 
> 
> deftest mostly just creates a defn with some extra metadata and the like. One 
> option would be to use a dynamic var to setup your config information. Or 
> better yet have the test itself read the config data the way your normal app 
> would. This not only exercises the same config codepaths, but it also keeps 
> the code quite functional. 
> 
>> On Mon, Oct 9, 2017 at 2:40 PM, Matt Grimm  wrote:
>> Hello,
>> 
>> I'm generating deftest's using a helper macro that takes a variety of test 
>> parameters and though the tests function correctly, the output of a failed 
>> test is not exactly right. The expect value is shown as the un-evaluated 
>> test form, and the actual value is shown as the result of evaluating the 
>> test form. I realize 'is' is a macro itself, but I'm not quite sure how to 
>> expand or escape the guts of my macro to make the output match that of a 
>> normal test.
>> 
>> Whereas a normal test failure looks like this (some output elided):
>> 
>> user=> (deftest normal-test
>>   #_=>   (is (= [0 1 5] (range 3
>> #'user/normal-test
>> user=> (run-tests)
>> 
>> FAIL in (normal-test)
>> 
>> expected: [0 1 5]
>>   actual: ((0 1 2))
>> 
>> A failure for a deftest defined within a macro comes out like this:
>> 
>> user=> (defmacro defnesttest [v]
>>   #_=>   `(deftest nested-test
>>   #_=>  (is (= [0 1 5] ~v
>> #'user/defnesttest
>> user=> (defnesttest (range 3))
>> #'user/nested-test
>> user=> (run-tests)
>> 
>> FAIL in (nested-test)
>> 
>> expected: (clojure.core/= [0 1 5] (range 3))
>>   actual: false
>> 
>> Thanks for any insight,
>> m.
>> -- 
>> 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.
> 
> 
> 
> -- 
> “One of the main causes of the fall of the Roman Empire was that–lacking 
> zero–they had no way to indicate successful termination of their C programs.”
> (Robert Firth)
> -- 
> 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: Is there a better way to get to `Classname[].class` ?

2017-10-09 Thread Gary Verhaegen
You can generally use ^"[fully.qualified.ClassName" as the type hint, if that's 
what you're trying to do. I'm not quite sure of the benefits of typing an array 
when it's not a primitive one, though.

What are you trying to accomplish, if we zoom back a little bit? Maybe there's 
a better way to do whatever you're trying to do.

> On 9 Oct 2017, at 16:36, pericles macedo  wrote:
> 
> Hey Guys,
> I wanted to know if there is a better way to get to the same result as 
> `GitlabProject[].class`
> after some digging around, I got to this array of class definition by doing 
> something like `(class (make-array GitlabProject 1))`. But I don't know if 
> there is a better way to get to this same result. 
> In Java, this array of class is sent as an attribute that is used to build 
> the array of objects that is returned. like: `retrieve().getAll(tailUrl, 
> GitlabProject[].class);`
> 
> 
> Thanks for your time,
> Pericles Dantas
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread Gary Verhaegen
Not easy to be positive without more information about your code base, but
the only times I had symptoms that resemble what you describe, the problem
was that the JVM died before printing. That is, you have multiple threads,
and printing is asynchronous at many levels (even the terminal itself
buffers stuff). If the app dies in that condition it's actually fairly
common that messages aren't visible, even though the statement and
sometimes a few next ones have indeed run. Nothing to do with Timbre as far
as I can tell.

Maybe try to give your app a bit more wall-clock time between the error and
killing the process? (Note: I don't think you can do that by sleeping in
the shutdownhook as the JVM will not necessarily wait on that one.)

On Monday, 9 October 2017, Shantanu Kumar  wrote:

>
>
> On Monday, 9 October 2017 12:34:41 UTC+5:30, lawrence...@gmail.com
>  wrote:
>>
>> Shantanu Kumar, thanks for that, I might try it. I assume you've never
>> had the problem I'm talking about, of messages on background threads that
>> disappear?
>>
>
> Logback (the SLF4j impl we use) is capable of logging from multiple
> threads. I always set the default uncaught handler to log any exception
> arising from background threads:
> https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#
> setDefaultUncaughtExceptionHandler(java.lang.Thread.
> UncaughtExceptionHandler)
>
> Stuart Sierra also wrote about how to do this: https://stuartsierra.
> com/2015/05/27/clojure-uncaught-exceptions
>
> If you do this step correctly, you might be able to notice the
> background-thread exceptions even with a plain `println` call.
>
>
> Shantanu
>
>
>>
>>
>> On Monday, October 9, 2017 at 2:56:24 AM UTC-4, Shantanu Kumar wrote:
>>>
>>>

 I'm curious what others do for logging?

>>>
>>> At Concur we using Cambium https://github.com/kumarshantanu/cambium
>>> that's being moved (WIP) here: https://github.com/cambium-clojure
>>>
>>> Cambium wraps SLF4j and gives a Clojure API (which extends
>>> tools.logging) to use it's MDC feature.
>>>
>>>
>>> Shantanu
>>>
 --
> 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: How to try/catch Let bindings?

2017-10-08 Thread Gary Verhaegen
As others have noted, this is pretty much what monads are made for. I've
found Brian Marick's "Functional Programming for the Object-Oriented
Programmer"'s chapter on monads really good at teaching how to recognize
situations where monads would be a good fit.

For this specific use-case, you can probably, as an intermediate solution,
define a fairly simple macro that would get you almost all you want,
something like:

(defmacro mlet
  [bindings & body]
  (if (seq bindings)
(let [[b expr & r] bindings]
  `(try (let [~b ~expr]
  (mlet ~r ~@body))
(catch Exception e#
  (let [~b [:mlet/error e#]]
(let ~(->> r
   (partition 2)
   (mapcat (fn [[b _]] [b :mlet/unbound]))
   vec)
  ~@body)
`(do ~@body)))
(mlet [a (+ 1 2)
   b (- a 3)
   c (/ 10 b)
   d (inc c)]
  [a b c d]);; => [3 0 [:mlet/error #error {#_elided}] :mlet/unbound]

Depending on how much complexity you're willing to bear within that macro,
you could do smarter things like detecting which variables can still be
computed, etc.

Maybe also take a look at prismatic graph?
https://github.com/plumatic/plumbing

-- 
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: ref strange behavior

2017-08-28 Thread Gary Verhaegen
I wasn't satisfied with the various answers to both this thread and
the StackOverflow question, so I spent a bit more time digging; it
turns out this was a bug in the range implementation that was fixed in
1.9.0-alpha11. I've added a bit more details on StackOverflow [1]; the
full story is on the ticket [2].

[1] 
https://stackoverflow.com/questions/39054911/strange-behavior-of-clojure-ref/45919119#45919119
[2] https://dev.clojure.org/jira/browse/CLJ-1914

On 23 August 2016 at 13:09, Sergei Koledov  wrote:
> Hello,
>
> I had a problem when I run the following code:
>
> (defn get-task [tasks]
>   (dosync
> (let [task (first @tasks)]
>   (alter tasks rest)
>   task)))
>
> (defn worker [& {:keys [tasks]}]
>   (agent {:tasks tasks}))
>
> (defn worker-loop [{:keys [tasks] :as state}]
>   (loop [last-task nil]
> (if-let [task (get-task tasks)]
>   (recur task)
>   (locking :out (println "Last task: " last-task
>   state)
>
> (defn create-workers [count & options]
>   (->> (range 0 count)
>(map (fn [_] (apply worker options)))
>(into [])))
>
> (defn start-workers [workers]
>   (doseq [worker workers] (send-off worker worker-loop)))
>
> (def tasks (ref (range 1 1000)))
>
> (def workers (create-workers 100 :tasks tasks))
>
> (start-workers workers)
> (apply await workers)
>
> Description: I have several agents (100 in my case). Each agent running in a
> separate thread. All agents share the one ref with the collection of tasks
> (range of longs in my case). Each agent get tasks from the collection (in
> transaction) one by one until the collection becomes empty and then prints
> the last task which it handle. However, when I run this code it looks like
> the collection of tasks suddenly becomes empty and workers handle only
> portion of all tasks (average 25-40% of all number).
>
> This code behave as I expected, when I create only one agent or use explicit
> locking in get-task function:
>
> (defn get-task [tasks]
>   (locking :lock
> (dosync
> (let [task (first @tasks)]
>   (alter tasks rest)
>   task
>
> I run this code on the Clojure 1.8.0
> java version "1.8.0_91"
> Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
> Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
>
> Can anyone tell me, what am I doing wrong, or it really looks like a bug in
> the clojure STM?
> I already asked this question on stackoverflow.com
> (http://stackoverflow.com/questions/39054911/strange-behavior-of-clojure-ref),
> but so far nobody has been able to help me.
>
> P.S. Sorry for my english skill.
>
> --
> 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: Joy of Clojure : Backward running lisp ??

2016-06-23 Thread Gary Verhaegen
In functional programming, you work with functions. Functions have a
well-defined list of inputs and a single output. So you can say of the
function cons, for example, that it takes as input a value and a list,
and yields as output a new list with the value prepended to the given
list; for example (cons 1 '(3 4)) would yield the value '(1 3 4).

In logic (sometimes called relational) programming, you work with
relations. A relation defines some link between multiple values. The
equivalent example to the above, usually denoted "conso" in the
Clojure world (and something like cons° in miniKanren, I think) would
be a relation of three values: (conso a b c). The more mathematical
interpretation would be "conso is true for any three values a, b, c
such that c is a list of at least one element, a is the first element
of c and b is a list of all elements of c except the first, in the
same order". In practical terms, a logic engine like miniKanren will
allow you to supply real values for some of the arguments and let the
others be free, and will return example values for which the relation
holds.

For example, (conso 1 '(3 4) c) would return something that says "c
must be '(3 4)". In this case, by analogy to the functional version,
we say we are running the relation "forward", i.e. in the same
direction as the function. But you can also ask a logic engine for
"(conso a b '(1 3 4))", and it will reply with something like "a
should be 1, b should be '(3 4)", and, again, by analogy with the
functional equivalent, we would say you are running the "function"
backwards. In terms of relational programming, in either case you're
just applying the relation, but most people who hear about relational
programming are more familiar with functions (or procedures) and will
relate to the notion that the "natural", i.e. "forward" way of running
conso is to supply the first two arguments and expect the engine to
supply values for the third, rather than the other way around.

Note that you could also ask a logic engine for "(conso 1 b '(1 3
4))", and it should respond with "b should be '(3 4)", which is
running it middleward, I guess. It's harder to relate to functions
when you have more than one "input", as logic programming would let
you specify any subset of them. Relations can also fail, such as if
you ask for "(conso 1 b '(3 4 5))"; in that case the logic engine,
depending on the robustness of its own implementation and the
definition of conso, would either enter an infinite loop trying to
find a value for which this holds or just respond with "there is no
value for b that makes this relation hold".

conso is a simple example in that it is bijective. If you instead
consider a concat function, such that (concat l1 l2), where l1 and l2
are lists, would yield a new list l3 with first all of the elements of
l1 then all of the elements of l2, then you can get a more interesting
equivalent relation ("concato"?).

Let's imagine you define (concato l1 l2 l3) to be true if l3 = (concat
l1 l2) (you cannot just state it like that to the logic engine). Then,
if you ask your logic engine about the relation (concato a b '(1 2
3)), it would respond with "Here are some possible values for a and b:
a = '(), b = '(1 2 3); a = '(1), b = '(2 3); a = '(1 2), b = '(3); a =
'(1 2 3), b = '()".

What Byrd and Friedman have been working on for some time now is the
(research) question of "can we write a relation that defines a Lisp
interpreter?", where a Lisp interpreter is thought of as the function
eval, essentially. So if (eval '(+ 1 2)) would yield 3, can you define
a relation evalo, within the constraints of their specific logic
engine ({mini,alpha}Kanren), that mimics that behaviour when run
"forward" (i.e. given the first argument as a value and the second one
as a free-floating logic variable) and also works "backwards" (i.e.
given the first argument as a free-floating variable and the second
one as a value).

So they would define (evalo a b) such that it is satisfied iff (eval
a) yields b (though again you cannot tell it that simply to your logic
engine, hence the research part); this means that for example (evalo
'(+ 1 2) 3) would be satisfied, (evalo '(+ 1 2) 4) would not be
satisfied, (evalo '(+ 1 2) a) would return something like "this can be
satisfied if a = 3" (forward), and (evalo a 3) (i.e. "backward with
respect to the equivalent function) would return something along the
lines of "There are a bunch of programs that can evaluate to 3. Here
are a few of them: '(+ 0 3), '(+ 1 2), '(+ 2 1), '(- 4 1), '((fn []
3)), ..."

Their last question is a bit tricky: what program, when evaluated,
yields itself? This is the notion of a quine, and quines are pretty
hard to generate for humans (apart from the simple self-evaluating
values, of course). An example quine in Clojure, which I just stole
from 
http://programming-puzzler.blogspot.co.uk/2012/11/clojure-makes-quines-way-too-easy.html,
would be:

((fn [x] (list x (list (quote quote) x))) (quote 

Re: Access user created Java package from Clojure

2016-06-01 Thread Gary Verhaegen
As long as you're working purely in Clojure, Leiningen mostly protects you
from having to know about the JVM and its infamous classpath. But when
you're trying to interoperate with Java code, you need to know a few things.

So, here's the very minimum I think you need to know to understand what is
happening here. When you start a JVM, it has a notion of a classpath. This
can come from your environment variables, but usually does not, especially
when your code is started by Leiningen, so printing out your $CLASSPATH
variable would not help you there. There is a `lein classpath` command that
can help you see what's happening.

The classpath is a series of locations (mostly directories, but also often
JAR files) in which the JVM is going to look for code. When you give a
fully-qualified Java class name, the JVM will look for the equivalent path
into every directory of the classpath. So if your classpath is
/dir1:/dir2/code, for example, and your code is referencing
my.package.MyClass, the JVM will look for /dir1/my/package/MyClass.class,
and if that does not exist, it will then look for
/dir2/code/my/package/MyClass.class.

Where your files are on your disk does not matter; what matters is where
they are relative to your classpath root folders.

Note that your home directory is *not* in your $CLASSPATH in your example
(the current directory is).

Now, as to accessing these from Clojure:

$ cd $(mktemp -d)
$ lein new app t
Generating a project called t based on the 'app' template.
$ cd t
$ vim project.clj
$ vim src/MyClass.java
$ cat project.clj(defproject t "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME;
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]]
  :main ^:skip-aot t.core
  :target-path "target/%s"
  :java-source-paths ["src"]
  :profiles {:uberjar {:aot :all}})
$ cat src/MyClass.java
public class MyClass {
public static void hello() {
System.out.println("hello");
}}
$ vim src/t/core.clj
$ cat src/t/core.clj(ns t.core
  (:import [MyClass])
  (:gen-class))
(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (MyClass/hello))
$ lein run
Compiling 1 source files to target/base+system+user+dev/classes
hello
$ tree target
target
├── base+system+user+dev
│   ├── classes
│   │   ├── META-INF
│   │   │   └── maven
│   │   │   └── t
│   │   │   └── t
│   │   │   └── pom.properties
│   │   └── MyClass.class
│   └── stale
│   └── leiningen.core.classpath.extract-native-dependencies
├── base+system+user+dev+b9e56754
│   └── stale
│   └── leiningen.core.classpath.extract-native-dependencies
└── base+system+user+dev+offline
└── stale
└── leiningen.core.classpath.extract-native-dependencies

11 directories, 5 files
$ lein classpath
test:src:dev-resources:resources:target/base+system+user+dev/classes:~/.m2/repository/cider/cider-nrepl/0.10.2/cider-nrepl-0.10.2.jar:~/.m2/repository/org/tcrawley/dynapath/0.2.3/dynapath-0.2.3.jar:~/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar:~/.m2/repository/org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar:~/.m2/repository/clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar
$


In this case, Leiningen is arranging for the MyClass.java file to be
compiled to MyClass.class, and for the result to be available in the
classpath of the running Clojure program. So, really, all you have to do to
access your Java code from Clojure is make sure it is on the classpath and
import it. One easy way to put existing, compiled .class files in the
classpath generated from Leiningen is to put them in resources, though it
would be better to either have the Java code as part of the project (in
:java-source-paths) or to package it as a Maven dependency.

I should mention, though, that using the default package (i.e. no package
declaration, i.e. having your java code directly at one of the roots of the
classpath) like that is generally considered bad form, as much in Java as
in Clojure, partly due to the risk of name clashes and partly because some
tooling just does not support it.

So, in summary:

1) Yes, as long as the .class files are on your classpath. You can also
call (import '[MyClass]) from the REPL if you are not running code from a
namespace.
2) It does not matter where on your disk these files are; your current
import statement is correct for any XXX/pirate_phrases/ directory as long
as XXX itself is on the classpath.


Hope that helped.

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

Re: Puzzle solving in Clojure

2016-04-12 Thread Gary Verhaegen
On 12 April 2016 at 14:58, Cornelius Goh  wrote:

> True. Clojure doesn't provide tail call optimization. According to Daniel
> Higginbotham  book "Clojure for the Brave and True" (Page 102) he suggests
> using "recur" for performance reasons.
>
> That is, in Olivier's original code, (sorry, without understanding his
> puzzle):
>
>
> (defn  permutations [s]
>(lazy-seq
>...
>...
>   (map # (...) (recur (remove #...)
> ...
>
> See if it improves performance by just using "recur" ?


But you can't do that, because you're using the return value there
(specifically, as the argument to map). If you try it, you'll see that the
compiler throws an error.

The idea behind tail call elimination is that, if the very last thing that
your function, say fnA, does is returning the result of a call to another
function, say fnB, then you do not need the stack frame of fnA during the
call to fnB, and you can preemptively pop it before calling fnB. But this
only works if calling fnB is the very last thing that fnA does: if fnA
still has some work to do with the result of fnB, its stack cannot be
destroyed. (You could argue that a sufficiently smart compiler could "trim"
the stack to just what will be needed after the call to fnB, but it's not
the same.)

A simple, well-known example is the case of the recursive factorial
function:

(defn non-tce-fact
  [n]
  (if (zero? n)
1
(* n (non-tce-fact (dec n)
(defn tce-fact
  ([n] (tce-fact n 1))
  ([n p]
(if (zero? n)
  p
  (recur (dec n) (* n p)


Note that in the first function, the result of the recursive call is used
in the multiplication, whereas in the second function the result is
directly the result of the recursive call.

Most common examples are of recursive functions, but TCE is (in principle)
a general technique that can be applied to any function whose last
instruction is a call to another function.

In Clojure, only recursive tail call elimination is supported, and only
when the programmer explicitly requires it by using recur instead of an
explicit recursive call. This has the advantage (and disadvantage) of being
explicit and checked by the compiler (i.e. if you use recur in a non-tail
position, you get an error).

-- 
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: Attempt At Futures

2016-04-09 Thread Gary Verhaegen
You could:

* Create all futures *without* deref'ing them, so they all start in
parallel;
* Loop through the futures, asking them if they have finished, and print
those that have (and remove them from the list)

But if you want to get each result as it comes back, it's probably a better
fit for core.async than plain futures. I would suggest creating a channel
with multiple producers and a single consumer, where each producer gets a
site and the consumer prints the result. That way, you get the results as
they come.

Here is a rough draft:

(ns cjr-http-test.core
  (:require [clj-http.client :as client]
[clojure.core.async :as async :refer [!!]]))
(defn get-heads
  [sites]
  (mapv (fn [site] (future {:head (client/head site)
:url site}))
sites))
(def sites ["http://www.google.com;
"http://www.yahoo.com;
"http://www.bing.com;])
(defn use-futures
  []
  (let [head-requests (get-heads sites)]
(loop [to-check head-requests checked []]
  (cond (and (empty? checked) (empty? to-check))
:finished

(empty? to-check)
(recur checked [])

(realized? (first to-check))
(do (-> to-check first deref :url println)
(recur (rest to-check) checked))

:else (recur (rest to-check) (cons (first to-check) checked))
(defn use-async
  []
  (let [ch (async/chan)
producers (mapv (fn [site]
  (doto (Thread. #(>!! ch {:head (client/head site)
   :url site}))
(.start)))
sites)
close-chan (doto (Thread. (fn []
(mapv #(.join %) producers)
(async/close! ch)))
 (.start))]
(loop [v ( v :url println)
(recur (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: Advice getting started with concurrency and parallelism in Clojure

2016-04-07 Thread Gary Verhaegen
The two resources that helped me most with concurrency and parallelism
are "Java Concurrency in Practice" and "ZeroMQ — The Guide".
Introductory Go books are also enlightening.

Once you have a clear understanding of the underlying concepts in
general, understanding how they are accessible in Clojure is really
just about knowing what is available in the standard library. Remember
that that includes all of Java, too. Also keep in mind that a
0-argument Clojure fn is a java.lang.Runnable and a
java.util.concurrent.Callable.

Here's an example of using an atom with multiple threads:

(def counter (atom 0))

(let [threads (repeatedly 10 (fn [] (Thread.
  #(dotimes [_ 100] (swap! counter inc)]
  (->> threads
   (map #(.start %))
   doall)
  (->> threads
   (map #(.join %))
   doall)
  (println @counter))

The point of the atom should be slightly clearer: it is indeed a
"mutable value" (we don't really use these two words together in
Clojure; things are either "mutable reference" or "immutable value")
like in any other language, except that you can change it from
multiple threads without any problem, because the updates are atomic —
hence the name.

The above code is using bare Java threads, which is not very
idiomatic. Usually, there are better options within Clojure itself
(for this simple example, using future instead of bare threads would
yield slightly more compact code), but it's hard to know which one to
suggest without more information on your use-case.

You basically have two ways of coordinating threads: message-passing
or shared memory. The point of atoms is to support a safe way to share
memory between threads, by providing a reference to a (supposedly)
immutable value. If you're more of the message-passing inclination,
you can use core.async channels and >!! (blocking put) and  wrote:
> The biggest problem with pmap I have is ordering, ie. it will process in
> batches of (+ 2 (.. Runtime getRuntime availableProcessors)), and only take
> a new batch when the slowest of the old batch has been evaluated. With
> functions dependent on IO, parallel gains are only a fraction of what they
> could be. I used to solve this by creating my own code to process in futures
> and delays, but when I found the claypoole library, especially it's
> unordered pmap and for, I never had to touch these again.
>
> On Wednesday, April 6, 2016 at 3:11:52 PM UTC+2, Mars0i wrote:
>>
>> Maybe people forget about pmap, pcalls, and pvalues because they're just
>> too easy.
>>
>> On Tuesday, April 5, 2016 at 8:51:59 PM UTC-5, tbc++ wrote:
>>>
>>> If it all seems confusing, do not despair, there's two things that will
>>> handle the vast majority of the use cases you may have:
>>>
>>> 1) `future` - spawns a thread that runs the body of the future
>>> (https://clojuredocs.org/clojure.core/future)
>>> 2) `atom` and `swap!` - Used to store data that needs to be shared
>>> between threads and updated concurrently
>>> (https://clojuredocs.org/clojure.core/atom) these are built on top of CAS,
>>> which itself is foundation upon which most of concurrent programming is
>>> built. (https://en.wikipedia.org/wiki/Compare-and-swap)
>>>
>>> Those two primitives alone will handle 90% of the use cases you will run
>>> into as a new clojure developer. The rest of the stuff (agents, thread
>>> pools, refs, vars, cps/core.async) can all come in time, but you will use
>>> them much less often than threads and atoms. So read up on those two and
>>> feel free to come back with any questions you may have.
>>>
>>> Timothy
>>>
>>>
>>> On Tue, Apr 5, 2016 at 7:24 PM, Chris White  wrote:

 I was doing some reading of code recently to help me get up to speed
 with Clojure. One of the libraries I randomly came across dealt with
 parallelism and I had a hard time following along with it. To try and wrap
 my head around things I did a quick search and found this article:


 http://www.thattommyhall.com/2014/02/24/concurrency-and-parallelism-in-clojure/

 I'm not sure how authoritative this is based on my current experience,
 but needless to say I was a bit overwhelmed. That said is there any sort of
 introductory material that list members have used to help get them into how
 Clojure deals with concurrency and parallelism? I also don't mind anything
 that's not specifically using Clojure but will at least help me understand
 the concepts behind how Clojure does it. Thanks again for any and all help!

 - Chris White (@cwgem)

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

Re: I am wondering if there is a better way to validate and read-in clojure data?

2016-03-13 Thread Gary Verhaegen
First off, unless you have a very good reason not to, you know the
differences, and you know what you are doing, always use the "read"
functions from clojure.edn rather than from clojure.core.

When you say "bad data", is it malformed (as in not valid EDN) or is it not
conforming to the expected schema? If the former, you can either rely on
the error reporting of clojure.edn/read-string, or (if you only need to
parse a very limited subset of EDN) write your own parser that reports
errors in a more suitable way for your use-case. Should you decide to go
that way, you may want to look into instaparse. I would advise against
going that way, though, but it's hard to know with the level of details you
have provided about what tou are actually trying to achieve.

If you get valid EDN but not the expected content, there are plenty of
"validation" libraries that may be used for the task; two that directly
come to mind are prismatic schema and validateur (slightly different
use-cases, but, again, you have not really explained what you are trying to
accomplish).

If it is well formed and follows the expected schema, I am not sure how you
can detect that it is not right. Maybe more unit tests?

On Saturday, 12 March 2016, john  wrote:

> I am producing clojure data with XSLT. At first I embraced the result in
> a vector of vectors so that a single (read-string) would read the whole
> structure in one take.
> Unfortunately when the XSLT sheet produces bad data I don't see easily
> what is going wrong.
>
> So is there an alternative for read-string?
>
> This is the code I am using right now. Instead of XSLT outputting a vector
> of vectors I output vectors separated by "@@@"
> -  Code ---
> ;; dependency [clojure-saxon "0.9.4"]
>
> (def xsl-sheet (xml/compile-xslt (java.io.File. "sheet.xsl")))
>
> (defn convert->transactions[[meta-params xml]]
>   (.toString (xsl-sheet (xml/compile-xml xml) meta-params)))
>
> (defn read-in [the-str]
>   (try (map
> #(try (read-string %1)
>   (catch Exception e
> (println "read-in Error:" (.getMessage e)
>  " token: " %1
>  " token-pos" %2
>  )))
>   (str/split the-str #"@@@") (range 10
>
>
> -  Code ---
>
>
> Is there a more elegant way to read-in and get nice errors ?
>
> Many Greetings
>
> John
>
> --
> 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: is there an implementation of GraphQL in Clojure?

2016-03-10 Thread Gary Verhaegen
There is a Java solution in that list at:

https://github.com/andimarek/graphql-java

You could use that directly through interop. If you're feeling
generous, you could even build a Clojure wrapper around it and release that
as open-source.

On Thursday, 10 March 2016,  wrote:

>
> I am looking here:
>
> https://github.com/chentsulin/awesome-graphql
>
> and Clojure is not listed.
>
> Is there anything in Clojure that I can use to offer GraphQL queries to a
> React frontend?
>
> --
> 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: Feedback on idiomatic API design

2016-03-10 Thread Gary Verhaegen
I would suggest a slightly different approach. First, define a record for
your fake server, which implements Closeable; put your current "shutdown"
code in the close method.

This will allow you to use the existing with-open macro, instead of having
to redefine your own, while leaving the option of not using the macro
should the user want that.

Then, define a constructor function for that record, which takes as
argument a map or vector defining your routes, and returns an instance of
the above record. That record should have a :uri property, and encapsulate
the actual server.

Then you can do stuff like:

(with-open [srv (fake-server routes)]
  (http/get (:uri srv) ...)
  ...)

while leaving the option of creating and closing the server manually if it
makes sense for some use-case. You can also easily reuse routes from one
server to another as it is a simple data structure.

On Wednesday, 9 March 2016, Marc Limotte  wrote:

> With the macro approach, they don't need to escape it.
>
> On Wed, Mar 9, 2016 at 12:52 PM, Johan Haleby  > wrote:
>
>> Thanks a lot for your support Marc, really appreciated.
>>
>> On Wed, Mar 9, 2016 at 5:33 PM, Marc Limotte > > wrote:
>>
>>> Yes, I was assuming the HTTP calls happen inside the with-fake-routes! 
>>> block.
>>>
>>> I missed the part about the random port.  I se 3 options for that:
>>>
>>> *Assign a port, rather than random*
>>>
>>> (with-fake-routes!  ...)
>>>
>>>
>>> But then, of course, you have to worry about port already in use.
>>>
>>> *An atom*
>>>
>>> (def the-uri (atom nil))
>>> (with-fake-routes! the-uri
>>>   ...
>>>   (http/get @the-uri "/x"))
>>>
>>> *A macro*
>>>
>>> A common convention in Clojure would be to pass it a symbol (e.g. `uri`
>>> that is bound by the macro), rather implicitly creating `uri`.
>>>
>>> (with-fake-routes! [uri option-server-instance]
>>>
>>> route-map
>>>
>>> (http/get uri "/x"))
>>>
>>>
>> Didn't know about this convention so thanks for the tip. But is your
>> snippet above actually working code or does the user need escape "uri" and "
>> option-server-instance" using a single-quotes, i.e.
>>
>> (with-fake-routes! [*'*uri *'*option-server-instance] ...)
>>
>>
>>>
>>> or, with a pre-defined server
>>>
>>> (def fake-server ...)
>>> (with-fake-routes!
>>>
>>> route-map
>>>
>>> (http/get (:uri fake-server) "/x"))
>>>
>>>
>>> marc
>>>
>>>
>>>
>>> On Wed, Mar 9, 2016 at 1:00 AM, Johan Haleby >> > wrote:
>>>


 On Wed, Mar 9, 2016 at 6:20 AM, Johan Haleby > wrote:

> Thanks for your feedback, exactly what I wanted.
>
> On Tuesday, March 8, 2016 at 3:16:02 PM UTC+1, mlimotte wrote:
>>
>> I don't think you need a macro here.  In any case, I'd avoid using a
>> macro as late as possible.  See how far you get with just functions, and
>> then maybe at the end, add one macro if you absolutely need it to add 
>> just
>> a touch of syntactic sugar.
>>
>> routes should clearly be some sort of data-structure, rather than
>> side-effect setter functions.  Maybe this:
>>
>> (with-fake-routes!
>>   optional-server-instance
>>   route-map)
>>
>>
 Hmm now that I come to think of it I don't see how this would actually
 work unless you also perform the HTTP request from inside the scope of  
 with-fake-routes!,
 otherwise the server instance would be closed before you get the chance
 to make the request. Since you make an actual HTTP request you need
 access to the URI generated when starting the fake-server instance (at
 least if the port is chosen randomly). So either I suppose you would
 have to do like this (which requires a macro?):

 (with-fake-routes!
   {"/x" {:status 200 :content-type "application/json" :body (slurp
 (io/resource "my.json"))}}
   ; Actual HTTP request
   (http/get uri "/x"))

 where "uri" is created by the  with-fake-routes! macro *or* we could
 return the generated fake-server. But if so with-fake-routes! cannot
 automatically close the fake-server instance since we need the
 instance to be alive when we make the call to the generated uri. I suppose
 it would have to look something like this:

 (let [fake-server (with-fake-routes! {"/x" {:status 200 :content-type
 "application/json" :body (slurp (io/resource "my.json"))}})]
 (http/get (:uri fake-server) "/x")
 (shutdown! fake-server))

 If so I think that the second option is unnecessary since then you
 might just go with:

 (with-fake-routes!
   *required*-server-instance
   route-map)

 instead 

Re: [ANN] CIDER 0.11 Released!

2016-03-03 Thread Gary Verhaegen
Thanks Bozhidar!

On Thursday, 3 March 2016, Leon Grapenthin  wrote:

> Congratulations. Cider is really awesome!
>
> On Thursday, March 3, 2016 at 6:42:48 AM UTC+1, Bozhidar Batsov wrote:
>>
>> Hey everyone,
>>
>> CIDER 0.11 (a.k.a. Bulgaria) is finally out!
>>
>> Today Bulgarians (like me) celebrate the country's Liberation Day and the
>> rest of the
>> world will get to celebrate the release of CIDER 0.11. :-)
>>
>> Once again we've got a ton of new features, refinements and bugfixes and
>> I hope you're going to love them!
>>
>> The changelog is here
>> https://github.com/clojure-emacs/cider/releases/tag/v0.11.0
>>
>> Enjoy!
>>
>> --
> 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 as first language

2016-02-26 Thread Gary Verhaegen
On Friday, 26 February 2016, Terje Dahl  wrote:

> Lee.
>
> About the confusion with parens - do you mean that an output-ed list/seq
> looks exactly like a callable s-expression?
> Please elaborate.
>
> Terje
>

Yes. If you print the list (1 2 3) it prints as a callable form, and then
you have to get into reading, evaluation, etc.

Aphyr's Clojure tutorial series went there. IIRC the second or third
chapter was devoted to that.

On the other hand, in the Racket curriculum, they define limited subsets of
Scheme used as teaching languages; when the student first learns about
lists, they construct them using cons and they print as cons forms, i.e.
the (in-memory) list '(1 2) would print as

(cons 1 (cons 2 (cons (

This is the kind of simplifications that are done in the teaching languages
and that allow the course to avoid a number of advanced topics in the
beginning. It avoids a lot of confusion at the cost of a small lie and an
extra effort when you want to introduce macros and the "code is data" idea.
(Which you usually don't want to do in an introductory course anyway.)

For a short (and, I found, very enlightening) peek at the HTDP curriculum,
you can skim through the Systematic Program Design course by Gregor
Kiczales on edX:

https://www.edx.org/xseries/how-code-systematic-program-design

This is by a wide margin the best introductory programming course I have
ever seen.

Re: ClojureBridge, the curriculum is on GitHub:

https://github.com/ClojureBridge/curriculum

-- 
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: ExceptionInInitialization error

2016-02-25 Thread Gary Verhaegen
The lein deps :tree message (on stderr, which may be why it was not
included in your mail?) said:


Possibly confusing dependencies found:
[cheshire "5.3.1"]
 overrides
[riemann "0.2.10"] -> [clj-http "1.1.2" :exclusions
[org.clojure/tools.reader]] -> [chesh
ire "5.4.0" :exclusions [org.clojure/clojure]]
 and
[riemann "0.2.10"] -> [cheshire "5.5.0"]

Which means: "In your project.clj file, you explicitly tell me that you
want cheshire 5.3.1, but you also tell me that you want riemann 0.2.10. It
turns out that riemann tells me it wants clj-http 1.1.2, which itself wants
cheshire 5.4.0. In addition, riemann also tells me that it wants cheshire
5.5.0. Now, you're the boss, and I can't load multiple versions of the same
library, so I'm going to guess that you really want cheshire 5.3.1 and not
one of the other ones, though I must say I am a bit confused.

I'm also a bit shy, so if this is really what you want, could you please
tell riemann that you do not want him to give me orders regarding the
version of cheshire to be included? That would make things less confusing."

so you have to choose: either follow Leiningen's advice and tell riemann to
shut up, or decide that you don't actually need to insist on that specific
version of cheshire and give riemann what it needs.

What Leiningen suggests (putting in exclusions) is a way of making explicit
the choices that he is already guessing from your project.clj, so in this
case it does not help.

-- 
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: ExceptionInInitialization error

2016-02-24 Thread Gary Verhaegen
So when I do `lein deps :tree` with these dependencies (except for the
swissknife one, which my computer does not seem to find), I get a
*lot* of conflicts with riemann, starting with:

$ lein deps :tree
Possibly confusing dependencies found:
[cheshire "5.3.1"]
 overrides
[riemann "0.2.10"] -> [clj-http "1.1.2" :exclusions
[org.clojure/tools.reader]] -> [chesh
ire "5.4.0" :exclusions [org.clojure/clojure]]
 and
[riemann "0.2.10"] -> [cheshire "5.5.0"]

Consider using these exclusions:
[riemann "0.2.10" :exclusions [cheshire]]
[riemann "0.2.10" :exclusions [cheshire]]


I would try updating the cheshire version you're declaring in
project.clj, instead of adding exclusions, though. (On my machine this
gets rid of the conflicts.)


On 24 February 2016 at 10:24, Punit Naik <naik.puni...@gmail.com> wrote:
> Okay. So this is my project.clj:
>
>
> (defproject chowkidar "0.3.0-SNAPSHOT"
>   :description "Formcept Monitoring Framework"
>   :dependencies [[org.clojure/clojure "1.6.0"]
>  [org.clojure/java.jmx "0.3.0"]
>  [org.clojure/tools.logging "0.3.1"]
>  [riemann/riemann "0.2.10"]
>  [riemann-clojure-client "0.4.2"]
>  [org.formcept/swissknife "0.6.0"]
>  [com.novemberain/langohr "3.0.1"]
>  [cheshire "5.3.1"]]
>   :java-source-paths ["src/java"]
>   :resource-paths ["resources" "conf"]
>   :jvm-opts ["-XX:+UseConcMarkSweepGC"]
>   :profiles {:ship {:aot :all
> :omit-source true}
>  :uberjar {:uberjar-name "formcept-chowkidar.jar"}})
>
> So I had changed the version of "riemann" from 0.2.6 to 0.2.10. Only that.
>
>
> On Wednesday, February 24, 2016 at 2:41:14 PM UTC+5:30, Gary Verhaegen
> wrote:
>>
>> No sign of conflict there - that's a bit surprising. Can you post your
>> project.clj? Do you have any explicit exclusions? What did you change last
>> before it broke? Is it possible that you somehow corrupted your Maven
>> repository and are missing the mentioned class?
>>
>> Maybe it's not a dependency issue at all.
>>
>> On Wednesday, 24 February 2016, Punit Naik <naik.p...@gmail.com> wrote:
>>
>> Here it is:
>>
>> [cheshire "5.3.1"] [com.fasterxml.jackson.core/jackson-core "2.3.1"]
>> [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.3.1"] [tigris
>> "0.1.1"] [clojure-complete "0.2.3" :scope "test" :exclusions
>> [[org.clojure/clojure]]] [com.novemberain/langohr "3.0.1"]
>> [clojurewerkz/support "1.1.0"] [com.google.guava/guava "18.0"]
>> [com.rabbitmq/amqp-client "3.4.2"] [org.clojure/clojure "1.6.0"]
>> [org.clojure/java.jmx "0.3.0"] [org.clojure/tools.logging "0.3.1"]
>> [org.clojure/tools.nrepl "0.2.6" :scope "test" :exclusions
>> [[org.clojure/clojure]]] [org.formcept/swissknife "0.6.0"]
>> [com.twitter/carbonite "1.4.0"] [com.esotericsoftware.kryo/kryo "2.21"]
>> [com.esotericsoftware.minlog/minlog "1.2"]
>> [com.esotericsoftware.reflectasm/reflectasm "1.07" :classifier "shaded"]
>> [org.ow2.asm/asm "4.0"] [org.objenesis/objenesis "1.2"]
>> [com.twitter/chill-java "0.3.5"] [riemann-clojure-client "0.4.2"]
>> [com.aphyr/riemann-java-client "0.4.1"] [com.google.protobuf/protobuf-java
>> "2.6.1"] [io.netty/netty "3.6.1.Final"] [riemann "0.2.10"] [amazonica
>> "0.3.28" :exclusions [[joda-time]]] [com.amazonaws/amazon-kinesis-client
>> "1.1.0" :exclusions [[joda-time]]] [com.taoensso/nippy "2.7.0"]
>> [com.taoensso/encore "1.11.2"] [net.jpountz.lz4/lz4 "1.2.0"]
>> [org.clojure/tools.reader "0.8.9"] [org.iq80.snappy/snappy "0.3"]
>> [org.tukaani/xz "1.5"] [robert/hooke "1.3.0"] [capacitor "0.4.3" :exclusions
>> [[http-kit]]] [org.clojure/core.async "0.1.319.0-6b1aca-alpha"]
>> [org.clojure/tools.analyzer.jvm "0.1.0-beta12"] [org.clojure/core.memoize
>> "0.5.6"] [org.clojure/tools.analyzer "0.1.0-beta12"] [org.ow2.asm/asm-all
>> "4.1"] [clj-antlr "0.2.2"] [org.antlr/antlr4-runtime "4.2.2"]
>> [org.abego.treelayout/org.abego.treelayout.core "1.0.1&

Re: Add support for seq on Java streams?

2016-02-24 Thread Gary Verhaegen
In the mean time, you can probably get pretty far with the
java.util.stream.BaseStream#iterator method and the
clojure.core/iterator-seq function.

On Tuesday, 23 February 2016, Alex Miller  wrote:

> It may, however keep in mind that Clojure supports Java 1.6+ and Stream
> was added in 1.8. That's not an impossible hurdle, but it might make sense
> to make longer before hurdling it.
>
> On Tuesday, February 23, 2016 at 11:03:55 AM UTC-6, 676c7...@gmail.com
>  wrote:
>>
>> Hello!
>>
>> For interoperation with Java, Clojure’s seq supports the Iterable
>> interface directly, which means that all Java collections are
>> automatically seqable. seq also supports the CharSequence and
>> java.util.Map interfaces, and arrays too.
>>
>> Would it make sense to have seq also support java.util.stream.Stream?
>> Streams are just as important an abstraction as collections, and I
>> believe that stream-producing APIs are becoming more and more common. It
>> would be nice if Clojure supported it out of the box.
>>
>> An example (context: http://stackoverflow.com/q/35574155):
>>
>> (->> (.splitAsStream #"\s+" "one two three")
>>  (remove #(clojure.string/includes? % "o"))
>>  (map clojure.string/upper-case)
>>  first)
>>
>> Thanks,
>>
>>
>> --
>> David
>>
>> --
> 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: Compojure does not augment response map

2016-02-24 Thread Gary Verhaegen
My understanding is that compojure concerns itself mostly with routing and
does not try (anymore?) to handle response maps.

Concerning ring.util.response, I think these functions are meant to be
threaded:

(-> (not-found "oh noes")
(content-type "text"))

On Wednesday, 24 February 2016, Torsten Uhlmann 
wrote:

> Thanks Gary!
>
> I haven't touched the middleware stack for a while, and I only found out
> about this thing when testing my routes for security.
> But, if response maps are supposed to be left alone, how is
> ring.util.response supposed to work, for instance the "not-found" function:
>
> (defn not-found
>   "Returns a 404 'not found' response."
>   {:added "1.1"}
>   [body]
>   {:status  404
>:headers {}
>:bodybody})
>
>
> They all return an empty header.
> I guess it's not something (not accepting the response if content type is
> missing?) that has changed in Chrome or Firefox over the last few month?
>
> But then, the compojure wiki's example for a map also manually adds the
> content-type:
> https://github.com/weavejester/compojure/wiki/Routes-In-Detail
>
> --
> 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: ExceptionInInitialization error

2016-02-24 Thread Gary Verhaegen
No sign of conflict there - that's a bit surprising. Can you post your
project.clj? Do you have any explicit exclusions? What did you change last
before it broke? Is it possible that you somehow corrupted your Maven
repository and are missing the mentioned class?

Maybe it's not a dependency issue at all.

On Wednesday, 24 February 2016, Punit Naik  wrote:

> Here it is:
>
> [cheshire "5.3.1"] [com.fasterxml.jackson.core/jackson-core "2.3.1"] [com.
> fasterxml.jackson.dataformat/jackson-dataformat-smile "2.3.1"] [tigris
> "0.1.1"] [clojure-complete "0.2.3" :scope "test" :exclusions [[org.clojure
> /clojure]]] [com.novemberain/langohr "3.0.1"] [clojurewerkz/support
> "1.1.0"] [com.google.guava/guava "18.0"] [com.rabbitmq/amqp-client "3.4.2"
> ] [org.clojure/clojure "1.6.0"] [org.clojure/java.jmx "0.3.0"] [org.
> clojure/tools.logging "0.3.1"] [org.clojure/tools.nrepl "0.2.6" :scope
> "test" :exclusions [[org.clojure/clojure]]] [org.formcept/swissknife
> "0.6.0"] [com.twitter/carbonite "1.4.0"] [com.esotericsoftware.kryo/kryo
> "2.21"] [com.esotericsoftware.minlog/minlog "1.2"] [com.esotericsoftware.
> reflectasm/reflectasm "1.07" :classifier "shaded"] [org.ow2.asm/asm "4.0"]
> [org.objenesis/objenesis "1.2"] [com.twitter/chill-java "0.3.5"] [riemann-
> clojure-client "0.4.2"] [com.aphyr/riemann-java-client "0.4.1"] [com.
> google.protobuf/protobuf-java "2.6.1"] [io.netty/netty "3.6.1.Final"] [riemann
> "0.2.10"] [amazonica "0.3.28" :exclusions [[joda-time]]] [com.amazonaws/
> amazon-kinesis-client "1.1.0" :exclusions [[joda-time]]] [com.taoensso/nippy
> "2.7.0"] [com.taoensso/encore "1.11.2"] [net.jpountz.lz4/lz4 "1.2.0"] [org
> .clojure/tools.reader "0.8.9"] [org.iq80.snappy/snappy "0.3"] [org.tukaani
> /xz "1.5"] [robert/hooke "1.3.0"] [capacitor "0.4.3" :exclusions [[http-
> kit]]] [org.clojure/core.async "0.1.319.0-6b1aca-alpha"] [org.clojure/
> tools.analyzer.jvm "0.1.0-beta12"] [org.clojure/core.memoize "0.5.6"] [org
> .clojure/tools.analyzer "0.1.0-beta12"] [org.ow2.asm/asm-all "4.1"] [clj-antlr
> "0.2.2"] [org.antlr/antlr4-runtime "4.2.2"] [org.abego.treelayout/org.
> abego.treelayout.core "1.0.1"] [org.antlr/antlr4-annotations "4.2.2"] [org
> .antlr/antlr4 "4.2.2"] [org.antlr/ST4 "4.0.8"] [org.antlr/antlr-runtime
> "3.5.2"] [clj-campfire "2.2.0"] [http.async.client "0.5.2"] [com.ning/
> async-http-client "1.7.10"] [clj-http "1.1.2" :exclusions [[org.clojure/
> tools.reader]]] [com.cognitect/transit-clj "0.8.271" :exclusions [[org.
> clojure/clojure]]] [com.cognitect/transit-java "0.8.287"] [com.fasterxml.
> jackson.datatype/jackson-datatype-json-org "2.3.2"] [org.json/json
> "20090211"] [org.apache.directory.studio/org.apache.commons.codec "1.8"] [
> org.msgpack/msgpack "0.6.10"] [com.googlecode.json-simple/json-simple
> "1.1.1" :exclusions [[junit]]] [org.javassist/javassist "3.18.1-GA"] [
> commons-codec "1.10" :exclusions [[org.clojure/clojure]]] [commons-io
> "2.4" :exclusions [[org.clojure/clojure]]] [crouton "0.1.2" :exclusions [[
> org.clojure/clojure]]] [org.jsoup/jsoup "1.7.1"] [org.apache.
> httpcomponents/httpclient "4.4.1" :exclusions [[org.clojure/clojure]]] [
> commons-logging "1.2"] [org.apache.httpcomponents/httpcore "4.4.1" :exclusions
> [[org.clojure/clojure]]] [org.apache.httpcomponents/httpmime "4.4.1" 
> :exclusions
> [[org.clojure/clojure]]] [potemkin "0.3.13" :exclusions [[org.clojure/
> clojure]]] [clj-tuple "0.2.1"] [riddley "0.1.7"] [clj-librato "0.0.5"] [
> clj-nsca "0.0.3"] [com.googlecode/jsendnsca-core "1.3.1"] [clj-time
> "0.10.0"] [joda-time "2.7"] [clj-wallhack "1.0.1"] [com.amazonaws/aws-java
> -sdk "1.10.5.1" :exclusions [[joda-time]]] 
> [com.amazonaws/aws-java-sdk-autoscaling
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-cloudformation "1.10.5.1"] [com.
> amazonaws/aws-java-sdk-cloudfront "1.10.5.1"] 
> [com.amazonaws/aws-java-sdk-cloudhsm
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-cloudsearch "1.10.5.1"] [com.
> amazonaws/aws-java-sdk-cloudtrail "1.10.5.1"] 
> [com.amazonaws/aws-java-sdk-cloudwatch
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-cloudwatchmetrics "1.10.5.1"] [com
> .amazonaws/aws-java-sdk-codecommit "1.10.5.1"] [com.amazonaws/aws-java-sdk
> -codedeploy "1.10.5.1"] [com.amazonaws/aws-java-sdk-codepipeline
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-cognitoidentity "1.10.5.1"] [com.
> amazonaws/aws-java-sdk-cognitosync "1.10.5.1"] [com.amazonaws/aws-java-sdk
> -config "1.10.5.1"] [com.amazonaws/aws-java-sdk-core "1.10.5.1"] [com.
> fasterxml.jackson.core/jackson-databind "2.5.3"] [com.fasterxml.jackson.
> core/jackson-annotations "2.5.0"] [com.amazonaws/aws-java-sdk-datapipeline
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-devicefarm "1.10.5.1"] [com.
> amazonaws/aws-java-sdk-directconnect "1.10.5.1"] [com.amazonaws/aws-java-
> sdk-directory "1.10.5.1"] [com.amazonaws/aws-java-sdk-dynamodb "1.10.5.1"]
> [com.amazonaws/aws-java-sdk-ec2 "1.10.5.1"] [com.amazonaws/aws-java-sdk-ecs
> "1.10.5.1"] [com.amazonaws/aws-java-sdk-efs "1.10.5.1"] 

Re: Compojure does not augment response map

2016-02-24 Thread Gary Verhaegen
IIRC this has always been the behaviour of compojure: if you return a
string it wraps it into a minimalist, valid Ring map, but if you return a
map it assumes it is a Ring map and leaves it alone.

There is a content-type ring middleware somewhere on the web, though in
general I don't think the content type is something that can be magically
detected.

Any changes in your middlewares? The JSON middlewares in particular tend to
fill in the content type automatically (given a map for the body).


On Wednesday, 24 February 2016, Torsten Uhlmann 
wrote:

> Hi,
>
> I'm experiencing a strange behavior in my app. I'm not sure if that's
> because of a version update or something I broke...
>
> The Compojure version used is 1.4.0
>
> In the past a response like this would usually work:
>
> {:status 404
>  :headers {}
>  :body "Not authorized"}
>
>
> The map would be augmented with missing header information.
>
>
> Now the browser tells me this is an invalid response. Logging the output 
> shows that the map is returned as is, without any additional headers. Adding 
> "Content-Type" "text/html; charset=utf-8" to the :headers manually would 
> solve the problem.
>
>
> When my handler only returns a string, that is turned into a response map:
>
>
> {:status 200,
>  :headers {"Content-Type" "text/html; charset=utf-8"},
>  :body "hiha"}
>
>
> I'm using compojure's "route" function not the "defroutes" macro to assemble 
> route
>
>
> This is the development version middleware stack I'm using:
>
>
> (-> handler
> (wrap-authorization auth-backend)
> (wrap-authentication auth-backend)
> ;(wrap-spy "SPY")
> ext-session/wrap-extended-session
> (wrap-defaults ring-defaults-config)
> auth/wrap-authorized-redirects
> wrap-exceptions
> reload/wrap-reload
> wrap-enlive-reload)
>
>
> I know I could solve this by adding the content type by hand, but I'd like to 
> get to the cause of this. I'd also like to just use response functions 
> provided by ring.util.response, these do also not work currently.
>
>
> I guess I just have misconfigured something- although I have no idea what.
>
>
> Torsten.
>
>
> --
> 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: ExceptionInInitialization error

2016-02-24 Thread Gary Verhaegen
Caused by:java.lang.ClassNotFoundException:com.fasterxml.jackson.dataformat.
cbor.CBORFactory

Looks like a dependency problem. If you can't share the whole code, can you
please post the result of

lein deps :tree

On Wednesday, 24 February 2016, Punit Naik  wrote:

> I was compiling my project and I got this error:
>
>
> java.lang.ExceptionInInitializerError, compiling:(riemann.clj:1:1)
>  at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3558)
>  at clojure.lang.Compiler.compile1(Compiler.java:7226)
>  at clojure.lang.Compiler.compile1(Compiler.java:7216)
>  at clojure.lang.Compiler.compile(Compiler.java:7292)
>  at clojure.lang.RT.compile(RT.java:398)
>  at clojure.lang.RT.load(RT.java:438)
>  at clojure.lang.RT.load(RT.java:411)
>  at clojure.core$load$fn__5066.invoke(core.clj:5641)
>  at clojure.core$load.doInvoke(core.clj:5640)
>  at clojure.lang.RestFn.invoke(RestFn.java:408)
>  at clojure.core$load_one.invoke(core.clj:5446)
>  at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
>  at clojure.core$load_lib.doInvoke(core.clj:5485)
>  at clojure.lang.RestFn.applyTo(RestFn.java:142)
>  at clojure.core$apply.invoke(core.clj:626)
>  at clojure.core$load_libs.doInvoke(core.clj:5524)
>  at clojure.lang.RestFn.applyTo(RestFn.java:137)
>  at clojure.core$apply.invoke(core.clj:626)
>  at clojure.core$require.doInvoke(core.clj:5607)
>  at clojure.lang.RestFn.invoke(RestFn.java:1523)
>  at chowkidar.core$loading__4958__auto__.invoke(core.clj:1)
>  at clojure.lang.AFn.applyToHelper(AFn.java:152)
>  at clojure.lang.AFn.applyTo(AFn.java:144)
>  at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3553)
>  at clojure.lang.Compiler.compile1(Compiler.java:7226)
>  at clojure.lang.Compiler.compile1(Compiler.java:7216)
>  at clojure.lang.Compiler.compile(Compiler.java:7292)
>  at clojure.lang.RT.compile(RT.java:398)
>  at clojure.lang.RT.load(RT.java:438)
>  at clojure.lang.RT.load(RT.java:411)
>  at clojure.core$load$fn__5066.invoke(core.clj:5641)
>  at clojure.core$load.doInvoke(core.clj:5640)
>  at clojure.lang.RestFn.invoke(RestFn.java:408)
>  at clojure.core$load_one.invoke(core.clj:5446)
>  at clojure.core$compile$fn__5071.invoke(core.clj:5652)
>  at clojure.core$compile.invoke(core.clj:5651)
>  at user$eval9$fn__16.invoke(form-init3209452928121977251.clj:1)
>  at user$eval9.invoke(form-init3209452928121977251.clj:1)
>  at clojure.lang.Compiler.eval(Compiler.java:6703)
>  at clojure.lang.Compiler.eval(Compiler.java:6693)
>  at clojure.lang.Compiler.load(Compiler.java:7130)
>  at clojure.lang.Compiler.loadFile(Compiler.java:7086)
>  at clojure.main$load_script.invoke(main.clj:274)
>  at clojure.main$init_opt.invoke(main.clj:279)
>  at clojure.main$initialize.invoke(main.clj:307)
>  at clojure.main$null_opt.invoke(main.clj:342)
>  at clojure.main$main.doInvoke(main.clj:420)
>  at clojure.lang.RestFn.invoke(RestFn.java:421)
>  at clojure.lang.Var.invoke(Var.java:383)
>  at clojure.lang.AFn.applyToHelper(AFn.java:156)
>  at clojure.lang.Var.applyTo(Var.java:700)
>  at clojure.main.main(main.java:37)
> Caused by: java.lang.ExceptionInInitializerError
>  at java.lang.Class.forName0(Native Method)
>  at java.lang.Class.forName(Class.java:278)
>  at clojure.lang.RT.loadClassForName(RT.java:2093)
>  at clojure.lang.RT.load(RT.java:430)
>  at clojure.lang.RT.load(RT.java:411)
>  at clojure.core$load$fn__5066.invoke(core.clj:5641)
>  at clojure.core$load.doInvoke(core.clj:5640)
>  at clojure.lang.RestFn.invoke(RestFn.java:408)
>  at clojure.core$load_one.invoke(core.clj:5446)
>  at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
>  at clojure.core$load_lib.doInvoke(core.clj:5485)
>  at clojure.lang.RestFn.applyTo(RestFn.java:142)
>  at clojure.core$apply.invoke(core.clj:626)
>  at clojure.core$load_libs.doInvoke(core.clj:5524)
>  at clojure.lang.RestFn.applyTo(RestFn.java:137)
>  at clojure.core$apply.invoke(core.clj:626)
>  at clojure.core$require.doInvoke(core.clj:5607)
>  at clojure.lang.RestFn.invoke(RestFn.java:457)
>  at cheshire.core$loading__4958__auto__.invoke(core.clj:1)
>  at cheshire.core__init.load(Unknown Source)
>  at cheshire.core__init.(Unknown Source)
>  at java.lang.Class.forName0(Native Method)
>  at java.lang.Class.forName(Class.java:278)
>  at clojure.lang.RT.loadClassForName(RT.java:2093)
>  at clojure.lang.RT.load(RT.java:430)
>  at clojure.lang.RT.load(RT.java:411)
>  at clojure.core$load$fn__5066.invoke(core.clj:5641)
>  at clojure.core$load.doInvoke(core.clj:5640)
>  at clojure.lang.RestFn.invoke(RestFn.java:408)
>  at clojure.core$load_one.invoke(core.clj:5446)
>  at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
>  at clojure.core$load_lib.doInvoke(core.clj:5485)
>  at clojure.lang.RestFn.applyTo(RestFn.java:142)
>  at clojure.core$apply.invoke(core.clj:626)
>  at clojure.core$load_libs.doInvoke(core.clj:5524)
>  at clojure.lang.RestFn.applyTo(RestFn.java:137)
>  at clojure.core$apply.invoke(core.clj:626)
>  at 

Re: Question about Clojure function naming

2016-02-19 Thread Gary Verhaegen
I'd say only Rich Hickey can really answer these questions, but here is one
possible explanation.

These functions are not equivalent. Just like 'send' on an agent has
fundamental differences with 'swap!', 'alter' has fundamental differences
with both. There is also some similarity, of course: in all three cases,
the intent is to "update" the "current" value by supplying a transformation
function, but:

* 'swap!' will happen immediately, in the current thread, with no regard
for whatever else happens;
* 'send' will happen at some point in the (hopefully near) future on a
different thread;
* 'alter' can only be used within a transaction and will do some complex
magic to coordinate changes to multiple refs.

Bear in mind that Clojure is built on top of a polymorphic foundation, so
names like "atom-swap!" and "ref-swap!" would not really make sense; if the
point was to call them the same, they could just be called the same, like
'conj' is the same for all data structures, and like 'deref', which does
have the same semantics for atoms, refs, and agents, is called the same for
the three of them.

In short, one possible explanation is that they were deemed sufficiently
different to warrant a different name.

On Friday, 19 February 2016, Atamert Ölçgen  wrote:

> why Clojure chose to name functions operating on refs and atoms so
>> differently
>
>
> swap! is not an alter on atoms. And vice versa.
>
> reset! is not a ref-set on atoms. And vice versa.
>
> The analogous functions names would make remembering which is which easier.
>
>
> Are you having trouble remembering them?
>
>
>
> On Fri, Feb 19, 2016 at 7:04 AM, Tianxiang Xiong <
> tianxiang.xi...@gmail.com
> > wrote:
>
>> I'm currently reading Practical Clojure
>>  by VanderHart and Sierra, and am
>> on the section about state management.
>>
>> I'm curious why Clojure chose to name functions operating on refs and
>> atoms so differently. As I understand it,
>>
>> swap! -> atoms, alter -> refs
>> reset! -> atoms, ref-set -> refs
>>
>> Why "swap!" and "reset!", instead of "atom-alter" and "atom-set"? The
>> analogous functions names would make remembering which is which easier.
>>
>> --
>> 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.
>>
>
>
>
> --
> Kind Regards,
> Atamert Ölçgen
>
> ◻◼◻
> ◻◻◼
> ◼◼◼
>
> www.muhuk.com
>
> --
> 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.async channels

2016-02-18 Thread Gary Verhaegen
There may be a mismatch between the way you approach the problem and the
way the library is intended to be used. core.async channels do not "do"
anything, they are really just conveying belts, or tubes. You put something
on one end and someone else takes it up from the other end.

If you want a consumer that waits for some time, you may for example use a
loop that first waits on a timeout channel, and then takes from the "real"
channel.

If you want to wait until you have a given number of elements to do
something, again, I would advise doing that in the consumer: it can easily
accumulate in a local variable (e.g. in the arguments to the go-loop call)
the elements you get from the channel, and act on them when you have enough.

Or you can build a pipeline of two channels, with an intermediate go block
that accumulates elements from the first channel and puts a vector of n
elements on the second channel, if you want to decouple the accumulation
part from the actual processing.

You can probably check if a channel is full with offer!, but I doubt that
will be an easy idiom, especially if you want to do that checking from the
consumer.


On Thursday, 18 February 2016, Punit Naik  wrote:

> I want to create a clojure aync channel which will do a specific task
> after its fully filled to its capacity or after a certain amount of time
> since its activation. How do I do this?
>
> --
> 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: macro to unwrap a list

2016-02-15 Thread Gary Verhaegen
On Monday, 15 February 2016, Sonny To  wrote:

> I am trying to write a macro to unwrap a list:
>
> here's my naive attempt
>
> (defmacro unwrap [s]
>   (-> s pr-str  (clojure.string/replace #"[\(\)]" "") read-string))
>
> (unwrap (1 2 3) ) should give 1 2 3
>
> any ideas how this can be done?
>
> thanks,
> Sonny
>

As pther mentioned, you can't really do that with a macro. Depending on
your use-case, though, you may find the "unquote splicing" ~@ operator
useful.

-- 
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 future method

2016-02-15 Thread Gary Verhaegen
`future` starts a function in a separate thread, which comes out of a
thread pool. It may not be that easy to check if a future has run at
all if you don't hold onto the future object and wait for it.

How did you check if they run? It's possible, for example, that they
are sending their print's to a different output than the rest of your
code, depending on your development setup; it's also possible (though
less likely) that in your experimentation you have somehow depleted
your thread pool and so they are queued somewhere.

Ideally, to maximize our chances of helping you, you would provide a
minimal, stand-alone snippet of code that demonstrates your problem.

On 15 February 2016 at 12:31, Punit Naik  wrote:
> I have a function which calls a number of functions in sequence. Few of them
> are normal functions and some of them use clojure's 'future' method. When I
> run this function, All the normal fuctions run but the functions which use
> 'future' don't run at all. But if I run the functions which use 'future'
> individually, they run perfectly fine.
>
> Can anyone point me to a solution?
>
> Please help!
>
> --
> 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.


conditional logic implemented as pattern-matching and restructuring in the signature of the function

2016-02-10 Thread Gary Verhaegen
It's not pattern matching, but would replacing the apply with a reduce
achieve the same result?

I'm not in a position to test this right now, but I believe (reduce f init
()) returns init without invoking f, and (conj x a b c) is equivalent to
(reduce conj x [a b c]), so replacing apply with reduce should let you get
rid of the if.

On Tuesday, 9 February 2016, Stuart Sierra > wrote:

> Clojure's destructuring is not the same thing as the "pattern matching"
> found in some other functional languages. Pattern matching can do various
> conditional checks, destructuring cannot. Clojure's "defn" supports
> destructuring in the argument list.
>
> Full pattern matching is available in Clojure via libraries such as
> core.match:
> https://github.com/clojure/core.match
>
> –S
>
>
>
> On Monday, February 8, 2016 at 2:41:44 PM UTC-5, Laws wrote:
>>
>> Sean Johnson has a great video about pattern matching, where he suggests
>> that any function that starts with a conditional should have the
>> conditional removed and the conditional logic implemented as
>> pattern-matching and restructuring in the signature of the function. But
>> after some experimentation, I have failed to figure out a way to do this
>> here:
>>
>> (defn add-parties-to-customer-queue [parties]
>>   (if (seq parties)
>> (swap! customer-queue
>>(fn [previous-customer-queue]
>>  (apply conj previous-customer-queue parties)
>>
>> "parties" sometimes has a vector of vectors, but sometimes it is simply:
>> ()
>>
>> Is there any way I can match against that pattern in the function
>> signature?
>>
>>
>>
>>
>>
>> --
> 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: Scripting with Clojure / "slow" boot time

2016-02-10 Thread Gary Verhaegen
Please excuse the very naive question, but if the main problem seems to be
compilation of loaded namespaces, what about aot? Does it help at all? If
not, why? As far as I know, the JVM already does lazy loading with Java
classes essentially in the way that Mike described.

On Wednesday, 10 February 2016, Marc O'Morain  wrote:

> Hi Alex,
>
> I've love to offer any help/test data on this that I can. At CircleCI we
> run (among other processes) a large Clojure app that takes 2 minutes to
> load on a top of line Macbook Pro, with Java 1.8 (Hotspot) . From my best
> efforts at profiling, this time is all spend in the Clojure Compiler and
> the JVM class loader, loading all transitive dependencies. Mike's analysis
> above is totally in line with what we see.
>
> One thing I have noticed is that all compilation runs in a single thread.
> In theory all namespaces required in an `ns` form can be loaded in parallel.
>
> If there is any profiling you would like me to run on the code-base,
> please let me know.
>
> Marc
>
> On 10 February 2016 at 08:22, Mikera  > wrote:
>
>> Good initiative, I've filled in a response to the survey.
>>
>> One thing that strikes me is that the main issue with loading time is the
>> time required to transitively load and compile all the referred namespaces
>> (which can be a lot in a big project...). This in turn may trigger class
>> loading of Java libraries, IO as various resources are initialised etc. An
>> observation is that a lot of this is often not required initially, so there
>> *might* be a clever strategy to mitigate this through laziness.
>>
>> This could be something like:
>> - When loading the current namespace, *don't* load referred namespaces
>> (yet)
>> - Create lazy placeholders within vars in the current namespace for (for
>> every def, defn etc.)
>> - Only when the placeholder is deref'd / invoked then compile the
>> relevant function and pull in dependencies.
>> - After first deref / invocation, replace the placeholder with the full
>> compiled function / value, so that subsequent access has no overhead
>>
>> This would be a pretty big change, and might break tools that make
>> assumptions about order of loading of namespaces... but I think it would
>> solve 90% of the boot time problems if implemented correctly.
>>
>> The other potentially big win would be concurrent loading of namespaces.
>> Guess you are looking at that already?
>>
>>
>>
>> On Wednesday, 10 February 2016 02:36:43 UTC+8, Alex Miller wrote:
>>>
>>> I'm doing some research on slow Clojure boot time and would be
>>> interested in collecting info about example use cases where it's been a
>>> problem for people.
>>>
>>> http://goo.gl/forms/eSpn8M5FNB
>>>
>>> I'm not expecting to release the results in any formal way, mostly
>>> looking to use it to pull out particular use cases and/or commonalities
>>> across anecdotes so that we can work on boot time problems that matter the
>>> most (and solutions likely to help the most). Any numbers you can provide
>>> would be great.
>>>
>>> Alex
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> 
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 

Re: Can the data in a vector have data inside it that points to the same vector? vector1=[a b c d] a=[1 2 f s vector1]

2016-02-10 Thread Gary Verhaegen
Basically, since vectors are immutable, you cannot easily construct that
kind of recursive structure. Any means of breaking immutability would allow
it, though (atoms, promises, undocumented mutable apis, mutable objects
inside the vector, etc.).

To clarify: the vector itself does not explicitly prevent that, but the
fact that a vector is immutable once created means that you cannot put it
into itself, since you don't have it before you create it and you cannot
add anything to it once it is created. That holds for any kind of immutable
(and eager) data structure.

On Wednesday, 10 February 2016, James Reeves  wrote:

> No, vectors can't be recursive. However you can use a reference of some
> description, e.g.
>
>(let [p (promise), v [p]]
>  (deliver p v)
>  v))
>
> You could also use a lazy seq.
>
> - James
>
> On 10 February 2016 at 04:29, Timothy Vinick  > wrote:
>
>> Here's an example:
>>
>>  vector1=[a b c d] a=[1 2 f s vector1]
>>
>> --
>> 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.
>

-- 
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: Java API type hint question

2016-02-04 Thread Gary Verhaegen
The part within brackets does not exist outside the Java compiler, i.e. at
the bytecode level, it is really just a Collection, not a Collection.

If you're interested, you can google "java type erasure" to learn more
about this.

On Wednesday, 27 January 2016, Ritchie Cai  wrote:

> Ahh, thanks. I was wondering how to specify Collection
>  extends E
> >,
> but looks like just Collection will work.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Attempting to call unbound fn

2016-02-02 Thread Gary Verhaegen
My first step would be to run

lein deps :tree

On the project where the error appears, and look for unexpected versions of
dependencies.

On Monday, 1 February 2016, Pedro Santos  wrote:

> Hello,
>
> I'm referencing a fn on another lib/namespace. Is this one:
>
> https://github.com/clanhr/clanhr-api/blob/master/src/clanhr_api/core.clj#L197
>
> We don't use declare, it's just a "normal" fn. On another project that
> references that fn, we get:
>
> #error {
>  :cause Attempting to call unbound fn:
> #'clanhr-api.core/query-string-builder
>  :via
>  [{:type java.lang.IllegalStateException
>:message Attempting to call unbound fn:
> #'clanhr-api.core/query-string-builder
>:at [clojure.lang.Var$Unbound throwArity Var.java 43]}]
>  :trace
>  [[clojure.lang.Var$Unbound throwArity Var.java 43]
>   [clojure.lang.AFn invoke AFn.java 36]
>   [clanhr.absences_api.core.get_events$query_string_builder invokeStatic
> get_events.clj 4
>
> The "clanhr.absences_api.core.get_events$query_string_builder" is just a
> wrapper that calls the other one.
>
> Any tips on how to troubleshoot this? Running clj 1.8.
>
> --
> Pedro Pereira Santos
> https://twitter.com/donbonifacio
>
> --
> 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: Scala for-comprehension to Clojure

2015-11-26 Thread Gary Verhaegen
It's a bit hard (at least for me) to see what you're actually trying to do
here that would precent a direct translation of your snippet to Clojure's
for. Could you perhaps post a complete, self-contained code example in
Scala?

On Thursday, 26 November 2015, Torsten Uhlmann 
wrote:

> Hi Rastko,
>
> One way of doing that would be to use the mlet macro from the Cats
> library: http://funcool.github.io/cats/latest/#mlet
>
> Also, there are several if-lets or when-lets out there that allow multiple
> bindings, I used one from https://github.com/ptaoussanis/encore
>
> I use Scala's for most of the time when there are Options in the mix that
> may or may not hold a value.
>
> For binding to generators, Clojures for might be a better fit?
> https://clojuredocs.org/clojure.core/for
>
> Would that help you?
>
> Torsten.
>
> PS: I'm learning Clojure myself with Scala and Java background.
>
> On Thursday, November 26, 2015 at 12:12:01 PM UTC+1, Rastko Soskic wrote:
>>
>> Hi,
>> I am aware of philosophical differences of Scala and Clojure
>> but functional programming should be a pretty common ground :)
>> Thus I need help, I am trying to mimic Scala's for comprehension in
>> Clojure.
>>
>> Hopefully someone will be able to aid me with the following (perhaps more
>> familiar with Scala):
>>
>> Scala for comprehension is errr how to say "de-sugared" to series
>> of map and flatMap calls... thus, it is possible to use plain functions
>> in for-comprehension
>> like:
>> *val *ns: Conv[List[Int]] = *for *{ // Conv is just alias for functions
>> of type B => (B, A)
>> x <- int // int is function again of type Conv
>> y <- int
>> xs <- ints(x) // this is just sequence of numbers
>> } *yield *xs.map(_ * y)
>>
>> I don't need all the nuts and bolts, just some guideline for achieving
>> something similar
>> in Clojure.
>>
>> I am not lazy :) I've already eagerly researched a bit and got to this: Scala
>> for-comprehension to Clojure
>> 
>>
>> But as you can see that is not really about having kind of generator
>> function which is wrapped into flatMap
>> call. Perhaps this is not in Clojure's spirit at all, perhaps there is
>> some Clojure idiom to achieve something similar.
>>
>> Any tip, suggestion, critic is welcome and appreciated.
>>
>> If someone is wondering how in the world I came up to this, I am doing
>> some f-p exercises which I've got Scala solution for
>> however I am not very interested in Scala and I am doing Clojure so I
>> just need to grasp concepts...
>>
>> Thanks in advance...
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] Okku 0.1.5 - Akka from Clojure

2015-11-19 Thread Gary Verhaegen
Okku, the Clojure (thin) wrapper for Akka.

Github: https://github.com/gaverhae/okku
Leiningen: [org.clojure.gaverhae/okku "0.1.5"]

New in this release:

* Updated Akka dependency to 2.3.14
* Updated Clojure dependency to 1.7.0
* Support for Akka's ask pattern

Thanks go to David Orme for this release.

-- 
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: newbie Q: how to tweak file-seq (original: how to selectively iterate through a tree of directories) ?

2015-10-04 Thread Gary Verhaegen
Sorry, I meant :when, not :where. Though it won't change the problem.

Here's the rub: first file-seq produces its whole seq, then for comes along
and filters out some of it. So (ignoring lazyness) file-seq ha already
traversed symbolic links (at least for folders) by the time for sees it.

I fear you'll have to write your own file traversal function. Fortunately,
it's not that hard. You can probably start from one of the examples here:

https://clojuredocs.org/clojure.core/tree-seq

On Saturday, 3 October 2015, <hpwe...@gmail.com
<javascript:_e(%7B%7D,'cvml','hpwe...@gmail.com');>> wrote:

> The directory structure is
>/path/top/dir1
>/path/top/dir1/f1
>/path/top/dir1/f2
>/path/top/dir2 -> /another/path/dir2
> --
>/another/path/dir2/g1
>/another/path/dir2/g2
>
> I tried this (following suggestion):
>
>   (for [file (file-seq dir) :while (.isFile file)] (.getPath file))
>
> It prints out a list with following items:
>   /path/top/dir1/f1
>   /path/top/dir1/f2
>   /path/top/dir2/g1
>   /path/top/dir2/g2
>
> BUT the last two items are the ones that I do NOT want.
> So, I guess I will need to tweak  file-seq so that it will NOT traverse
> /path/top/dir2  since it is a symbolic link.
>
> Is there anyway to tweak file-seq ??
>
> THanks
> HP
>
> On Saturday, October 3, 2015 at 11:59:40 AM UTC-4, Gary Verhaegen wrote:
>>
>> I'm on Windows at the moment, so I can't test, but I think you can
>> filter on isFile:
>>
>> (for [file (file-seq dir)
>>   :where (.isFile file)]
>>   (.getName file))
>>
>> should work, I think.
>>
>> On 3 October 2015 at 07:36,  <hpw...@gmail.com> wrote:
>> > Under linux, I have a tree of directories like this:
>> >
>> > /path/top
>> >
>> > /path/top/dir1  (in here there are two files f1, f2)
>> >
>> > /path/top/dir2 -> /another-path/dir2 (a symbolic link)
>> >
>> >  and under /another-path/dir2 there are two files g1,
>> g2
>> >
>> > If I use below code, I would get a list of files f1, f2, and g1, g2
>> >
>> > (def directory (clojure.java.io/file "/path/top"))
>> > (def files
>> > (for [file (file-seq directory)] (.getName file)))
>> > (files)
>> >
>> > BUT I want to skip traversing the directory dir2 since it is a symbolic
>> > link.
>> >
>> > i.e. the list of files that I want to get is f1, f2 only.
>> >
>> > Could you please suggest a way to do this ?
>> >
>> > THanks
>> >
>> > HP
>> >
>> > --
>> > 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.
>

-- 
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: macroexpand and syntax-quote

2015-10-03 Thread Gary Verhaegen
This is very much by design. Clojure is somewhere between Common Lisp and
Scheme in terms of macro hygiene.

Being compatible with Common Lisp is explicitly not a goal for Clojure.
Watch out for similarly named functions with different behavior too.

On Saturday, 3 October 2015, bentav  wrote:

> Common Lisp:
>
> (defmacro foo ()
>   `(defmacro bar ()
> `(baz)))
>
> (macroexpand-1 '(foo))
>
> => (DEFMACRO BAR () `(BAZ))
>
>
>
>
> Clojure:
>
> (defmacro foo []
>   `(defmacro bar []
> `(baz)))
>
> (macroexpand-1 '(foo))
>
> => (clojure.core/defmacro user/bar [] (clojure.core/seq
> (clojure.core/concat (clojure.core/list (quote user/baz)
>
>
> Looks awful. Is it possible to do something about that?
>
> --
> 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: newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread Gary Verhaegen
I'm on Windows at the moment, so I can't test, but I think you can
filter on isFile:

(for [file (file-seq dir)
  :where (.isFile file)]
  (.getName file))

should work, I think.

On 3 October 2015 at 07:36,   wrote:
> Under linux, I have a tree of directories like this:
>
> /path/top
>
> /path/top/dir1  (in here there are two files f1, f2)
>
> /path/top/dir2 -> /another-path/dir2 (a symbolic link)
>
>  and under /another-path/dir2 there are two files g1, g2
>
> If I use below code, I would get a list of files f1, f2, and g1, g2
>
> (def directory (clojure.java.io/file "/path/top"))
> (def files
> (for [file (file-seq directory)] (.getName file)))
> (files)
>
> BUT I want to skip traversing the directory dir2 since it is a symbolic
> link.
>
> i.e. the list of files that I want to get is f1, f2 only.
>
> Could you please suggest a way to do this ?
>
> THanks
>
> HP
>
> --
> 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: Origin for Clojure using the term 'vector' instead of 'array'?

2015-10-03 Thread Gary Verhaegen
For people with a C/Java-style background, array typically designates a
contiguous piece of memory that has been allocated at once, is thus
fixed-size, and can be accessed randomly (i.e. by index). Vectors are
typically structures or objects at a higher level, that still present a
random-access collection, but can also for example change size.

With that Background, Clojure's choice makes perfect sense. Please also
consider that Clojure does not use vector instead of array, but in addition
to; see make-array, geta, seta, et al.

On Saturday, 3 October 2015, Mars0i  wrote:

> I have no idea about the official reason, but outside of certain
> programming languages that use "array" for one-dimensional data structures,
> an array often has two (or more) dimensions.  In R, for example, arrays can
> have an arbitrary number of dimensions.  Honestly, when I'm away from Java
> for a while and then encounter the term "array" in Java, I have to stop and
> remember that it's 1-D, or check some documentation, because "array"
> doesn't automatically mean 1-D to me.
>
> On the other hand, I believe that vectors are always one-dimensional, as
> in linear algebra.
>
> So maybe Rich Hickey just decided that "vector" was a better, less
> ambiguous name.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2015-09-29 Thread Gary Verhaegen
This is the whole official API, as defined since Clojure 1.6 (prior to
that, there was no official Java API). All other Java classes in the
clojure codebase are considered internal implementation. Here is the
relevant part of the 1.6 release notes:

https://github.com/clojure/clojure/blob/master/changes.md#21-java-api

On 29 September 2015 at 16:46, Andy Fingerhut  wrote:
> Others can confirm, but I think that is the entire API, callable from Java,
> that is documented and supported by Clojure.  Everything is reachable from
> there if you know which Clojure Vars you want to use.
>
> Andy
>
> On Tue, Sep 29, 2015 at 7:31 AM, crocket  wrote:
>>
>> http://clojure.github.io/clojure/javadoc/ contains only two classes.
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to 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.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: No recent activity for core.async?

2015-09-26 Thread Gary Verhaegen
That question has been asked recently and the official answer was that a
new release is coming "soon". There was no promise that the next release
would get the project out of alpha, though.

On Saturday, 26 September 2015, Rafik NACCACHE 
wrote:

> core.async didn't move since more than a year.
>
> Is any new release coming soon? I actually use this library intensively,
> and the fact it is staying alpha for more than a year starts giving me some
> shivers :)
>
> Thank you for any updates !!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: Lazy Sequence Results in Stack Overflow

2015-09-26 Thread Gary Verhaegen
Primes are hard, because you essentially need to track all previous primes.

Here's one way to think about what you're doing here. First, you
create a lazy sequence of infinite numbers from 3 and up. This is done
by building a cons cell with 3 as the head and (iterate inc 4) as the
tail.

Then you filter that. From now on, every time you want the next
element, you'll have to run two functons: inc and odd?, plus some
extra processing for iterate and filter which both build up an
intermediate lazy seq.

Then you call sieve, which yet again builds up a new lazy seq that
accumulates more functions on its tail: assoc-nth, drop-while and a
recursive call to sieve. And assoc-nth itself still wraps a bunch of
other functions on your tail.

Now, the crucial part here is that most of these functions never go
away: for each new element that you compute, you add additional
function calls to each subsequent element. So that getting the 5th
element requires more additional elements than getting the 4th.

In some way, you have chosen to encode your list of previous primes as
accumulated functions. By the 500th prime, you have some much
accumulated functions that your call stack itself blows the stack.

With your implementation, on my computer, I only get about 300:

(defn num-primes
  [prime-seq]
  (try (doall prime-seq)
   (catch StackOverflowError e
 (count prime-seq

=> (time (num-primes primes))
"Elapsed time: 62385.706564 msecs"
325

A slightly more direct approach to the sieve (though arguably not a
true sieve), which has the same problem, in a more obvious way, would
be:

(defn filter-primes
  []
  (let [helper (fn helper [n]
 (lazy-seq (cons n (remove #(zero? (mod % n))
   (helper (inc n))]
(helper 2)))

=> (time (max-prime (filter-primes)))
"Elapsed time: 472.078328 msecs"
251

Two things to note:

* I've turned the sequence into a defn instead of a def. This makes it
possible to not hold onto the head. Since we get a stack overflow
around 300 integers here, this is no biggie, but it's a good practice
when defining potentially very long lazy seqs.
* It should be much more clear here that each prime is adding a call
to remove: whereas the 2 gets returned directly, the 3 has to go
through a mod 2 operation, then a remove function has to check that it
returned false. Similarly, the 5 will, in this very naive
implementation, need to check that it is not divisible by either 2, 3,
or 4, so we now have a "stack" of three remove functions to go
through.

A closer implementation to yours would be:

(defn filter-primes2
  []
  (let [sieve (fn [ls]
(let [p (first ls)]
  (lazy-seq
(cons p (remove #(zero? (mod % p)) ls)]
(sieve (iterate inc 2

=> (time (num-primes (filter-primes2)))
"Elapsed time: 59021.93554 msecs"
325

However, storing "primes found so far" into a stack of functions is
not very efficient (in either memory or computation), and the sieve
only really shines when it's used on vectors of known length (because
then there's no division), not on lazy seqs of potentially infinite
length. Here's an attempt to combine the advantages of the sieve with
lazy seqs:

(defn array-sieve
  []
  (let [sieve (fn [n]
(let [a (long-array n)]
  (loop [idx 0]
(when (< idx n)
  (aset-long a idx (+ 2 idx))
  (recur (inc idx
  (loop [idx 0]
(when (and (< idx n)
   (not= 0 (aget a idx)))
  (let [v (aget a idx)]
(loop [idx2 (+ idx v)]
  (when (< idx2 n)
(aset-long a idx2 0)
(recur (+ v idx2))
(when (< idx n)
  (recur (inc idx
  (vec (remove zero? a
generator (fn [[prev-idx known-primes prev-prime]]
(let [next-idx (inc prev-idx)
  known-primes (if (< next-idx (count known-primes))
 known-primes
 (loop [n (* 2 next-idx)]
   (let [k (sieve n)]
 (if (> (count k) next-idx)
   k

(recur (* 2 n))
  next-prime (get known-primes next-idx)]
  [next-idx known-primes next-prime]))]
(->> [0 [2] 2]
 (iterate generator)
 (map last

=> (time (nth (array-sieve) (dec 10)))
"Elapsed time: 13454.668724 msecs"
1299709

(You can check e.g. here that this is correct:
https://primes.utm.edu/nthprime/index.php#nth; the dec is there
because this website counts from 1, and nth from 0)

This is of course much more complex, but it's also much 

Re: Immediate streaming of shell cmd stdout to a browser

2015-09-24 Thread Gary Verhaegen
Are you sure that the script itself is streaming its results? Shells
sometimes batch things when they detect they are not connected to a
tty.

On 24 September 2015 at 16:45, Karel Miarka  wrote:
> Hi,
>
> I want to run a long running bash script from a webapp and see it's
> continuous results on the page. I use conch to get the process' output
> stream and use this simple ring handler:
>
> (defn handler [req]
>   (response/response
> (let [p (sh/proc "/home/xyz/build.sh")]
>   (ring-io/piped-input-stream
> #(io/copy (:out p) % :buffer-size 1)))
> ...
>
> And run-jetty with :output-buffer-size 1 option, but the output is
> unfortunately displayed at once after the process finishes.
>
> Any idea?
>
> Thanks,
> Karel
>
> --
> 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: To supply callback function from clojure to java method expecting a lambda with interop

2015-09-21 Thread Gary Verhaegen
Note that you have to implement the one method of the functional interface.
It may not always be called "run", as Java 8 places no restriction on the
method name.

On Sunday, 20 September 2015, Nagarajan  wrote:

> Thank you everyone for clearing this up. Since my case is for a specific
> java library, it's source should give me an idea what to do. Java 8
> callback is still possible with clojure. I really like to praise whoever
> responsible for making decision of java 8 lamdas as interface
> On 20-Sep-2015 7:18 pm, "ajoberstar"  > wrote:
>
>> Yes, your understanding is correct. MyCalcLambda is the one you'll want
>> to reify, and it will be just like using reify on any interface.
>>
>> After that thread you linked to, I did create ike.cljj (
>> https://github.com/ike-tools/ike.cljj) which supports converting Clojure
>> functions to lambdas.
>>
>> For a lot of use cases, it's probably better to stick with reify, but
>> ike.cljj can cut down on some of the boilerplate.
>>
>> Andrew Oberstar
>>
>> On Sat, Sep 19, 2015 at 8:20 PM Nagarajan N > > wrote:
>>
>>> I started using clojure since last year. I like the language. It even
>>> made me more familiar with java. Before I detested java. Am moderately
>>> familiar with clojure way of making interop calls to java libraries. But I
>>> have no idea how to interop with a java library implementing java 8 lambdas
>>> as method params. I am not expecting any clean way to do this (I got that
>>> from this thread
>>> https://groups.google.com/forum/#!topic/clojure/WjTtqrLf_FY) . I just
>>> need a way (however verbose it is) to call a java method expecting a lambda.
>>> For example a java 8 code like this
>>>
>>>
>>> server.requestHandler(request -> {
>>>   request.response().end("hello world!");
>>> });
>>>
>>>
>>> how do I call this in clojure ,something like this
>>>
>>>
>>> (.requestHandler
>>>server
>>>(some-magical-function-or-macro
>>>  [request]
>>>  (doto request
>>>(.response)
>>>(.end "hello world!!"
>>>
>>>
>>> I 'd like someone to point me in the right direction for this.
>>>
>>> --
>>> 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 a topic in the
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/clojure/QcKQ1PHLfh8/unsubscribe.
>> To unsubscribe from this group and all its topics, 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 

Re: To supply callback function from clojure to java method expecting a lambda with interop

2015-09-20 Thread Gary Verhaegen
The magical macro is reify. Ironically, you'll need to know the type of the
lambda to use it from Clojure.

On Sunday, 20 September 2015, Nagarajan N  wrote:

> I started using clojure since last year. I like the language. It even made
> me more familiar with java. Before I detested java. Am moderately familiar
> with clojure way of making interop calls to java libraries. But I have no
> idea how to interop with a java library implementing java 8 lambdas as
> method params. I am not expecting any clean way to do this (I got that from
> this thread https://groups.google.com/forum/#!topic/clojure/WjTtqrLf_FY)
> . I just need a way (however verbose it is) to call a java method expecting
> a lambda.
> For example a java 8 code like this
>
>
> server.requestHandler(request -> {
>   request.response().end("hello world!");
> });
>
>
> how do I call this in clojure ,something like this
>
>
> (.requestHandler
>server
>(some-magical-function-or-macro
>  [request]
>  (doto request
>(.response)
>(.end "hello world!!"
>
>
> I 'd like someone to point me in the right direction for this.
>
> --
> 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: Why (memoize (fn [_#] (gensym "node")) in rhizome?

2015-09-13 Thread Gary Verhaegen
Because the form appears in a syntax-quote, the # is required to,ask
syntax-quote to create an identifier rather than resolve it to the current
namespace.

On Sunday, 13 September 2015, Akhil Wali  wrote:

> What does _# mean opposed to simply _? With respect to memoization of
> genus it's the same thing IMHO.
>
> --
> 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: why there is java.lang.NoClassDefFoundError: clojure_mail/message$loading__4958__auto__, error

2015-09-12 Thread Gary Verhaegen
For that kind of question, you really need to post your code along with the
error. A project on github, perhaps?

>From just the error message, it looks like you're trying to use a
namespaced symbol "clojure-mail/message", and that symbol is not defined. I
would gues either a typo in your own code, or a dependency mismatch. Both
are hard to ascertain without the full project, though.

If you really can't post your code, can you at least post the result of
"lein deps :tree"?

On Monday, 24 August 2015, Chih Yang  wrote:

> I  aot compile my project:
>
> :aot [my namespace]
>
> But I always get following error, this is crazy, can some one help me to
> troubleshooting what is going on?
>
> vagrant@precise32:/work/everbridge.qa$ lein compile
> Compiling everbridge.qa
> java.lang.NoClassDefFoundError:
> clojure_mail/message$loading__4958__auto__, compiling:(core.clj:1:1)
> at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3558)
> at clojure.lang.Compiler.compile1(Compiler.java:7226)
> at clojure.lang.Compiler.compile1(Compiler.java:7216)
> at clojure.lang.Compiler.compile(Compiler.java:7292)
> at clojure.lang.RT.compile(RT.java:398)
> at clojure.lang.RT.load(RT.java:438)
> at clojure.lang.RT.load(RT.java:411)
> at clojure.core$load$fn__5066.invoke(core.clj:5641)
> at clojure.core$load.doInvoke(core.clj:5640)
> at clojure.lang.RestFn.invoke(RestFn.java:408)
> at clojure.core$load_one.invoke(core.clj:5446)
> at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
> at clojure.core$load_lib.doInvoke(core.clj:5485)
> at clojure.lang.RestFn.applyTo(RestFn.java:142)
> at clojure.core$apply.invoke(core.clj:626)
> at clojure.core$load_libs.doInvoke(core.clj:5524)
> at clojure.lang.RestFn.applyTo(RestFn.java:137)
> at clojure.core$apply.invoke(core.clj:626)
> at clojure.core$require.doInvoke(core.clj:5607)
> at clojure.lang.RestFn.invoke(RestFn.java:436)
> at
> everbridge.mail_service$loading__4958__auto__.invoke(mail_service.clj:1)
> at clojure.lang.AFn.applyToHelper(AFn.java:152)
> at clojure.lang.AFn.applyTo(AFn.java:144)
> at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3553)
> at clojure.lang.Compiler.compile1(Compiler.java:7226)
> at clojure.lang.Compiler.compile1(Compiler.java:7216)
> at clojure.lang.Compiler.compile(Compiler.java:7292)
> at clojure.lang.RT.compile(RT.java:398)
> at clojure.lang.RT.load(RT.java:438)
> at clojure.lang.RT.load(RT.java:411)
> at clojure.core$load$fn__5066.invoke(core.clj:5641)
> at clojure.core$load.doInvoke(core.clj:5640)
> at clojure.lang.RestFn.invoke(RestFn.java:408)
> at clojure.core$load_one.invoke(core.clj:5446)
> at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
> at clojure.core$load_lib.doInvoke(core.clj:5485)
> at clojure.lang.RestFn.applyTo(RestFn.java:142)
> at clojure.core$apply.invoke(core.clj:626)
> at clojure.core$load_libs.doInvoke(core.clj:5524)
> at clojure.lang.RestFn.applyTo(RestFn.java:137)
> at clojure.core$apply.invoke(core.clj:626)
> at clojure.core$require.doInvoke(core.clj:5607)
> at clojure.lang.RestFn.invoke(RestFn.java:551)
> at everbridge.qa$loading__4958__auto__.invoke(qa.clj:1)
> at clojure.lang.AFn.applyToHelper(AFn.java:152)
> at clojure.lang.AFn.applyTo(AFn.java:144)
> at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3553)
> at clojure.lang.Compiler.compile1(Compiler.java:7226)
> at clojure.lang.Compiler.compile1(Compiler.java:7216)
> at clojure.lang.Compiler.compile(Compiler.java:7292)
> at clojure.lang.RT.compile(RT.java:398)
> at clojure.lang.RT.load(RT.java:438)
> at clojure.lang.RT.load(RT.java:411)
> at clojure.core$load$fn__5066.invoke(core.clj:5641)
> at clojure.core$load.doInvoke(core.clj:5640)
> at clojure.lang.RestFn.invoke(RestFn.java:408)
> at clojure.core$load_one.invoke(core.clj:5446)
> at clojure.core$compile$fn__5071.invoke(core.clj:5652)
> at clojure.core$compile.invoke(core.clj:5651)
> at user$eval9$fn__16.invoke(form-init2679087226527270250.clj:1)
> at user$eval9.invoke(form-init2679087226527270250.clj:1)
> at clojure.lang.Compiler.eval(Compiler.java:6703)
> at clojure.lang.Compiler.eval(Compiler.java:6693)
> at clojure.lang.Compiler.load(Compiler.java:7130)
> at clojure.lang.Compiler.loadFile(Compiler.java:7086)
> at clojure.main$load_script.invoke(main.clj:274)
> at clojure.main$init_opt.invoke(main.clj:279)
> at clojure.main$initialize.invoke(main.clj:307)
> at clojure.main$null_opt.invoke(main.clj:342)
> at clojure.main$main.doInvoke(main.clj:420)
> at clojure.lang.RestFn.invoke(RestFn.java:421)
> at clojure.lang.Var.invoke(Var.java:383)
> at clojure.lang.AFn.applyToHelper(AFn.java:156)
> at clojure.lang.Var.applyTo(Var.java:700)
> at clojure.main.main(main.java:37)
> Caused by: 

Re: Just found out about Elixirs function argument pattern matching...

2015-09-05 Thread Gary Verhaegen
It won't really help for the library/ecosystem problem, but for your own
code I'd recommend watching Jeanine Atkinson's Conj talk from last year:

http://m.youtube.com/watch?v=ZQkIWWTygio

On Saturday, 5 September 2015, Amith George  wrote:

> Nice. Hadn't heard of it before. It looks interesting. The criterium
> benchmark is kinda disappointing though. The pattern matched function took
> nearly 15x the time of the normal function.
>
> Performance aside, in Elixir, there seems to be an established convention
> for creating the function argument tuple. Every function can expect to be
> pattern matched against both :ok and :err. NodeJS callbacks also have
> follow a convention, error first, which would make it trivial to pattern
> match against. Goodbye to all those mundane `if (err) {} else {}` checks. I
> can't quite think of any similar conventions in Clojure.
>
>
>
> On Saturday, 5 September 2015 14:05:02 UTC+5:30, James Reeves wrote:
>>
>> You might want to take a look at defun:
>> https://github.com/killme2008/defun
>>
>> - James
>>
>> --
> 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: How can find something inside heavily nested data structure ?

2015-08-19 Thread Gary Verhaegen
If you want more specific answers, you'll need to describe the
structure of your tree. In particular, what is the relationship
between your conceptual nodes and your data structures (vectors and
maps)?

On 19 August 2015 at 17:26, Andy- andre.r...@gmail.com wrote:
 I have yet to evaluate it myself but this might do help you:

 https://github.com/nathanmarz/specter


 On Wednesday, August 19, 2015 at 10:18:06 AM UTC-4, Hussein B. wrote:

 Hi,

 I have transformed JSON response into the equivalent data structure using
 Cheshire library.

 The result is a huge nested data structure , mostly vectors and maps. It
 is actually a tree.

 How to find a property that is nested deep inside the tree ? For example
 I'm search for the node that has the value zyx for property uuid.

 What I'm supposed to use? Something like zipper or walk? or something
 simpler is available?

 Thanks for help.

 --
 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: How to transform this structure idiomaticlly in Clojure?

2015-08-18 Thread Gary Verhaegen
I'd do something like (untested):

(defn transform
  [node]
  (-Node (first node) (map transform (second node



On 18 August 2015 at 17:32, Hussein B. hubaghd...@gmail.com wrote:
 Hi,

 I have the following structure. Node has a string properly and a vector
 nodes and of course, each node has a string a property and a vector of
 nodes.

 So I created the following record:

 (defrecord Node [title childs])

 And I have the following JSON response:

 node
  string
  [
  node1 [
nn1
nn2
..
nnn]
  node2 [
nn1
nn2
..
nnn]
 ]

 What I want to achieve is to transform that JSON response into the
 equivalent structure with Node recored type.

 Thanks for help and time.

 --
 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 Truck Factor

2015-08-17 Thread Gary Verhaegen
On 17 August 2015 at 07:25, Jorge Branco jorge.d.f.bra...@gmail.com wrote:
 If a file has not been touched in two years, does it really
 matter who wrote it?

 I think that depending on the project and the kind of file, it does make a
 difference. One of the primary problems our team faced when working on a
 large brownfield enterprise project spanning several (distributed) teams was
 precisely that a lot of time new features would come up that required domain
 and technical knowledge about stuff written a long time ago. It was pretty
 common to find out that those file's authors were no long in the company so
 it was pretty painful to extend and implement features related to those
 areas of code. I'd say it was in at least some cases almost as costly as
 rewriting those portions from scratch.

It may be just me and my bad memory, but I'm not sure I would have an
easier time than anyone else if I had to go back and change code I
have written more than a year ago. That's what I meant: if the code is
old enough, even the original author will have to approach it with
essentially fresh eyes. (But, again, maybe it's just me.)

-- 
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: Is this resource only loaded once?

2015-08-14 Thread Gary Verhaegen
Once you've AOT compiled that (which is necessary for the class to be
actually generated), slurp won't be called again. Beware, however, that
`def` (and hence `slurp`) will be executed by the compiler, at compile
time, in the context (classpath, cwd, etc.) of the compiler, which may not
be what you want.

Note that you can easily test that by replacing your def with:

(def parser
  (do (println def parser executed)
  (slurp .)))

If you want the parser to be slurped once per execution, you can use an
atom and a function, something like:

(let [p (atom nil)]
  (defn parser
[]
(swap! p (fn [p] (if (nil? p) (slurp ) p)

You can then access your parser with (parser), which will only slurp the
file once. (If it matters, there are alternatives that will not keep on
paying the atom update cost.)



On 14 August 2015 at 10:59, Thomas Goossens cont...@thomasgoossens.be
wrote:

 When a java class uses the compiled Test (gen-class) from test namespace.
 Everytime the static function -run is called, will parser be slurped again
 or only once ?

 (ns test  (:gen-class   :name Test   :methods [ ^:static [run
 [] String]))  (def parser (slurp ..))

 (defn -run [] ;... do something with parser )



 --
 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 Truck Factor

2015-08-14 Thread Gary Verhaegen
Hi Guilherme,

I am not a Clojure developer (I only use it), so maybe I'm speaking
out of line. I would first like to thank you for the initiative; as an
industry, I believe we direly need more quantitative, scientific
studies of our practices, so I'm really happy to see this.

There is of course a lot of social dynamics that cannot be captured
from code commits alone. For example, if Rich was to step down (for
whatever reason), I would be much more worried about the direction of
the project than about the technical skills required to understand and
grow the code base: to my somewhat external eyes, Rich's role of
refusing contributions and setting a clear direction for the language
is at least as important as any code he writes himself. I love Clojure
because it's clear, from usage, that there is a single, strong,
unified vision behind it. I'm not saying nobody shares Rich's
aesthetics, but at the very least it would take time for any
replacement to earn the social authority that Rich has (it is, after
all, his language).

As for the truck factor computation, have you considered weighing the
relative importance of different files in a project? Something like
the inverse of churn, or taking into account the last modification
date? If a file has not been touched in two years, does it really
matter who wrote it? Even the author will probably need to read it
very carefully should there ever be a need to change it.

-- 
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: Size of Java serialized Clojure data structures

2015-08-07 Thread Gary Verhaegen
You should probably look at Clojure-specific solutions, starting with EDN
(i.e. essentially pr-str), fressian, transit or nippy.

Clojure data structures have a lot of properties that can be exploited (we
only care about the abstract type and the actual data), so a serializer can
make a lot of assumptions that a generic Java solution can't.

On Friday, 7 August 2015, icamts ica...@gmail.com wrote:

 Hi all,
 I opened this issue on github project prevayler-clj

 https://github.com/klauswuestefeld/prevayler-clj/issues/1

 because 1M short vectors, like this [:a1 1], forming the state of the
 prevayler, results in 1GB file size when serialized, one by one, with Java
 writeObject.

 Is it possible? About 1kB for each PersistentVector? Further
 investigations demonstrated the same amount of vectors can be serialized in
 a 80MB file. So, what's going wrong in prevayler serialization?

 Any suggestion is welcome. Thanks in advance.

 Luca

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Reality check: EC2 + Ubuntu + Atom (from GitHub) + Clojure?

2015-08-07 Thread Gary Verhaegen
Sorry for steering the discussion away from tooling, but have tou looked at
Racket and the research in teaching programming that's been going on around
it for the past ~20 years?

One of their findings was that beginning with functional programming (1
semester FP followed by 1 semester OOP) yielded better OOP prpgrammers than
a full year of OOP teaching. Some of them have recently branched out from
the original scheme-base syntax to a more python-like one. If you're
designing a curriculum for teaching FP and OOP I believe it's worth
investigating.

And to steer back towards tooling, you could then use DrRacket, which is a
fantastic beginner's editor with debugger and code analyzer integrated.

On Friday, 7 August 2015, Colin Fleming colin.mailingl...@gmail.com wrote:

 Note that IntelliJ will actually do Python and Clojure in the same (free,
 OSS) IDE if you only need the community edition of Python, i.e. you don't
 need support for frameworks like Django or the web stuff.

 If you do need the Ultimate edition of IntelliJ, you can get free licences
 for open source and/or academic work by applying to JetBrains.

 On 7 August 2015 at 01:26, kirby urner kirby.ur...@gmail.com
 javascript:_e(%7B%7D,'cvml','kirby.ur...@gmail.com'); wrote:


 To recap this thread:  I started by looking at GitHub's Atom as an IDE
 for
 Asynchronous Learning Engine (ALE), a name I'm using for an
 Open Source project.  I'm interested in Clojure + Java + Python as
 an example flight path through our curriculum space.

 Turns out Eclipse is a strong candidate if a single IDE is required.

 IntelliJ with Cursive is where I'm starting, great beginning!  I use
 PyCharm at work.

 I now have Python and Clojure both implementing a special kind
 of vector class using PyDev for Python and CounterClockwise
 for Clojure:

 http://mybizmo.blogspot.com/2015/08/eclipse-for-python-java-clojure.html

 Just screen shots at this point.

 I'm finding much to like in the ease of use department.

 Eclipse remains a strong contender though of course Emacs can do all this
 too.

 Kirby


 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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, WEB and Enterprise development

2015-08-06 Thread Gary Verhaegen
I'm not sure I understand the problems here, but if you really want to wrap
a Java library that generates a web layer, I'd suggest looking at Vaadin
rather than GWT.

Though as others have said I do not clearly see what kind of problems you
have with the current solutions (immutant, om, etc.).

On Thursday, 6 August 2015, Alexander Hudek a...@kirasystems.com wrote:

 Immutant provides a lot of enterprisy things out of the box.

 On Wednesday, August 5, 2015 at 5:28:02 PM UTC-4, Olek wrote:

 Hi!

 I was using Clojure for a long time. It has been used for private and
 commercial projects (sniffed by me and hated by others).

 Now it has been abandoned. It's not giving me any money nor there is no
 agreement in peers to use it.

 But...


 I think that Clojure has a future. Datomic is ready for new Intel mass
 storage (which is 1000 times faster than current SSD). Clojure as lisp is a
 head of time for most today programing paradigms.

 But


 I'm disappointed by few things:


 Problem: there is no a bind for the JEE servers - they should be treated
 as the SQL - you will never reach its maturity

 Solution: so you should parasite it and make a wrapper around timed
 services, jms queues, web services, ejb, jpa (with changed semantic fitting
 to clojure style)

 My try: I have already build some prototype for building web services in
 runtime (with build in http server in jdk)


 Problem: there is still no true web layer - all what you can see is a
 wrap around Servlet and HTTP protocol concept or own semantic around WWW

 Solution: you should try to build a layer around GWT or Java Prime Faces,
 I know that now it is not possible, but you should think what steps are
 needed to achive that

 My try: I have build and framework which abstracts from the system domain
 in GUI and the server side conforms it's protocol (what contexts as tabs,
 CRUD, contextual operations, elastic permissions - tab context and data
 context, dialogs for CRUD, filters for listing, tables, dynamic forms
 modification, validation) all was made first in Clojure and the spec of DSL
 could produce Swing app, the same spec later could produce GWT app (for
 known reasons the engine had to be rewritten in Java but spec could be
 still Clojure data or XML)

 The GUI engine is so abstract that Web Layer could switch between backend
 system and provide all the GUI functionality as needed - the limit is that
 it was ordinary a CRUD app (card management system; football cards
 management and bans system; CAR system with conjunction with EJBCA; user
 and persmission managment system; lottery systems - all there where
 registration system fits)


 Let the big business promote you potential and left for yourself only the
 evangelism of the Clojure language...

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: What Counted interface is for?

2015-08-04 Thread Gary Verhaegen
I don't know of it is correct, but I also remember reading that Counted was
a marker interface, i.e. it does not actually add any method but it
implies that the count operation will be fast.

On Tuesday, 4 August 2015, Laurent PETIT laurent.pe...@gmail.com wrote:

 If I'm remember correctly, the Counted interface must only be implemented
 by collection implementations for which it is guaranteed that count() is an
 O(~1) operation

 2015-08-04 17:07 GMT+02:00 Keisuke Fukuda keisukefuk...@gmail.com
 javascript:_e(%7B%7D,'cvml','keisukefuk...@gmail.com');:

 Hello,

 I've been investigating the basic data structures and their underlying
 concepts in Clojure, particularly focusing on the definitions of coll, seq,
 map, vector, set, etc. and their inclusion relationships.

 I saw a Venn diagram in this page[1]. Although it is as of Clojure 1.3, I
 confirmed it is still correct. Counted interface has its only method
 count() and it implies that we can get the explicit size of a Counted
 collection.

 However, IPersistentCollection, which is actually the definition of
 collections, also has count() method. It's a bit surprising to me that even
 LazySeq supports count() (indirectly via ISeq).

 Questions:
 If IPersistentCollection has count() method, What is Counted for?
 Is it always reasonable for LazySeq to support count() method? Shouldn't
 there be an explicit CountedLazySeq,

 Thanks.
 Keisuke

 [1] http://www.brainonfire.net/files/seqs-and-colls/main.html


 --
 FUKUDA, Keisuke 福田圭祐
 Tokyo, Japan
 Email: keisukefuk...@gmail.com
 javascript:_e(%7B%7D,'cvml','keisukefuk...@gmail.com');

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');.
 For more options, visit https://groups.google.com/d/optout.




 --
 Laurent Petit

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: [ANN] Release 0.32.0 of Counterclockwise

2015-07-30 Thread Gary Verhaegen
I'm all for increasing the visibility of women in technology and for trying
to avoid simplistic assimilations like programmer = male, but in this
case I think it's more like a simplistic ends in a = female on your part,
and I'm afraid Laurent did not make a grammatical mistake:

https://github.com/arichiardi

On Thursday, 30 July 2015, Fluid Dynamics a2093...@trbvm.com wrote:

 On Thursday, July 30, 2015 at 5:43:39 AM UTC-4, Laurent PETIT wrote:

 I have forgotten to thank Andrea Richiardi for his involvement in this
 release content.

   ^^   ^^^
 Syntax error, line 1: Clauses do not agree as to grammatical gender.

 Typo somewhere?

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: [ANN] Pink 0.2.0, Score 0.3.0

2015-07-29 Thread Gary Verhaegen
There's http://m.youtube.com/watch?v=wDcN7yoZ6tQ, though I guess it does
not cover the latest features in this release.

On Wednesday, 29 July 2015, zcaudate z...@caudate.me wrote:

 This is so cool =)

 Can you put up a video?

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Twitter bot crashing on Heroku

2015-07-27 Thread Gary Verhaegen
the error message also sugget that your process may not have started
quickly enough. How do you deploy on heroku? Do you have a Procfile? What
does it say? Do you prepackage on push, or recompile everything on startup?

On Monday, 27 July 2015, Divyansh Prakash divyanshprakas...@gmail.com
wrote:

 Hi!

 I had written a poetry generator http://yushing.herokuapp.com/ sometime
 back and wanted to convert it into a Twitter bot.
 I followed this tutorial https://howistart.org/posts/clojure/1 to do
 so. You can find my code here https://github.com/divs1210/yushing-bot.

 The bot's working fine from my local machine, but sporadically crashes on
 Heroku with the following message:

 2015-07-27T10:23:06.574908+00:00 heroku[web.1]: Error R10 (Boot timeout)
 - Web process failed to bind to $PORT within 60 seconds of launch
 2015-07-27T10:23:06.574908+00:00 heroku[web.1]: Stopping process with
 SIGKILL
 2015-07-27T10:23:07.550373+00:00 heroku[web.1]: Process exited with
 status 137
 2015-07-27T10:23:07.561392+00:00 heroku[web.1]: State changed from
 starting to crashed


  Some answers on SO suggest that this is because Heroku already provides a
 port to bind to and I might be trying to bind to some other port, but this
 is not the 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Twitter bot crashing on Heroku

2015-07-27 Thread Gary Verhaegen
Just peeked at your code, and it seems to indeed compile everything at
startup. I'm not quite remembering all of the details, but I remember that
Chestnut got it right: on Heroku, you can set things up so that an uberjar
is created on git push and then started with java -jar on startup, which is
usually much faster. See for example:

https://github.com/plexus/chestnut/blob/master/src/leiningen/new/chestnut/Procfile

I *think* it was enough to declare an :uberjar-name entry in the
prpject.clj to trigger that behaviour on Heroku, but I am not quite sure.
You'll have to experiment a bit (or hope someone else can answer more
definitely).

On Monday, 27 July 2015, Gary Verhaegen gary.verhae...@gmail.com wrote:

 the error message also sugget that your process may not have started
 quickly enough. How do you deploy on heroku? Do you have a Procfile? What
 does it say? Do you prepackage on push, or recompile everything on startup?

 On Monday, 27 July 2015, Divyansh Prakash divyanshprakas...@gmail.com
 javascript:_e(%7B%7D,'cvml','divyanshprakas...@gmail.com'); wrote:

 Hi!

 I had written a poetry generator http://yushing.herokuapp.com/
 sometime back and wanted to convert it into a Twitter bot.
 I followed this tutorial https://howistart.org/posts/clojure/1 to do
 so. You can find my code here https://github.com/divs1210/yushing-bot.

 The bot's working fine from my local machine, but sporadically crashes on
 Heroku with the following message:

 2015-07-27T10:23:06.574908+00:00 heroku[web.1]: Error R10 (Boot timeout)
 - Web process failed to bind to $PORT within 60 seconds of launch
 2015-07-27T10:23:06.574908+00:00 heroku[web.1]: Stopping process with
 SIGKILL
 2015-07-27T10:23:07.550373+00:00 heroku[web.1]: Process exited with
 status 137
 2015-07-27T10:23:07.561392+00:00 heroku[web.1]: State changed from
 starting to crashed


  Some answers on SO suggest that this is because Heroku already provides
 a port to bind to and I might be trying to bind to some other port, but
 this is not the 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.



-- 
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: What is the best way to pass log configs everywhere without a global var?

2015-07-27 Thread Gary Verhaegen
Have you guys looked at dire?

https://github.com/MichaelDrogalis/dire/blob/master/README.md

it could be used to take decomplection one step further, by not defining
monitoring things inline at all. A library author could define additional
logging namespace(s) with fns that load different levels of logging.

On Monday, 27 July 2015, Colin Yates colin.ya...@gmail.com wrote:

 I don’t have a proof of concept either but if somebody is going to put
 some effort into writing a new library I had a great idea they could
 incorporate. Continuing the ‘decomplecting’ that James started, the other
 thing that is decomplected (or actually not addressed at all) is _why_ we
 want logging to be produced. For me, I often want to see WARNING and above
 all the time and only see INFO and below if something interesting happened.
 ‘Interesting’ typically being an exception happened.

 My notion was to add an adapter which at some point (e.g. around the
 use-case service/transaction boundary) started collecting all the logs
 in-memory and if the service executed correctly would simply drop the INFO
 and below messages. However, if the service aborted (e.g. threw an
 Exception) only then would the INFO and below logs get written to disk.

 It’s so simple and useful I can’t believe nobody else has already written
 it. My excuse is good old time. Clojure, Agents, robert-hooke - couldn’t be
 easer.


 On 27 Jul 2015, at 08:28, crocket crockabisc...@gmail.com
 javascript:_e(%7B%7D,'cvml','crockabisc...@gmail.com'); wrote:

 Can I see your proof of concept on github? Is it just an idea?

 On Mon, Jul 27, 2015 at 2:27 PM, James Reeves ja...@booleanknot.com
 javascript:_e(%7B%7D,'cvml','ja...@booleanknot.com'); wrote:

 On 27 July 2015 at 05:25, crocket crockabisc...@gmail.com
 javascript:_e(%7B%7D,'cvml','crockabisc...@gmail.com'); wrote:


 How those logs are outputted is stored in a global state called log
 configuration. So, I think the separation was done.
 How else do you want to separate that?



 Traditionally, logging code is written something like:

(log/info HTTP request to (:request-method req) (:uri req))

 So the priority of the log (info) and the formatting of the log line is
 inlined into the source code.

 A less complected piece of code would separate out what we want to monitor
 (req) from how we monitor it. So inline we just write:

(monitor/monitor req :ring/request)

 This monitors the variable req and associates it with the namespaced
 keyword
 :ring/request. In our logging namespace, we can then later define how we
 want to report on that monitor:

(monitor/add-reporter
 :ring/request
 (fn [req] (log/info HTTP request to (:request-method req) (:uri
 req

 This separates *what* we want to monitor from *how* we eventually log it.
 It
 means we can do things like define a set of useful monitoring points in a
 library, and then in a separate application decide on what's important.

 - James

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/9YiGAp6axcY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 clojure+unsubscr...@googlegroups.com
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 

Re: WebService request are not getting served properly

2015-07-27 Thread Gary Verhaegen
On Monday, 27 July 2015, hemant gautam gomze...@gmail.com wrote:

 On running the below mentioned code on browser I am getting Page not
 found for each type of request.
 Can anybody suggest me where I am doing a mistake.

 (ns currentday.core
 (:require [compojure.core :refer :all]
   [compojure.route :as route]
   [compojure.handler :as handler]
   [ring.middleware.defaults :refer :all]
   [ring.util.response :refer :all])
 (:use ring.adapter.jetty))

 (defn now []
   (new java.util.Date))

 (defn say-hello []
Hello!! everyone. I am home page of webservice.)

 (defn date-is [req]
   Today's date is:  (str (now)))

 (defn get-date [req]
(- (response (date-is))
(content-type text/html)))

 (defn add-data [a b]
(- (response Sum of two no. is: (str (+ a b)))
(content-type text/html)))

 (defn sub-data [a b]
(- (response Subtraction of two no. is: (str (- a b)))
(content-type text/html)))

 (defroutes my-routes
   (GET / [] Hello)
   (GET /date req (get-date [req]))
   (GET /add/:a/:b [a b] (add-data a b))
   (GET /sub/:a/:b [a b] (sub-data a b))
   (route/not-found Page not found))

 (def app
   (handler/site my-routes))

 (defonce server (run-jetty #'app {:port 3032 :join? false}))


I'm not in a position to actually try that code, so I'm shooting blind.
Here are a few comments:

* You do not seem to be using the ring.middleware.defaults, but instead use
the deprecated compojure.handler ns.
* Your say-hello function is not used.
* Your / route returns a String, which as far as I know is not a valid
ring response. Try with {:status 200 :body Hello!} instead of just a
string?
* Your add and subtract handlers look like they should throw exceptions, as
you're calling response with 2 args and it's defined to receive a single
string argument.
* From what I see here, I do not see any reason why the /date route does
not work.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Java 8 Lambda Interop

2015-07-27 Thread Gary Verhaegen
On Sunday, 26 July 2015, Andrew Oberstar ajobers...@gmail.com wrote:

 Hi,

 I'm wondering if anyone has a good approach for making calls from Clojure
 to Java APIs (e.g. Stream API) that expect a @FunctionalInterface type.

 Ideally, IFn would transparently work, but I'm guessing that requires some
 compiler changes.

 Right now, the best I can think of is a function or macro to reify a
 wrapper around a Clojure function to implement all of the usual interfaces
 from java.util.function.

 Anyone have any better ideas?

 Andrew Oberstar


You're probably aware of this, but @FunctionalInterface is not a type, it's
an annotation. All it does is ensure, at compile time, that the annotated
element is an interface with a single non-default and non-static method. At
the type-system level, it's just an interface like any other, and the
lambda syntax is just a shorthand for an anonymous instance of a
well-defined type.

Since the lambda syntax is java-compiler magic, you can't access it from
Clojure, and the most straightforward option right now is to actually know
which type is expected, e.g.:

user= (- (doto (java.util.ArrayList.) (.add 1) (.add 2)) (.stream) (.map
(reify java.util.function.Function (apply [_ arg] (inc arg (.collect
(java.util.stream.Collectors/toList)))
[2 3]
user=

As neither IFn nor Function are Clojure protocols, I do indeed think you're
best bet is a macro to essentially generate the above reify. You can of
course do a single macro that reifies to all of the protocols that you need.

I don't think it's realistic to hope that IFn will cover any arbitrary
@FunctionalInterface, as that is Java compiler magic. It may, in the
future, be extended to cover all of the standard ones in
java.util.function, or even all the ones in the standard library, but it's
not going to happen until Java 7 support is dropped. I guess the best you
could hope for in the short term would be to have IFn changed to a protocol.

-- 
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: 2 way transform in single definition ? unification ?

2015-07-13 Thread Gary Verhaegen
Have you already looked at core.logic?

On Monday, 13 July 2015, craig worrall craig.worr...@transacumen.com
wrote:

 You may have already discounted Java versions, but just in case  ...
 http://www.javacodegeeks.com/2013/10/java-object-to-object-mapper.html

 Craig

 On Monday, July 13, 2015 at 3:53:19 AM UTC+10, Jules wrote:

 Guys,

 I have an external and an internal data representation.

 I need to define transforms both ways.

 Both models are structured.

 A pair of in/out functions might look like:

 (fn [{{b :b c c:} :a}] [b [c]])

 (fn [[b [c]] {:a {:b b :c c}})

 I just typed that OTTOMH so please forgive any mistakes.

 I have about 50 of these to define and maintain and I may have further
 representations to map to in the future.

 My question - Is there a library that will allow me to define the
 relationship between the two representations declaratively and then
 generate the transform functions from that single src.

 Ideally it would allow me to extend it to construct/destructure e.g.
 joda-time class instances etc as some of my internal rep uses these.

 It feels a bit like unification in PROLOG...

 Looking forward to hearing your ideas.

 regards,


 Jules

  --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: 2 way transform in single definition ? unification ?

2015-07-13 Thread Gary Verhaegen
I have not used it. I'm mentioning it because you mentioned unification and
prolog and because you basically want a two-way function, which is what was
touted as the ideal use-case for core.logic when it was heavily discussed
on this list a few months (years?) ago.

I'm not aware of the details of the performance tradeoffs, though. I
imagine it would be slower than writing both functions by hand, but I have
no idea how much.

On Monday, 13 July 2015, Jules jules.gosn...@gmail.com wrote:

 I haven't.

 Are you just suggesting it because I mentioned unification, or have you
 used it and know that it might be a good fit ?

 Thanks,

 Jules

 On Monday, 13 July 2015 10:37:55 UTC+1, Gary Verhaegen wrote:

 Have you already looked at core.logic?

 On Monday, 13 July 2015, craig worrall craig@transacumen.com wrote:

 You may have already discounted Java versions, but just in case  ...
 http://www.javacodegeeks.com/2013/10/java-object-to-object-mapper.html

 Craig

 On Monday, July 13, 2015 at 3:53:19 AM UTC+10, Jules wrote:

 Guys,

 I have an external and an internal data representation.

 I need to define transforms both ways.

 Both models are structured.

 A pair of in/out functions might look like:

 (fn [{{b :b c c:} :a}] [b [c]])

 (fn [[b [c]] {:a {:b b :c c}})

 I just typed that OTTOMH so please forgive any mistakes.

 I have about 50 of these to define and maintain and I may have further
 representations to map to in the future.

 My question - Is there a library that will allow me to define the
 relationship between the two representations declaratively and then
 generate the transform functions from that single src.

 Ideally it would allow me to extend it to construct/destructure e.g.
 joda-time class instances etc as some of my internal rep uses these.

 It feels a bit like unification in PROLOG...

 Looking forward to hearing your ideas.

 regards,


 Jules

  --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Creating jar specific defaults

2015-07-03 Thread Gary Verhaegen
You're probably using clojure.java.io/file (looks for files on the
filesytem) instead of clojure.java.io/resource (looks for files in the
classpath).

On 20 June 2015 at 16:41, Timur timurha...@gmail.com wrote:
 Hi everyone,

 I want to specify some defaults for a library that I pack as a jar, for
 instance standard port a server. It should be read from a property file in
 the respective jar file automatically. However,  when I include a jar in my
 class path, the file is not loaded from the included jar path but rather
 from the path of the parent application. What would be the best practice to
 specify jar specific constants. Should I define them in the source code?

 Thanks in advance!

 --
 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: Joda Time version conflict? Initializing JollyDayHoliday for SUTime

2015-06-30 Thread Gary Verhaegen
Also, your last error (about in-ns) is from an incompatible version of
clj-time, not joda-time.

By the way, this has nothing to do with interop, it's straight dependency
management on the jvm.

Concerning FD's solution of classloaders, you'll also jave to figure out a
way to package the different versions into your JAR, which will not be
trivial if both versions use the same package names (which seem to be the
case).

I think your best bet at this point is to carefully read the lein deps
:tree output to note all of the required versions of clj-time and jodatime,
and then try to play with either excludes or version ponning in your
project.clj until you find a combination that works. Also remember that
your code is the most flexible: are you absolutely stuck using clj-time
0.6.0 for your own code ?

On Tuesday, 30 June 2015, Sean Corfield s...@corfield.org wrote:

 Have you actually tried any of the exclusions that Leiningen suggests? For
 example:

 [clj-time 0.6.0]
  overrides
 [ring 1.4.0-RC1] - [ring/ring-jetty-adapter 1.4.0-RC1] -
 [ring/ring-core 1.4.0-RC1] - [clj-time 0.9.0]
  and
 [ring 1.4.0-RC1] - [ring/ring-devel 1.4.0-RC1] - [ring/ring-core
 1.4.0-RC1] - [clj-time 0.9.0]
  and
 [ring 1.4.0-RC1] - [ring/ring-core 1.4.0-RC1] - [clj-time 0.9.0]

 Consider using these exclusions:
 [ring 1.4.0-RC1 :exclusions [clj-time]]
 [ring 1.4.0-RC1 :exclusions [clj-time]]
 [ring 1.4.0-RC1 :exclusions [clj-time]]

 This tells you to that Ring is pulling in the later version of clj-time
 (and, hence, the Joda Time 2.6) but clj-time 0.6.0 is pulling in 2.2 (next
 set of suggested exclusions). The suggestion is to add the exclusions to
 your Ring dependency:

 [ring 1.4.0-RC1 :exclusions [clj-time joda-time]]

 See if that helps.

 Sean

 On Jun 29, 2015, at 5:17 PM, gingersafflo...@gmail.com
 javascript:_e(%7B%7D,'cvml','gingersafflo...@gmail.com'); wrote:


  If the worst comes to the worst, you may need to run the NLP module
  and the Clojure code in separate JVMs using some form of IPC to exchange
 data.

 That is what I'm looking at right now, though I've also been told that I
 absolutely must have this working by tomorrow morning, so I'm a little
 frustrated with the amount of work I face tonight. Also, a month ago we
 were doing IPC and then we gave up on that redesigned the NLP to work as a
 library we could embed inside of the Clojure app, but now it looks like we
 need to reverse that decision.

 For me, it's been a good reminder that easy Java interop is true up to a
 point, but then very not true for certain kinds of ambitions.



 On Monday, June 29, 2015 at 7:18:07 PM UTC-4, Fluid Dynamics wrote:

 On Monday, June 29, 2015 at 6:38:40 PM UTC-4, Gary Verhaegen wrote:

 Assuming there is a version that works for both dependencies, you can
 manually fix it in your own project.clj. Your own direct dependencies
 will override transitive ones.

 Otherwise, as far as I can tell, you're stuck. Maybe you can try using
 an older clj-time?


 In theory, JodaTime 2.6 should not have any API-breaking changes since
 2.1, or they should have called it 3.something.

 So, if you can force the NLP module to use JodaTime 2.6 it *should* work.

 If that fails, it may still be possible if you can force the two versions
 of JodaTime to load in separate classloaders. I haven't the foggiest how
 that might actually be achieved. Actually I'm somewhat surprised that the
 Java NLP component and clj-time are not *already* loading in different
 classloaders, the former in the standard Java classloader and the latter in
 Clojure's DynamicClassLoader. Two different versions of the same Java
 package or Clojure namespace can *usually* coexist peacefully in different
 classloaders, though, modulo native dependencies or centralized filesystem
 stuff (e.g. a single .foo file in the user directory that they both modify,
 stepping on each others' toes, and they can't be overridden to look for
 separate files to each keep their own version).

 If the worst comes to the worst, you may need to run the NLP module and
 the Clojure code in separate JVMs using some form of IPC to exchange data.
 Then deployment, startup, and shutdown become more complicated and
 annoying, and communication across the divide much less efficient (like
 kernel mode switching, IPC means carting data across address space
 boundaries), so ideally there'd be a clean internal boundary between the
 NLP-parts and the rest that has relatively little traffic crossing it.
 You'd then end up with a kind of NLP daemon and an application that had a
 dependency on it.



  --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D

Re: Joda Time version conflict? Initializing JollyDayHoliday for SUTime

2015-06-29 Thread Gary Verhaegen
Assuming there is a version that works for both dependencies, you can
manually fix it in your own project.clj. Your own direct dependencies
will override transitive ones.

Otherwise, as far as I can tell, you're stuck. Maybe you can try using
an older clj-time?

On 29 June 2015 at 21:00,  gingersafflo...@gmail.com wrote:


 I think I have a conflict involving different libraries using different
 versions of JodaTime. I have no idea how to fix this.

 I have nearly the same problem as this:

 http://stackoverflow.com/questions/21487476/maven-build-throws-jodatime-exception-at-runtime

 However, in my case, I'm building a web app in Clojure, whereas my co-worker
 is building our Natural Language Processing engine in Java. The NLP is
 included as a jar. We had this working for a few weeks, but my co-worker has
 added some new dependencies that are now giving us this error.

 This person also reports a similar error:

  Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

 See here:

 http://mail.wso2.org/mailarchive/dev/2014-September/035337.html

 with an answer here:

 http://mail.wso2.org/mailarchive/dev/2014-September/035341.html

 The issue in both cases seems to be a version conflict in different
 libraries, but I have no idea how to resolve this. In the Clojure app we use
 clj-time, which apparently uses Joda-Time 2.6, whereas the Stanford Core NLP
 libraries seem to use Joda 2.1. Is there anyway to resolve that conflict?

 Both pieces of software compile, and the Clojure app can start, with the NLP
 engine included. However, the Clojure app then calls a start method in the
 NLP engine, which causes the NLP engine to load the lexers and parsers that
 it needs. We then get these messages and errors:

 Loading classifier from
 /home/safflower/apricots/dependencies/english.muc.7class.caseless.distsim.crf.ser.gz
 ... done [1.5 sec].

 Loading parser from serialized file
 edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ...  done [0.3 sec].

 Loading parser from serialized file
 edu/stanford/nlp/models/lexparser/englishPCFG.caseless.ser.gz ...  done [1.1
 sec].

 Adding annotator tokenize

 TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.

 Adding annotator ssplit

 Adding annotator pos

 Reading POS tagger model from
 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger
 ... done [1.9 sec].

 Adding annotator lemma

 Adding annotator ner

 Loading classifier from
 /home/safflower/apricots/dependencies/english.all.7class.distsim.crf.ser.gz
 ... done [1.5 sec].

 Initializing JollyDayHoliday for SUTime from classpath:
 edu/stanford/nlp/models/sutime/jollyday/Holidays_sutime.xml as
 sutime.binder.1.
 #ReflectionLoadingException
 edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error
 creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

 Exception in start/start:
 edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error
 creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

 If I do this in the Java app:

 mvn dependency:tree

 I see this:

 [INFO] |  +- joda-time:joda-time:jar:2.1:compile
 [INFO] |  \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
 [INFO] +- log4j:log4j:jar:1.2.17:compile
 [INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
 [INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
 [INFO] +- junit:junit:jar:3.8.1:test
 [INFO] +- net.sf.supercsv:super-csv:jar:2.0.0-beta-1:compile
 [INFO] +- org.apache.commons:commons-lang3:jar:3.0:compile
 [INFO] \- edu.stanford.nlp:stanford-corenlp:jar:3.5.2:compile
 [INFO]+- com.io7m.xom:xom:jar:1.2.10:compile
 [INFO]|  +- xml-apis:xml-apis:jar:1.3.03:compile
 [INFO]|  +- xerces:xercesImpl:jar:2.8.0:compile
 [INFO]|  \- xalan:xalan:jar:2.7.0:compile
 [INFO]+-
 com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
 [INFO]\- javax.json:javax.json-api:jar:1.0:compile

 If I do this in the Clojure app:

 lein deps :tree

 I see this:

 Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.pom from central
 Retrieving
 clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.pom from
 clojars
 Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.jar from central
 Retrieving
 clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.jar from
 clojars
 Possibly confusing dependencies found:
 [slingshot 0.10.3]
  overrides
 [clj-http 1.1.2] - [slingshot 0.12.2 :exclusions [org.clojure/clojure]]

 Consider using these exclusions:
 [clj-http 1.1.2 :exclusions [slingshot]]

 [clj-time 0.6.0]
  overrides
 [ring 1.4.0-RC1] - [ring/ring-jetty-adapter 1.4.0-RC1] -
 [ring/ring-core 1.4.0-RC1] - [clj-time 0.9.0]
  and
 [ring 1.4.0-RC1] - [ring/ring-devel 1.4.0-RC1] - [ring/ring-core
 1.4.0-RC1] - [clj-time 0.9.0]
  and
 [ring 1.4.0-RC1] - [ring/ring-core 1.4.0-RC1] - [clj-time 0.9.0]

 Consider using these exclusions:
 [ring 1.4.0-RC1 :exclusions [clj-time]]
 [ring 

Re: Basic question: what's the difference between require as and use as?

2015-06-23 Thread Gary Verhaegen
Unless you have a very compelling reason, just don't use use. It's mostly a
historical accident that's kept there for backwards compatibility.

And try to avoid :refer :all if possible. There are legitimate use-cases
for it, but outside the REPL they are pretty rare.

On Tuesday, 23 June 2015, Ritchie Cai ritchie...@gmail.com wrote:

 Ah, I see. I thought “use :as” will not intern all the symbols into
 current namespace, apparently that’s not the case.
 Thanks for clearing this up.

 Ritchie

  On Jun 22, 2015, at 4:52 PM, Sean Corfield s...@corfield.org
 javascript:; wrote:
 
  On Jun 22, 2015, at 2:39 PM, Ritchie Cai ritchie...@gmail.com
 javascript:; wrote:
  Ok, so require without :refer will default to :refer :all?
 
  No.
 
  (:use [clojure.java.io]) is equivalent to (:require [clojure.java.io
 :refer :all])
 
  There’s no :as here. :use is like :require :refer :all.
 
  (:use [clojure.java.io :as io]) is equivalent to (:require [
 clojure.java.io :as io :refer :all])
 
  There’s an :as in both here. :use :as is like :require :as :refer :all
 
  Both :use and :refer :all (in :require) are discouraged because they
 pollute your namespace with every symbol from the used/required namespace.
 
  There’s not much point in specifying an alias (with :as) for :use or
 :require :refer :all since those bring in every symbol directly anyway.
 
  Sean Corfield -- (904) 302-SEAN
  An Architect's View -- http://corfield.org/
 
  Perfection is the enemy of the good.
  -- Gustave Flaubert, French realist novelist (1821-1880)
 
 
 
  --
  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
 javascript:;
  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 javascript:;
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to a topic in the
 Google Groups Clojure group.
  To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/ned76MpB-W0/unsubscribe.
  To unsubscribe from this group and all its topics, send an email to
 clojure+unsubscr...@googlegroups.com javascript:;.
  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
 javascript:;
 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 javascript:;
 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 javascript:;.
 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: How to share the large files that can not fit in Github?

2015-06-23 Thread Gary Verhaegen
There is also a git annex command. I have not use it personally, but my
understanding is that it is essentially keeping a hash of the file (and
perhaps a url to download it?) in source control in git, without adding the
file itself.

That way git can tell when the file has changed, without polluting the git
repo itself.

On Monday, 22 June 2015, Daniel Jomphe danieljom...@gmail.com wrote:

 Since you mentioned GitHub, have you looked at Git Large File Storage?

 https://github.com/blog/1986-announcing-git-large-file-storage-lfs

 On Monday, June 22, 2015 at 4:09:31 PM UTC-4, Mohit Thatte wrote:

 AWS S3 is a great place to put large files
 https://aws.amazon.com/blogs/aws/amazon-s3-object-size-limit/. You can
 use S3 sync
 http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html  to keep
 things current.

 ~Mohit

 On Mon, Jun 22, 2015 at 9:34 PM, Lawrence Krubner 
 lawr...@rollioforce.com wrote:


 This is more of Java eco-system/development question, but I am curious
 what folks in the Clojure community might regard as best practice. Up
 till now most of the projects that I've worked on we've been able to share
 resources informally via scp and email, or via Github, but on the current
 project we are dealing with a lot of massive files, over 100 megs, many
 over a gig. These are things such as Natural Language Processing
 classifiers/dictionaries, many of which are huge. We need to have them
 available on our machines so we can do development work. We're trying to
 figure a way such that when we add new paths or new files we can tell each
 other, or find a way that they can do something similar to git fetch
 origin and see what changes have happened.

 How do others handle this?




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




 --
 -Mohit Thatte

  --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: stuartsierra/component is oop, can clojure namespace self init to solve the dependencies?

2015-06-18 Thread Gary Verhaegen
OOP does not mean mutab... erh... anything, really, but there is an
argument to be made for calling an immutable blob that carries data and the
operations to act on it an immutable object. If every mutative
operation returns a modified copy of the object, you can have immutable OOP.

On Thursday, 18 June 2015, Atamert Ölçgen mu...@muhuk.com wrote:

 How is stuartsierra/component OOP when it is building an immutable object
 graph? (Contrast that to Guava etc.)

 On Thu, Jun 18, 2015 at 5:15 AM, Xiangtao Zhou tao...@gmail.com
 javascript:_e(%7B%7D,'cvml','tao...@gmail.com'); wrote:

 hi guys,

 Constructing simple clojure project is trival, just make functions. if
 the project grows large, with more datasources, message queue, and other
 storages, dependencies problem is on the table.

 One solution is stuartsierra/component,  using system to configure
 dependencies graph, make component and dependencies resolution separate.

 If we make namespace must run with code block that init the namespace,
 like the start method in component, is this a good way to solve the
 dependencies?


 You can do that. But it's not a really good idea to have top-level
 side-effectful code within namespaces. How are you going to test that ns?
 How will you do (stop)?

 Namespaces should only define things.



 because when the namespace is required the first time, the init block
 worked once.

 any suggestion is appreciated.


 - Joe

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');.
 For more options, visit https://groups.google.com/d/optout.




 --
 Kind Regards,
 Atamert Ölçgen

 ◻◼◻
 ◻◻◼
 ◼◼◼

 www.muhuk.com

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Making Java serializables transparently printable and readable

2015-06-17 Thread Gary Verhaegen
From glancing at the source, I think you should be able to do what you want
with clojure.core/*data-readers* and/or
clojure.core/*default-data-readers-fn*.

http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/*data-readers*

It is not clearly documented that the edn reader checks them, so maybe it
won't be reliable across versions.

On Wednesday, 17 June 2015, Surgo morgon.kan...@gmail.com wrote:

 I've been working on a Ring app that involves storing sessions as cookies,
 and within the session there are a couple Java objects that implement
 java.io.Serializable. I was somewhat surprised to find that the print-dup
 multimethod didn't have native support for Java Serializables, though I can
 understand why (they aren't really meant for long-term storage because
 version changes are troublesome). It wasn't too much trouble to come up
 with a basic implementation that could cover all of java.io.Serializable:
 https://bitbucket.org/snippets/morgon/jkjyA

 The trouble I'm having comes with reading it back in, though. In the above
 snippet, we output as a function call and depend on the behavior of
 clojure.core/read{,-string} to evaluate the function where the magic
 happens. This obviously doesn't work with the safer and recommended
 clojure.edn/read{,-string}. According to the EDN specification I should be
 able to set a dispatch tag like, say, #java base64 and attach a
 deserialization function to :readers for the tag. This isn't transparent
 though: I can't just include the library and have it work with Ring's
 already-existing (de)serialization, nor anywhere else that doesn't
 explicitly pass my special function to clojure.edn/read{,-string}.

 Is there anything I can do without filing a ticket and hoping something
 comes to be a part of the core library? To the best of my knowledge there's
 no binding I can alter for the :readers or :default options for
 clojure.edn/read{,-string}; that needs to be passed directly into the
 function at the call site. I could maybe alter the clojure.edn/read and
 clojure.edn/read-string vars themselves to wrap them so I can pass in a
 :readers option with my tag, though that seems kind of nasty and I'm not
 sure it will work in 100% of cases. What is there that can be done for this
 problem?

 Thanks,
 -- Morgon

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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.


`rational?` `decimal?` Am I misunderstanding these? (also `float?`)

2015-06-12 Thread Gary Verhaegen
Your definitions are correct, but in a different domain: you are using the
mathematical definitions.

What these functions give you is information about the representation of
the numbers in memory, not information about the numbers themselves. For
example, (integer? 1.0) will give you false.

A rational number in mathematics is one that can be written as a fraction
(of integers), or equivalently one that does not have an infinite and
non-periodic expansion. A rational number in the sense of rational? in
Clojure is an object in memory which is actually stored as a couple of
integers, not merely a valie that could be stored that way.

As others have mentioned, the way in which a number is stored will have
some impact on how much memory it takes up, how fast the computer can
compute operations on it, and how much precision will be lost with these
operations.

As always, Clojure puts more emphasis on behaviours and interfaces than on
implementations, so you should really understand rational? as will I get
an exact answer if I use operations that would give an exact answer with a
rational number (in the mathematical sense)?

For example, (/ 1M 3) will throw an exception rather than returning an
inexact, truncated answer, whereas (/ 1.0 3) will happily lie to you.
(According to the documentation, BigDecimal always returns a correct value
or throws an exception, except if you explicitly tell it to round. It can
represent values down to about 1e-2_147_483_647, and up to filling your
computer's memory.)

For a first step towards understanding floating-point values, I would
recommend reading:

http://blog.reverberate.org/2014/09/what-every-computer-programmer-should.html

On Friday, 12 June 2015, John Gabriele jmg3...@gmail.com
javascript:_e(%7B%7D,'cvml','jmg3...@gmail.com'); wrote:

 My understanding is that a rational number is one that can be written as a
 fraction. For example, 5.1, which can be written as 51/10. But Clojure
 seems to disagree:

 ~~~
 (rational? 51/10) ;= true
 (rational? 5.1)   ;= false (?!)
 ~~~

 Is my definition of rational incorrect?

 Also, my understanding is that a decimal number is one that has a decimal
 point in it, like, for example, 5.1. However:

 ~~~
 (decimal? 5.1) ;= false (?!)
 ~~~

 And while typing this, I also notice that while `integer?` acts like I'd
 expect, `float?` does something weird:

 ~~~
 (integer? 5)   ;= true Yes
 (integer? 5N)  ;= true Yes
 (integer? 5.1) ;= false

 (float? 5.1)  ;= true
 (float? 5.1M) ;= false (?!)
 ~~~

 Maybe I'm confusing floating point number with decimal number here? If
 so, what's the difference?

 Thanks!

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   >