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

2021-06-24 Thread Justin Smith
anyway - vars implement IFn, as far as I can see there's no real problem
here, you can deref the var object and it just happens to also implement IFn

(control-return adds a new line without sending in slack, but sends
immediately in gmail, clearly my brain is having trouble code switching
here)


On Thu, Jun 24, 2021 at 9:43 AM Justin Smith  wrote:

> (sorry, hit reply too soon)
>
> On Thu, Jun 24, 2021 at 9:42 AM Justin Smith  wrote:
>
>> >  Clojure vars under the IFn interface. In other words, you can only
>> import Clojure functions, not Clojure values, through that API.
>>
>> On Fri, Jun 18, 2021 at 12:29 PM ru  wrote:
>>
>>> Thank you, Gary, for the comprehensive answer. I have a control over
>>> Clojure side, so I decide to add special functions to get values of needed
>>> vars.
>>> Thanks to all for the help.
>>>
>>> Best regards,
>>>   Ru
>>>
>>> пятница, 18 июня 2021 г. в 20:23:31 UTC+3, gary.ve...@gmail.com:
>>>
>>>> The official Clojure API for Java is defined here
>>>> <https://clojure.github.io/clojure/javadoc/clojure/java/api/Clojure.html> 
>>>> 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 <https://clojuredocs.org/clojure.core/gen-class>, which may
>>>> be faster.
>>>>
>>>> If you can't change the Clojure side, you'll have to use undocumented
>>>> APIs. The Clojure.var
>>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/java/api/Clojure.java#L82>
>>>>  call
>>>> will return a Var
>>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java>
>>>>  (cast
>>>> to the IFn
>>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java>
>>>> interface), which has a deref()
>>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java#L199>
>>>> 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
>>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IDeref.java>,
>>>> 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
>>>>> <https://clojure.org/reference/vars> 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 clo...@googlegroups.com
>>>>> Note that posts from new members a

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

2021-06-24 Thread Justin Smith
(sorry, hit reply too soon)

On Thu, Jun 24, 2021 at 9:42 AM Justin Smith  wrote:

> >  Clojure vars under the IFn interface. In other words, you can only
> import Clojure functions, not Clojure values, through that API.
>
> On Fri, Jun 18, 2021 at 12:29 PM ru  wrote:
>
>> Thank you, Gary, for the comprehensive answer. I have a control over
>> Clojure side, so I decide to add special functions to get values of needed
>> vars.
>> Thanks to all for the help.
>>
>> Best regards,
>>   Ru
>>
>> пятница, 18 июня 2021 г. в 20:23:31 UTC+3, gary.ve...@gmail.com:
>>
>>> The official Clojure API for Java is defined here
>>> <https://clojure.github.io/clojure/javadoc/clojure/java/api/Clojure.html> 
>>> 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 <https://clojuredocs.org/clojure.core/gen-class>, which may
>>> be faster.
>>>
>>> If you can't change the Clojure side, you'll have to use undocumented
>>> APIs. The Clojure.var
>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/java/api/Clojure.java#L82>
>>>  call
>>> will return a Var
>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java>
>>>  (cast
>>> to the IFn
>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java>
>>> interface), which has a deref()
>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java#L199>
>>> 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
>>> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IDeref.java>,
>>> 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
>>>> <https://clojure.org/reference/vars> 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 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.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/clojure/fcbd3883-705a-4180-9b99-7c

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

2021-06-24 Thread Justin Smith
>  Clojure vars under the IFn interface. In other words, you can only
import Clojure functions, not Clojure values, through that API.

On Fri, Jun 18, 2021 at 12:29 PM ru  wrote:

> Thank you, Gary, for the comprehensive answer. I have a control over
> Clojure side, so I decide to add special functions to get values of needed
> vars.
> Thanks to all for the help.
>
> Best regards,
>   Ru
>
> пятница, 18 июня 2021 г. в 20:23:31 UTC+3, gary.ve...@gmail.com:
>
>> 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 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.
>>> 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/33e8dc71-7199-4f14-86d6-97b549b3b6e0n%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 

Re: Library like "infix"...

2021-05-17 Thread Justin Smith
unless this is an exercise in learning clojure, why not use an existing
calculator parser? eg.
https://inst.eecs.berkeley.edu/~cs164/sp05/ta/calculator/Parser.java for a
random example found with a quick google

On Sat, May 15, 2021 at 3:23 PM Blake Watson 
wrote:

> Hello,
>
> I've got a situation where I want to allow users some modest calculation
> ability, and I've gone through various evolutions of possibilities, like
> letting them put in raw Clojure code (that I will restrict at some point),
> to (heh) using POI to let them use Excel to specify possibilities (which is
> WAY overkill), to using infix.
>
> https://github.com/rm-hull/infix
>
> This is basically what I want, only expandable. I have some reservations,
> however:
>
> 1. It's no longer maintained.
> 2. It uses the author's own homegrown parser.
> 3. The comparator operators don't seem to work.
> 4. There's no function for "I can't calculate this because I don't know
> the value of X."
>
> All of this is surmountable, of course. The question is, should I surmount
> it? Or should I just start with Instaparse and a calculator grammar. Or is
> there a third way?
>
> ===Blake===
>
> --
> 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/CAJAnwPmhNNKYY1yHvND5Z8pKwMnNBXqtox7DZrP%2BVwc5LJndmg%40mail.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
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/CAGokn9J6v_CLjZu3vc9S87rbKmUUSSZ%3DSVzweS7t7gONEQmaZw%40mail.gmail.com.


Re: How get function name in body?

2021-05-03 Thread Justin Smith
there's a handy trick for pulling in the standard repl aliases / refers:

(cmd)user=> clojure.main/repl-requires
[[clojure.repl :refer (source apropos dir pst doc find-doc)]
[clojure.java.javadoc :refer (javadoc)] [clojure.pprint :refer (pp pprint)]]
(ins)user=> (ns foo.bar)
nil
(ins)foo.bar=> (doc fn)
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: doc in this context
(ins)foo.bar=> (apply require clojure.main/repl-requires)
nil
(cmd)foo.bar=> (doc fn)
-
clojure.core/fn
  (fn name? [params*] exprs*)
  (fn name? ([params*] exprs*) +)
([& sigs])
Special Form
...

On Thu, Apr 29, 2021 at 10:41 PM Sean Corfield  wrote:

> Sorry, it's clojure.repl/demunge so it depends on how you run your REPL
> and evaluate code -- in my case, clojure.repl symbols were all referred in.
> In your case, you'll need to require clojure.repl and refer it in:
>
> (require '[clojure.repl :refer [demunge])
>
> or make that part of your ns form as:
>
>   (:require [clojure.repl :refer [demunge]])
>
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- https://corfield.org/
> World Singles Networks, LLC. -- https://worldsinglesnetworks.com/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
>
> On Thu, Apr 29, 2021 at 10:27 PM damon kwok  wrote:
>
>>
>> Clojure 1.10.1
>>(defn haha []
>>(println (demunge (.getName (.getCallerClass
>> (java.lang.StackWalker/getInstance
>> java.lang.StackWalker$Option/RETAIN_CLASS_REFERENCE))
>> Syntax error compiling at (REPL:1:23).
>> Unable to resolve symbol: demunge in this context
>> 在2021年4月30日星期五 UTC+8 上午4:35:45 写道:
>>
>>> That's definitely nicer:
>>>
>>> dev=> (*defn* *add* [a b]
>>>
>>>  #_=>   (*println* (demunge (*.getName* (*.getCallerClass* (
>>> *java.lang.StackWalker*/getInstance *java.lang.StackWalker$Option*
>>> /RETAIN_CLASS_REFERENCE)
>>>
>>>  #_=>   (*+* a b))
>>>
>>> #'dev/add
>>>
>>> dev=> (add 1 2)
>>>
>>> dev/add
>>>
>>> 3
>>>
>>> dev=>
>>>
>>> Thanks, Rémi!
>>>
>>> On Thu, Apr 29, 2021 at 12:08 PM Remi Forax  wrote:
>>>


 --

 *De: *"Sean Corfield" 
 *À: *"clojure" 
 *Envoyé: *Jeudi 29 Avril 2021 01:26:34
 *Objet: *Re: How get function name in body?

 Consider that:

 (defn add [a b] (+ a b))

 is expanded to (something like):

 (def add (fn [a b] (+ a b)))

 So the actual code that runs is an anonymous function, which is bound
 to the (global) var #'add -- the function itself has no name.

 dev=> (*macroexpand* '(*defn**add* [a b] (*+* a b)))

 (def add (clojure.core/fn ([a b] (+ a b

 dev=> (*defn**add* [a b] (*+* a b))

 #'dev/add

 dev=> add

 #object[dev$add 0x72f91c91 "dev$add@72f91c91"]

 So the value of add is an object, with type dev$add, a class that
 implements a bunch of things including clojure.lang.IFn and
 java.lang.Runnable and java.util.concurrent.Callable etc.

 The "name" of function is hard to get to, inside a function because of
 that.

 One way to figure that out at runtime is to dig into the stack, which
 you can get at by creating an exception and inspecting it: be aware that
 this is an expensive operation!

 dev=> (*defn**add* [a b]

 #_=> (*let* [frame (*first* (*:trace* (*Throwable->map* (*ex-info**""*
 {}]

 #_=> (*println* (demunge (*name* (*first* frame

 #_=> (*+* a b)))

 #'dev/add

 dev=> (add 1 2)

 dev/add

 3

 dev=>

 demunge is what turns Clojure's generated classnames back into readable
 source names.


 Instead of using the stacktrace of java.lang.Throwable, you can use
 StackWalker.getCallerClass() if you are using a jdk 9+


 The more important question is: why do you want the function's name
 inside the body?
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- https://corfield.org/
 World Singles Networks, LLC. -- https://worldsinglesnetworks.com/

 "Perfection is the enemy of the good."
 -- Gustave Flaubert, French realist novelist (1821-1880)


 Rémi

 [1]
 https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/StackWalker.html#getCallerClass()

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

Re: Socket servers, threads, and redirecting error output.

2021-01-02 Thread Justin Smith
to be clear, in my second example you see the error from the future without
using deref

good luck finding your solution

On Sat, Jan 2, 2021 at 12:50 PM Austin Haas  wrote:

> Thank you very much for the explanation, Justin.
>
> I don't see how I can use futures, though, without blocking on the main
> thread (to get the exception when it occurs). I'm spawning a long-running
> process that never returns a value.
> On Saturday, January 2, 2021 at 12:43:14 AM UTC-8 noise...@gmail.com
> wrote:
>
>> By the time the exception is caught, you are already outside the context
>> of the Thread which the repl client is interacting with. The default
>> exception handler has no information tying the executing thread to the repl
>> process (not to mention the dynamic variables clojure is using to associate
>> output from code your client runs with that socket connection).
>>
>> You probably don't want to rebind the root exception handler to show
>> *all* exceptions to your client socket. Which means that you need to set up
>> some soft of infrastructure connecting the information about the failed
>> function to the socket you are listening to.
>>
>> I find "future" very convenient for this, it uses a pool which will
>>  perform better than creating Threads ad-hoc, and will capture Exceptions
>> and re-throw when you deref (of course, it's up to you to ensure you deref,
>> or use try/catch and otherwise forward the failure information via the
>> catch block). Also, it conveys dynamic bindings for things like
>> clojure.core/*out* and clojure.core/*err* that java classes don't know
>> about.
>>
>> (ins)user=> (def fut (future (throw (Exception. "oops"
>> #'user/fut
>> (ins)user=> @fut ; waits until deref to raise the error
>> Execution error at user/fn (REPL:11).
>> oops
>> (ins)user=> (def fut2 (future (try (throw (Exception. "oops")) (catch
>> Exception e (println "wat\n" e) ; prints instead of raising
>> #'user/fut2
>> user=> wat
>>  #error {
>>  :cause oops
>>  :via
>>  [{:type java.lang.Exception
>>:message oops
>>:at [user$fn__165 invokeStatic NO_SOURCE_FILE 13]}]
>>  :trace
>>  [[user$fn__165 invokeStatic NO_SOURCE_FILE 13]
>>   [user$fn__165 invoke NO_SOURCE_FILE 13]
>>   [clojure.core$binding_conveyor_fn$fn__5754 invoke core.clj 2030]
>>   [clojure.lang.AFn call AFn.java 18]
>>   [java.util.concurrent.FutureTask run FutureTask.java 264]
>>   [java.util.concurrent.ThreadPoolExecutor runWorker
>> ThreadPoolExecutor.java 1128]
>>   [java.util.concurrent.ThreadPoolExecutor$Worker run
>> ThreadPoolExecutor.java 628]
>>   [java.lang.Thread run Thread.java 834]]}
>>
>>
>>
>> On Thu, Dec 31, 2020 at 1:48 PM Austin Haas  wrote:
>>
>>>
>>> Problem: When I connect to a socket server and create a thread,
>>> exceptions in the thread are printed in the server's process, not the
>>> client's. I'd like them to appear in the client's process, where the thread
>>> was created.
>>>
>>> (I'm using the term "process" very generally here, because I don't
>>> understand what is going on.)
>>>
>>> From searching, I understand that there are some other things at play,
>>> like System/err, but I don't understand what is happening or how I can work
>>> around it. Why does an exception thrown in the client process show in the
>>> client process, but an exception thrown in a thread created by the client
>>> process shows in the server process? Why doesn't binding *err* in a thread
>>> seem to have any effect? Any suggestions or workarounds?
>>>
>>> I'm not using futures, because this is a long-running process that never
>>> returns a value.
>>>
>>> Example transcript:
>>>
>>> # Socker server
>>>
>>> (The only command entered is the first one, which begins with clj.
>>> Everything after "user=>" is due to the client below.)
>>>
>>> $ clj -J-Dclojure.server.myrepl='{:port
>>> ,:accept,clojure.core.server/repl}'
>>> Clojure 1.10.1
>>> user=> My second message.
>>> Exception in thread "Thread-0" clojure.lang.ExceptionInfo: My second
>>> exception {}
>>> at user$eval5$fn__141.invoke(NO_SOURCE_FILE:7)
>>> at clojure.lang.AFn.run(AFn.java:22)
>>> at java.lang.Thread.run(Thread.java:745)
>>> Exception in thread "Thread-1" clojure.lang.ExceptionInfo: My third
>>> exception {}
>>> at user$eval144$fn__145.invoke(NO_SOURCE_FILE:16)
>>> at clojure.lang.AFn.run(AFn.java:22)
>>> at java.lang.Thread.run(Thread.java:745)
>>>
>>> # Client
>>>
>>> $ nc localhost 
>>> user=> (println "My first message.")
>>> My first message.
>>> nil
>>> user=> (throw (ex-info "My first exception." {}))
>>> Execution error (ExceptionInfo) at user/eval3 (REPL:2).
>>> My first exception.
>>> user=> (.start
>>>  (Thread.
>>>   (fn []
>>> (println "My second message.")
>>> (throw (ex-info "My second exception" {})
>>> nil
>>> user=> (.start
>>>  (Thread.
>>>   (let [out *out*
>>> err *err*]
>>> (fn []
>>>   (binding [*out* out
>>> *err* err]
>>> (println "My third message.")
>>>

Re: Socket servers, threads, and redirecting error output.

2021-01-02 Thread Justin Smith
By the time the exception is caught, you are already outside the context of
the Thread which the repl client is interacting with. The default exception
handler has no information tying the executing thread to the repl process
(not to mention the dynamic variables clojure is using to associate output
from code your client runs with that socket connection).

You probably don't want to rebind the root exception handler to show *all*
exceptions to your client socket. Which means that you need to set up some
soft of infrastructure connecting the information about the failed function
to the socket you are listening to.

I find "future" very convenient for this, it uses a pool which will
 perform better than creating Threads ad-hoc, and will capture Exceptions
and re-throw when you deref (of course, it's up to you to ensure you deref,
or use try/catch and otherwise forward the failure information via the
catch block). Also, it conveys dynamic bindings for things like
clojure.core/*out* and clojure.core/*err* that java classes don't know
about.

(ins)user=> (def fut (future (throw (Exception. "oops"
#'user/fut
(ins)user=> @fut ; waits until deref to raise the error
Execution error at user/fn (REPL:11).
oops
(ins)user=> (def fut2 (future (try (throw (Exception. "oops")) (catch
Exception e (println "wat\n" e) ; prints instead of raising
#'user/fut2
user=> wat
 #error {
 :cause oops
 :via
 [{:type java.lang.Exception
   :message oops
   :at [user$fn__165 invokeStatic NO_SOURCE_FILE 13]}]
 :trace
 [[user$fn__165 invokeStatic NO_SOURCE_FILE 13]
  [user$fn__165 invoke NO_SOURCE_FILE 13]
  [clojure.core$binding_conveyor_fn$fn__5754 invoke core.clj 2030]
  [clojure.lang.AFn call AFn.java 18]
  [java.util.concurrent.FutureTask run FutureTask.java 264]
  [java.util.concurrent.ThreadPoolExecutor runWorker
ThreadPoolExecutor.java 1128]
  [java.util.concurrent.ThreadPoolExecutor$Worker run
ThreadPoolExecutor.java 628]
  [java.lang.Thread run Thread.java 834]]}



On Thu, Dec 31, 2020 at 1:48 PM Austin Haas  wrote:

>
> Problem: When I connect to a socket server and create a thread, exceptions
> in the thread are printed in the server's process, not the client's. I'd
> like them to appear in the client's process, where the thread was created.
>
> (I'm using the term "process" very generally here, because I don't
> understand what is going on.)
>
> From searching, I understand that there are some other things at play,
> like System/err, but I don't understand what is happening or how I can work
> around it. Why does an exception thrown in the client process show in the
> client process, but an exception thrown in a thread created by the client
> process shows in the server process? Why doesn't binding *err* in a thread
> seem to have any effect? Any suggestions or workarounds?
>
> I'm not using futures, because this is a long-running process that never
> returns a value.
>
> Example transcript:
>
> # Socker server
>
> (The only command entered is the first one, which begins with clj.
> Everything after "user=>" is due to the client below.)
>
> $ clj -J-Dclojure.server.myrepl='{:port
> ,:accept,clojure.core.server/repl}'
> Clojure 1.10.1
> user=> My second message.
> Exception in thread "Thread-0" clojure.lang.ExceptionInfo: My second
> exception {}
> at user$eval5$fn__141.invoke(NO_SOURCE_FILE:7)
> at clojure.lang.AFn.run(AFn.java:22)
> at java.lang.Thread.run(Thread.java:745)
> Exception in thread "Thread-1" clojure.lang.ExceptionInfo: My third
> exception {}
> at user$eval144$fn__145.invoke(NO_SOURCE_FILE:16)
> at clojure.lang.AFn.run(AFn.java:22)
> at java.lang.Thread.run(Thread.java:745)
>
> # Client
>
> $ nc localhost 
> user=> (println "My first message.")
> My first message.
> nil
> user=> (throw (ex-info "My first exception." {}))
> Execution error (ExceptionInfo) at user/eval3 (REPL:2).
> My first exception.
> user=> (.start
>  (Thread.
>   (fn []
> (println "My second message.")
> (throw (ex-info "My second exception" {})
> nil
> user=> (.start
>  (Thread.
>   (let [out *out*
> err *err*]
> (fn []
>   (binding [*out* out
> *err* err]
> (println "My third message.")
> (throw (ex-info "My third exception" {})))
> nil
> My third message.
>
> Any clues would be appreciated. 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 

Re: Idiomatic program for someone new to Clojure

2020-12-14 Thread Justin Smith
a small suggestion: you don't need to nest let inside let, a clause
can use previous clauses:

(defn get-latest-build
  [pipeline]
  (let [response (fetch-pipeline pipeline)
json (parse-string (:body response) true)
   [pipeline] (:pipelines json)]
  (:counter pipeline

also consider using get-in:

(defn get-latest-build
  [pipeline]
  (let [response (fetch-pipeline pipeline)
json (parse-string (:body response) true)]
   (get-in json [:pipelines 0 :counter])))

finally, this can now be simplified into a single threading macro:

(defn get-latest-build
  [pipeline]
  (-> (fetch-pipeline pipeline)
  (:body)
  (parse-string true)
  (get-in [:pipelines 0 :counter])))

On Mon, Dec 14, 2020 at 7:18 AM James Lorenzen  wrote:
>
> Hello all,
> This is my first Clojure program and I was hoping to get some advice on it 
> since I don't know any experienced Clojure devs. I'm using it locally to 
> print the latest build numbers for a list of projects.
>
> ```
> (ns jlorenzen.core
>   (:gen-class)
>   (:require [clj-http.client :as client])
>   (:require [cheshire.core :refer :all]))
>
> (defn fetch-pipeline
> [pipeline]
> (client/get (str "https://example.com/go/api/pipelines/; pipeline "/history")
> {:basic-auth "username:password"}))
>
> (defn get-latest-build
> [pipeline]
> (let [response (fetch-pipeline pipeline)
> json (parse-string (:body response) true)]
> (let [[pipeline] (:pipelines json)]
> (:counter pipeline
>
> (def core-projects #{"projectA"
> "projectB"
> "projectC"
> "projectD"})
>
> (defn print-builds
> ([]
> (print-builds core-projects))
> ([projects]
> (let [builds (pmap #(str % " " (get-latest-build %)) projects)]
> (map #(println %) (sort builds)
> ```
>
> This will output the following:
> ```
> projectA 156
> projectB 205
> projectC 29
> projectD 123
> (nil nil nil nil)
> ```
>
> A few questions:
>
> How can this program be improved?
> How idiomatic is it?
> How can I prevent it from returning the nils at the end? I know this is 
> returning nil for each map'd item; I just don't know the best way to prevent 
> that.
>
> Thanks,
> James Lorenzen
>
> --
> 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/ccb868e0-7e0c-46df-80fc-712f718314e3n%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/CAGokn9L65oxePmfJqEDNvyhS9XL-JFjDbQAfk5zdiRctXS_-bQ%40mail.gmail.com.


Re: How to safely print structures that may contain infinite lazy seqs?

2020-11-02 Thread Justin Smith
hit send too soon --

also, that print-method doesn't catch all lazy values

user=> (instance? clojure.lang.LazySeq (range))
false

user=> (supers (class (range)))
#{java.lang.Iterable java.util.List clojure.lang.Obj
clojure.lang.IPending java.io.Serializable clojure.lang.IHashEq
java.util.Collection clojure.lang.IObj clojure.lang.Sequential
clojure.lang.Seqable clojure.lang.IPersistentCollection
clojure.lang.ASeq clojure.lang.IReduce java.lang.Object
clojure.lang.ISeq clojure.lang.IMeta clojure.lang.IReduceInit}

On Mon, Nov 2, 2020 at 12:36 PM Justin Smith  wrote:
>
> > The next step might be to investigate why infinite lazy seqs don't print as 
> > clojure.lang.LazySeq, like the finite ones.
>
> that printing of  "clojure.lang.LazySeq@c5d38b66" relies on completely
> realizing the input, as it relies on the hash, which relies on the
> fully realized value
>
> On Mon, Nov 2, 2020 at 12:32 PM Austin Haas  wrote:
> >
> > Thanks, Juan.
> >
> > I don't need to know the length of the seq, though, only that it is lazy. I 
> > don't want to realize any lazy seqs. Ideally, I'd like to be able to print 
> > any data structure and have all lazy seqs print just like it does in the 
> > example I gave above (i.e., "clojure.lang.LazySeq@c5d38b66"), whether it is 
> > finite or infinite.
> >
> > I also don't want to walk through every data structure to check if it 
> > contains a lazy seq, but maybe that is the only option.
> >
> > I've also tried:
> >
> > (defmethod print-method clojure.lang.LazySeq [q, w]
> >  (.write w "#clojure.lang.LazySeq"))
> >
> > The next step might be to investigate why infinite lazy seqs don't print as 
> > clojure.lang.LazySeq, like the finite ones.
> > On Monday, November 2, 2020 at 9:22:58 AM UTC-8 jpmon...@gmail.com wrote:
> >>
> >> Hi Austin,
> >>
> >> Since there is no way to know the length of a lazy-seq without realizing 
> >> it, I think your only choice is to set a limit on it by binding 
> >> *print-length* if you are not sure about the sequence.
> >>
> >> Other thing you can try is bounded-count like this :
> >>
> >> (defn looks-finite? [xs]
> >>   (let [limit 1000]
> >> (< (bounded-count limit xs) limit)))
> >>
> >> (looks-finite? (map inc (range))) ;; => false
> >> (looks-finite? (map inc (range 100))) ;; => true
> >>
> >> I hope that helps.
> >>
> >> Juan
> >> El domingo, 1 de noviembre de 2020 a las 20:06:39 UTC-3, Austin Haas 
> >> escribió:
> >>>
> >>>
> >>> How can I make sure that a logging function won't try to realize an 
> >>> infinite lazy seq that could be anywhere in the arguments passed to the 
> >>> logging function?
> >>>
> >>> Is there some way to guarantee that lazy seqs won't be realized when 
> >>> converting to a string?
> >>>
> >>> I know I can bind *print-length*, but I don't want to constrain every 
> >>> collection.
> >>>
> >>> And I know that lazy seqs aren't always realized, but that doesn't seem 
> >>> to help if they are infinite:
> >>>
> >>> user=> (str (map inc (range 10)))
> >>> "clojure.lang.LazySeq@c5d38b66"
> >>>
> >>> user=> (str (map inc (range)))
> >>> 
> >>>
> >>> 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.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/clojure/ab820e20-75ad-4852-aa01-9321cb7487b4n%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/CAGokn9L7pzXArLcvu0BUf0x7JnD2wZpjgisuFr6ZPfA0817EZg%40mail.gmail.com.


Re: How to safely print structures that may contain infinite lazy seqs?

2020-11-02 Thread Justin Smith
> The next step might be to investigate why infinite lazy seqs don't print as 
> clojure.lang.LazySeq, like the finite ones.

that printing of  "clojure.lang.LazySeq@c5d38b66" relies on completely
realizing the input, as it relies on the hash, which relies on the
fully realized value

On Mon, Nov 2, 2020 at 12:32 PM Austin Haas  wrote:
>
> Thanks, Juan.
>
> I don't need to know the length of the seq, though, only that it is lazy. I 
> don't want to realize any lazy seqs. Ideally, I'd like to be able to print 
> any data structure and have all lazy seqs print just like it does in the 
> example I gave above (i.e., "clojure.lang.LazySeq@c5d38b66"), whether it is 
> finite or infinite.
>
> I also don't want to walk through every data structure to check if it 
> contains a lazy seq, but maybe that is the only option.
>
> I've also tried:
>
> (defmethod print-method clojure.lang.LazySeq [q, w]
>  (.write w "#clojure.lang.LazySeq"))
>
> The next step might be to investigate why infinite lazy seqs don't print as 
> clojure.lang.LazySeq, like the finite ones.
> On Monday, November 2, 2020 at 9:22:58 AM UTC-8 jpmon...@gmail.com wrote:
>>
>> Hi Austin,
>>
>> Since there is no way to know the length of a lazy-seq without realizing it, 
>> I think your only choice is to set a limit on it by binding *print-length* 
>> if you are not sure about the sequence.
>>
>> Other thing you can try is bounded-count like this :
>>
>> (defn looks-finite? [xs]
>>   (let [limit 1000]
>> (< (bounded-count limit xs) limit)))
>>
>> (looks-finite? (map inc (range))) ;; => false
>> (looks-finite? (map inc (range 100))) ;; => true
>>
>> I hope that helps.
>>
>> Juan
>> El domingo, 1 de noviembre de 2020 a las 20:06:39 UTC-3, Austin Haas 
>> escribió:
>>>
>>>
>>> How can I make sure that a logging function won't try to realize an 
>>> infinite lazy seq that could be anywhere in the arguments passed to the 
>>> logging function?
>>>
>>> Is there some way to guarantee that lazy seqs won't be realized when 
>>> converting to a string?
>>>
>>> I know I can bind *print-length*, but I don't want to constrain every 
>>> collection.
>>>
>>> And I know that lazy seqs aren't always realized, but that doesn't seem to 
>>> help if they are infinite:
>>>
>>> user=> (str (map inc (range 10)))
>>> "clojure.lang.LazySeq@c5d38b66"
>>>
>>> user=> (str (map inc (range)))
>>> 
>>>
>>> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/clojure/ab820e20-75ad-4852-aa01-9321cb7487b4n%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/CAGokn9%2BGw2oZBfMNMGKPVko7gOUDMJMNuz3dEr45vdx%2BuEUgrA%40mail.gmail.com.


Re: clojure.edn/read isn't spec compliant

2020-10-17 Thread Justin Smith
not only does clojure.edn accept invalid input, but the clojure reader
also accepts invalid input for the same reason (prioritizing speed of
implementation over validation)

user=> (name 'a/b/c)
"b/c"

On Sat, Oct 17, 2020 at 5:14 PM William la Forge  wrote:
>
> My understanding is that run-time validation is often left weak in preference 
> to speed of execution. In contrast to validation by the "compiler". Thus 
> clojure throws many more exceptions than does the edn reader. --Bill la Forge
>
> On Friday, October 16, 2020 at 9:07:40 PM UTC-4 EuAndreh wrote:
>>
>>
>> Hello there.
>>
>> I was working on implementing a specification compliant edn reader on
>> Rust, and I found that clojure.edn/read itself isn't specification
>> compliant.
>>
>> I have three examples below that should all throw exceptions, but
>> instead they are valid values according to clojure.edn/read. The quotes
>> were taken verbatim from the text of the specification[0].
>>
>> --8<---cut here---start->8---
>> ;; "Per the symbol rules above, :/ and :/anything are not legal keywords."
>> [(edn/read-string ":/")
>> ;; "It can be used once only in the middle of a symbol to separate
>> the _prefix_ (often a namespace) from the _name
>> _"
>> (name (edn/read-string "a/b/c"))
>>
>> ;; specification doesn't talk about namespaced maps
>> (edn/read-string "#:a{:k 1}")]
>>
>> [:/ "b/c" #:a{:k 1}]
>> --8<---cut here---end--->8---
>>
>> I couldn't find many references to these issues, other than a Jira
>> ticket[1] and a thread on clojure-dev[2]. Both talk about
>> clojure.edn/read being consistent with LispReader, though. I have no
>> opinions on that.
>>
>> Since the clojure.edn/read is an edn reader, shouldn't it comply with
>> the edn specification? Maybe not the namespaced maps parts, which the
>> specification itself could be extended to cover. But the other two cases
>> are explicitly forbidden on the specification, and clojure.edn/read
>> allows them.
>>
>> I'm willing to write a patch to fix those, but is it something that
>> would be welcome? One could consider it a breaking change since the
>> reader will stop accepting data that is now does, but I could also argue
>> that this is a bug on the reader that was fixed, and the behaviour was
>> changed to match the expected behaviour, which is the specification.
>>
>> The specification itself could change to match the behaviour of the
>> reader, but this is not desirable since it would invalidate the work
>> that others have done to implement edn outside of Clojure.
>>
>> The tension between breaking the reader and matching the specification
>> should, IMHO, be favoured towards the matching the specification.
>> Otherwise, the actual specification isn't what edn-format.org says, but
>> it would instead be "whatever clojure.edn/read does", which is worse.
>> The value proposition of having an specification to begin with is lost.
>>
>> WDYT? Is there any other resource on this that I missed?
>>
>> [0]: 
>> https://raw.githubusercontent.com/edn-format/edn/a51127aecd318096667ae0dafa25353ecb07c9c3/README.md
>> [1]: https://clojure.atlassian.net/browse/CLJ-1530
>> [2]: https://groups.google.com/g/clojure-dev/c/b09WvRR90Zc/discussion
>
> --
> 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/1a9c0924-0b94-4094-8fa0-c8cd8f9bc667n%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/CAGokn9JNhUhR2_k_av606J5JWeu0vC%3DbrZPAoFuJygkzyc-z%2BQ%40mail.gmail.com.


Re: Accessing Record fields with keywords in ClojureScript not working as in Clojure

2020-08-04 Thread Justin Smith
I don't think this is true, or if true is incidental to the real problem

% cljs
ClojureScript 1.10.758
cljs.user=> (defrecord Attr [has-default default])
cljs.user/Attr
cljs.user=> (get (->Attr true 1) :default)
1
cljs.user=> (:default (->Attr true 1))
nil
cljs.user=>

On Tue, Aug 4, 2020 at 11:53 AM Mark Engelberg  wrote:
>
> You misspelled default in your defrecord.
>
> On Tue, Aug 4, 2020 at 7:42 AM 'clartaq' via Clojure 
>  wrote:
>>
>> I originally posted this on StackOverflow.
>>
>> When I try this:
>>
>> ```clojure
>> (defrecord Attr [has-default default])
>> (def attr (->Attr true 1))
>> (get attr :default) ;;=> 1
>> (:default attr) ;;=> ClojureScript returns nil, Clojure returns 1
>> ```
>>
>> Is the difference in behavior when using keyword access expected? I couldn't 
>> find anything about it in the [docs][1]  on the differences between Clojure 
>> and ClojureScript.
>>
>> **Update 2020-08-04**
>>
>> Well, this is getting weird. This morning, if I open a REPL with 
>> figwheel-main, or from CIDER, it sometimes works as expected -- `(:default 
>> attr)` returns 1.
>>
>> If I try it by opening the ClojureScript REPL using `clj`, it is still 
>> broken.
>>
>> ```clojure
>> % clj --main cljs.main --repl
>> ClojureScript 1.10.773
>> cljs.user=> (defrecord Attr [has-default defaut])
>> cljs.user/Attr
>> cljs.user=> (def attr (->Attr true 1))
>> #'cljs.user/attr
>> cljs.user=> (get attr :default)
>> nil
>> cljs.user=> (:default attr)
>> nil
>> cljs.user=> (:has-default attr)
>> true
>> cljs.user=> (println "attr: " attr)
>> attr:  #cljs.user.Attr{:has-default true, :defaut 1}
>> nil
>> ```
>>
>>
>>   [1]: https://www.clojurescript.org/about/differences#_data_structures
>>
>> --
>> 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/5dd44871-3915-4d80-a959-28be44c8cc32o%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/CAORbMON7N3ukBEn%3D%3DzX8pAz3tJg%2BjX32x4TTDDqYdCxbWDswbA%40mail.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
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/CAGokn9LpwPYku9606pYXXzLSGQp6aphtsvckjd%3DASG6JEQM2VA%40mail.gmail.com.


Re: first time without state - and I'm lost

2020-06-15 Thread Justin Smith
The usage of delay here is clever. I suggest as an addition, using
`force` instead of `deref` to disambiguate delay vs. atom (of course
if you take a few moments to think about it, swap! shouldn't return an
atom etc., but I think it becomes clearer with force).

On Mon, Jun 15, 2020 at 10:34 AM Ernesto Garcia  wrote:
>
> Hi, it's a long time that this question was posted, but I have found it 
> interesting in the implementation of token refreshes.
>
> First of all, for service invocation, given a `revise-oauth-token` method, I 
> think this is good client code:
>
> (http/request
>   {:method :get
>:url "https://example.com/;
>:oauth-token (revise-oauth-token token-store)})
>
> If you find it too repetitive or fragile in your client code, you can make a 
> local function, but I wouldn't abstract the service invocation at a higher 
> layer.
>
> Regarding the implementation of the token store, we could initially think of 
> a synchronized store, like an atom, and `revise-oauth-token` would swap its 
> content when a refresh is required. This is inconvenient for multithreaded 
> clients, because there could be several refresh invocations going on 
> concurrently.
>
> In order to avoid concurrent refreshes, I propose to implement the token 
> store as an atom of promises. Implementation of `revise-oauth-token` would be:
>
> (defn revise-oauth-token [token-store]
>   (:access_token
> @(swap! token-store
>(fn [token-promise]
>  (if (token-needs-refresh? @token-promise (Instant/now))
>(delay (refresh-oauth-token (:refresh_token @token-promise)))
>token-promise)
>
> Note that using a delay avoids running `refresh-oauth-token` within the 
> `swap!` operation, as this operation may be run multiple times.
> Also note that `token-needs-refresh` takes an argument with the present time. 
> This keeps the function pure, which could help for unit testing, for example.
>
> There is an alternative implementation using `compare-and-set!` that avoids 
> checking `token-needs-refresh?` several times, but it is more complicated. I 
> have posted full sample code in a gist: 
> https://gist.github.com/titogarcia/4f09bcc5fa38fbdc1076954b9a99a8fc
>
> Remark: None of this refers to "functional programming" per se. Dealing with 
> state in a purely functional way involves using different constructs (like 
> possibly monads, for which you can find Clojure libraries if you are 
> interested), and best practices are still a topic of research. Clojure has 
> taken the pragmatic approach of making purely functional code easy to write, 
> but it doesn't reject the use of state, rather it provides well-behaved 
> primitives like vars, atoms, agents, etc.
>
> Ernesto
>
> --
> 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/ac79058b-2c31-4b9c-9cf3-e2de998eb8deo%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/CAGokn9L_Od2ZN2LJAsYUfJ2G_hbLKkamkUxgFX2vTKySxpHQWg%40mail.gmail.com.


Re: Conceptual difference between map and class

2020-03-31 Thread Justin Smith
I think it's also important here that Clojure methods are actual Java
methods - Clojure likes to stay close to the host functionality. A map
with a function isn't a class with a method because the JVM bytecode
doesn't let you invoke it that way directly. A Clojure function is not
a method because methods are not first class, it's an Object with a
static .invoke method (and some other details that are less important
here).

This object as hash with functions model is useful for learning (and
there's a lot of scheme and common lisp code that actually works this
way). With some effort, you can do everything with a function in a map
that you can with an object with a method if you are careful to
provide the object of the first arg.

But it's normal in Clojure to use the built in affordances. For real
code, defrecord gives you a new class that operates in a way similar
to this but with lower friction to the underlying bytecode (it
implements actual methods but also acts like a hash map for its
fields). Protocols let you use a hash map for extension (they act like
interfaces for classes, but you can add new implementations
dynamically, letting you do what you would do by adding a function
under a key on a hash, but tracking it on the protocol side).

On Tue, Mar 31, 2020 at 7:39 AM Jason Felice  wrote:
>
> A subtle difference between a map of functions and a Python class is that the 
> class has implicit "self" or "this".  Otherwise, these are semantically the 
> same.  Well, ignoring that Clojure maps are immutable.
>
> In fact, C++ compilers compile methods by inserting a first "this" argument 
> and mangling the name.  Virtual methods (ones which can be overridden) are 
> collected into what is effectively a map attached to the instance.
>
> On Tue, Mar 31, 2020 at 4:41 AM Dieter Van Eessen 
>  wrote:
>>
>> Hello,
>>
>> I've got a clojure and a python piece of code. Both seem to create what can 
>> be considered an instance of a class. Wherein lies the conceptual difference?
>>
>> Python:
>> class MYCLASS():
>> def __init__(self, x):
>>   self.x = x
>> def MYMETHOD(self):
>>  ...
>>
>> def MYFUNCTION():
>> lol = MYCLASS()
>>
>> Clojure:
>> (defn MYCLASS [x]
>>  {:x [x]
>>   :MYMETHOD (fn [] (MYCLASS ...))})
>>
>> (let [lol (MYCLASS ...)])
>>
>> I know its not valid code, but I hope you see what I'm aiming at: isn't 
>> using a map with functions in it just the same as a class?
>> Or is only the user interface of the language conceptually equal, while the 
>> underlying plumbing is completely different?
>> If this is the case, wherein lies the major differences?
>>
>> If one could simply point me in the right direction, I'd already be very 
>> pleased. Most literature I've read so far only explains clojure can be used 
>> this way, but never focuses deeper on the subject.
>>
>> kind regards,
>> Dieter
>>
>> --
>> 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/49cd26ca-48ae-48b4-a5ab-b0f7c711b77e%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/CAB6_SoYCTeKi2teO%3DbgyEB-Vu3C-fCGpX6T%3DXZB8ApmDP-c8vA%40mail.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
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 

Re: Bizarre issue when calling protocol-fn wrapper from different namespace

2019-11-22 Thread Justin Smith
if I'm not mistaken, the usage of apply in the api ns ensures that the
method will only be found if "opts" is exactly one opt, otherwise the
arity won't be found and that will be reported as no such method

On Fri, Nov 22, 2019 at 12:37 AM Dimitrios Jim Piliouras
 wrote:
>
> Ok, here is the protocol definition:
> https://github.com/jimpil/cryptohash-clj/blob/master/src/cryptohash_clj/proto.clj
>
> Here are the implementations (notice the two public fns at the end of each 
> file):
> https://github.com/jimpil/cryptohash-clj/tree/master/src/cryptohash_clj/impl
>
> And here is the api with the two multi-methods:
> https://github.com/jimpil/cryptohash-clj/blob/master/src/cryptohash_clj/api.clj
>
> Everything works as expected inside the impl namespaces, but not in the api 
> namespace, even though all it does is to delegate to some impl ns.
>
> Thanks again...
>
> Kind regards,
> Dimitris
>
> ps: this repo is WIP
>
>
> On 21 Nov 2019, at 23:43, Justin Smith  wrote:
>
> on rereading I've clearly misunderstood you, I think we need to see
> actual code reproducing this error in order to know what failed here
>
> On Thu, Nov 21, 2019 at 3:42 PM Justin Smith  wrote:
>
>
> there is no foo/x unless you defined one - the protocol function is
> created by defprotocol and is not owned by the object implementing the
> protocol
>
> On Thu, Nov 21, 2019 at 3:29 PM Dimitrios Jim Piliouras
>  wrote:
>
>
> But the call-chain is api/x-with-foo => foo/x => proto/X so it does bottom 
> out in the ns the protocol was defined in. It's just that the middle step 
> could come from 3 different namespaces all containing protocol extensions.
>
> On Thu, 21 Nov 2019, 23:03 Justin Smith,  wrote:
>
>
> it might be helpful to consider that in the jvm methods are not data,
> and the proto function makes the method into concrete data belongs to
> the namespace that owns the protocol
>
> On Thu, Nov 21, 2019 at 2:58 PM Justin Smith  wrote:
>
>
> if you define proto method x, it belongs to the protocol namespace no
> matter where it is called, and calling it as if it belonged to the
> namespace defining the object extending the protocol will and should
> fail
>
> On Thu, Nov 21, 2019 at 1:57 PM Dimitrios Jim Piliouras
>  wrote:
>
>
> Hi folks,
>
> This has me completely stumped - I would massively appreciate a helping hand! 
> Suppose the following simple directory structure:
>
>
> — someProject.impl.{foo.clj, bar.clj,baz.clj}
> — someProject.proto.clj
> — someProject.api.clj
>
> `proto.clj` contains a single protocol with two methods - let’s call them X & 
> Y. Each implementation namespace (foo, bar, baz), requires 
> `[someProject.proto :as proto]`,  extends it to 3 types (bytes/chars/String), 
> and defines two public fns x & y which delegate to `proto/X` & `proto/Y` 
> respectively. Everything is good so far. I can fire up a REPL, load any of 
> the impl  namespaces (foo, bar, baz), call the corresponding x or y fn and 
> get the right result.
>
> Now, I want to provide a unified API so that the caller doesn’t need to 
> (potentially) require 3 namespaces. Hence the `someProject.api` ns, which 
> contains require clauses for all impl namespaces + two multi-methods `X-with` 
> & `Y-with` with 3 implementations (`defmethod`) each. Each implementation 
> delegates to the x or y fn in the right impl namespace. In other words,  
> `X-with :foo` calls `(foo/x)`, `X-with :bar` calls `(bar/x)` etc etc. 
> Remember, that calling x or y inside any impl namespace works correctly, so 
> all I’m doing here is providing a multi-method wrapper. However, things don’t 
> work as I was expecting in this namespace…Loading `someProject.api` in a 
> fresh REPL and calling  `X-with :foo` bottoms out at the protocol extension 
> for X in the baz ns, which is the last require clause in the api namespace.
>
> So basically,  the protocol extensions in each impl namespace work fine when 
> called from their wrapper fn in the namespace they were defined, but don’t 
> quite work when the same wrapper fn is called from some other namespace! What 
> am I missing? :(
>
> Many thanks in advance…
> Dimitris
>
>
> --
> 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 t

Re: Bizarre issue when calling protocol-fn wrapper from different namespace

2019-11-21 Thread Justin Smith
on rereading I've clearly misunderstood you, I think we need to see
actual code reproducing this error in order to know what failed here

On Thu, Nov 21, 2019 at 3:42 PM Justin Smith  wrote:
>
> there is no foo/x unless you defined one - the protocol function is
> created by defprotocol and is not owned by the object implementing the
> protocol
>
> On Thu, Nov 21, 2019 at 3:29 PM Dimitrios Jim Piliouras
>  wrote:
> >
> > But the call-chain is api/x-with-foo => foo/x => proto/X so it does bottom 
> > out in the ns the protocol was defined in. It's just that the middle step 
> > could come from 3 different namespaces all containing protocol extensions.
> >
> > On Thu, 21 Nov 2019, 23:03 Justin Smith,  wrote:
> >>
> >> it might be helpful to consider that in the jvm methods are not data,
> >> and the proto function makes the method into concrete data belongs to
> >> the namespace that owns the protocol
> >>
> >> On Thu, Nov 21, 2019 at 2:58 PM Justin Smith  wrote:
> >> >
> >> > if you define proto method x, it belongs to the protocol namespace no
> >> > matter where it is called, and calling it as if it belonged to the
> >> > namespace defining the object extending the protocol will and should
> >> > fail
> >> >
> >> > On Thu, Nov 21, 2019 at 1:57 PM Dimitrios Jim Piliouras
> >> >  wrote:
> >> > >
> >> > > Hi folks,
> >> > >
> >> > > This has me completely stumped - I would massively appreciate a 
> >> > > helping hand! Suppose the following simple directory structure:
> >> > >
> >> > >
> >> > > — someProject.impl.{foo.clj, bar.clj,baz.clj}
> >> > > — someProject.proto.clj
> >> > > — someProject.api.clj
> >> > >
> >> > > `proto.clj` contains a single protocol with two methods - let’s call 
> >> > > them X & Y. Each implementation namespace (foo, bar, baz), requires 
> >> > > `[someProject.proto :as proto]`,  extends it to 3 types 
> >> > > (bytes/chars/String), and defines two public fns x & y which delegate 
> >> > > to `proto/X` & `proto/Y` respectively. Everything is good so far. I 
> >> > > can fire up a REPL, load any of the impl  namespaces (foo, bar, baz), 
> >> > > call the corresponding x or y fn and get the right result.
> >> > >
> >> > > Now, I want to provide a unified API so that the caller doesn’t need 
> >> > > to (potentially) require 3 namespaces. Hence the `someProject.api` ns, 
> >> > > which contains require clauses for all impl namespaces + two 
> >> > > multi-methods `X-with` & `Y-with` with 3 implementations (`defmethod`) 
> >> > > each. Each implementation delegates to the x or y fn in the right impl 
> >> > > namespace. In other words,  `X-with :foo` calls `(foo/x)`, `X-with 
> >> > > :bar` calls `(bar/x)` etc etc. Remember, that calling x or y inside 
> >> > > any impl namespace works correctly, so all I’m doing here is providing 
> >> > > a multi-method wrapper. However, things don’t work as I was expecting 
> >> > > in this namespace…Loading `someProject.api` in a fresh REPL and 
> >> > > calling  `X-with :foo` bottoms out at the protocol extension for X in 
> >> > > the baz ns, which is the last require clause in the api namespace.
> >> > >
> >> > > So basically,  the protocol extensions in each impl namespace work 
> >> > > fine when called from their wrapper fn in the namespace they were 
> >> > > defined, but don’t quite work when the same wrapper fn is called from 
> >> > > some other namespace! What am I missing? :(
> >> > >
> >> > > Many thanks in advance…
> >> > > Dimitris
> >> > >
> >> > >
> >> > > --
> >> > > 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/c

Re: Bizarre issue when calling protocol-fn wrapper from different namespace

2019-11-21 Thread Justin Smith
there is no foo/x unless you defined one - the protocol function is
created by defprotocol and is not owned by the object implementing the
protocol

On Thu, Nov 21, 2019 at 3:29 PM Dimitrios Jim Piliouras
 wrote:
>
> But the call-chain is api/x-with-foo => foo/x => proto/X so it does bottom 
> out in the ns the protocol was defined in. It's just that the middle step 
> could come from 3 different namespaces all containing protocol extensions.
>
> On Thu, 21 Nov 2019, 23:03 Justin Smith,  wrote:
>>
>> it might be helpful to consider that in the jvm methods are not data,
>> and the proto function makes the method into concrete data belongs to
>> the namespace that owns the protocol
>>
>> On Thu, Nov 21, 2019 at 2:58 PM Justin Smith  wrote:
>> >
>> > if you define proto method x, it belongs to the protocol namespace no
>> > matter where it is called, and calling it as if it belonged to the
>> > namespace defining the object extending the protocol will and should
>> > fail
>> >
>> > On Thu, Nov 21, 2019 at 1:57 PM Dimitrios Jim Piliouras
>> >  wrote:
>> > >
>> > > Hi folks,
>> > >
>> > > This has me completely stumped - I would massively appreciate a helping 
>> > > hand! Suppose the following simple directory structure:
>> > >
>> > >
>> > > — someProject.impl.{foo.clj, bar.clj,baz.clj}
>> > > — someProject.proto.clj
>> > > — someProject.api.clj
>> > >
>> > > `proto.clj` contains a single protocol with two methods - let’s call 
>> > > them X & Y. Each implementation namespace (foo, bar, baz), requires 
>> > > `[someProject.proto :as proto]`,  extends it to 3 types 
>> > > (bytes/chars/String), and defines two public fns x & y which delegate to 
>> > > `proto/X` & `proto/Y` respectively. Everything is good so far. I can 
>> > > fire up a REPL, load any of the impl  namespaces (foo, bar, baz), call 
>> > > the corresponding x or y fn and get the right result.
>> > >
>> > > Now, I want to provide a unified API so that the caller doesn’t need to 
>> > > (potentially) require 3 namespaces. Hence the `someProject.api` ns, 
>> > > which contains require clauses for all impl namespaces + two 
>> > > multi-methods `X-with` & `Y-with` with 3 implementations (`defmethod`) 
>> > > each. Each implementation delegates to the x or y fn in the right impl 
>> > > namespace. In other words,  `X-with :foo` calls `(foo/x)`, `X-with :bar` 
>> > > calls `(bar/x)` etc etc. Remember, that calling x or y inside any impl 
>> > > namespace works correctly, so all I’m doing here is providing a 
>> > > multi-method wrapper. However, things don’t work as I was expecting in 
>> > > this namespace…Loading `someProject.api` in a fresh REPL and calling  
>> > > `X-with :foo` bottoms out at the protocol extension for X in the baz ns, 
>> > > which is the last require clause in the api namespace.
>> > >
>> > > So basically,  the protocol extensions in each impl namespace work fine 
>> > > when called from their wrapper fn in the namespace they were defined, 
>> > > but don’t quite work when the same wrapper fn is called from some other 
>> > > namespace! What am I missing? :(
>> > >
>> > > Many thanks in advance…
>> > > Dimitris
>> > >
>> > >
>> > > --
>> > > 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/A549FB15-0B12-4E20-9D98-4F5A56330DC4%40gmail.com.
>>
>> --
>> You received this message because you are subscribed to t

Re: Bizarre issue when calling protocol-fn wrapper from different namespace

2019-11-21 Thread Justin Smith
it might be helpful to consider that in the jvm methods are not data,
and the proto function makes the method into concrete data belongs to
the namespace that owns the protocol

On Thu, Nov 21, 2019 at 2:58 PM Justin Smith  wrote:
>
> if you define proto method x, it belongs to the protocol namespace no
> matter where it is called, and calling it as if it belonged to the
> namespace defining the object extending the protocol will and should
> fail
>
> On Thu, Nov 21, 2019 at 1:57 PM Dimitrios Jim Piliouras
>  wrote:
> >
> > Hi folks,
> >
> > This has me completely stumped - I would massively appreciate a helping 
> > hand! Suppose the following simple directory structure:
> >
> >
> > — someProject.impl.{foo.clj, bar.clj,baz.clj}
> > — someProject.proto.clj
> > — someProject.api.clj
> >
> > `proto.clj` contains a single protocol with two methods - let’s call them X 
> > & Y. Each implementation namespace (foo, bar, baz), requires 
> > `[someProject.proto :as proto]`,  extends it to 3 types 
> > (bytes/chars/String), and defines two public fns x & y which delegate to 
> > `proto/X` & `proto/Y` respectively. Everything is good so far. I can fire 
> > up a REPL, load any of the impl  namespaces (foo, bar, baz), call the 
> > corresponding x or y fn and get the right result.
> >
> > Now, I want to provide a unified API so that the caller doesn’t need to 
> > (potentially) require 3 namespaces. Hence the `someProject.api` ns, which 
> > contains require clauses for all impl namespaces + two multi-methods 
> > `X-with` & `Y-with` with 3 implementations (`defmethod`) each. Each 
> > implementation delegates to the x or y fn in the right impl namespace. In 
> > other words,  `X-with :foo` calls `(foo/x)`, `X-with :bar` calls `(bar/x)` 
> > etc etc. Remember, that calling x or y inside any impl namespace works 
> > correctly, so all I’m doing here is providing a multi-method wrapper. 
> > However, things don’t work as I was expecting in this namespace…Loading 
> > `someProject.api` in a fresh REPL and calling  `X-with :foo` bottoms out at 
> > the protocol extension for X in the baz ns, which is the last require 
> > clause in the api namespace.
> >
> > So basically,  the protocol extensions in each impl namespace work fine 
> > when called from their wrapper fn in the namespace they were defined, but 
> > don’t quite work when the same wrapper fn is called from some other 
> > namespace! What am I missing? :(
> >
> > Many thanks in advance…
> > Dimitris
> >
> >
> > --
> > 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/A549FB15-0B12-4E20-9D98-4F5A56330DC4%40gmail.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/CAGokn9%2B1ZiFHBzuS_bwSyrx0DsM_ocu7dk844DnU-h5D3b9fzA%40mail.gmail.com.


Re: Bizarre issue when calling protocol-fn wrapper from different namespace

2019-11-21 Thread Justin Smith
if you define proto method x, it belongs to the protocol namespace no
matter where it is called, and calling it as if it belonged to the
namespace defining the object extending the protocol will and should
fail

On Thu, Nov 21, 2019 at 1:57 PM Dimitrios Jim Piliouras
 wrote:
>
> Hi folks,
>
> This has me completely stumped - I would massively appreciate a helping hand! 
> Suppose the following simple directory structure:
>
>
> — someProject.impl.{foo.clj, bar.clj,baz.clj}
> — someProject.proto.clj
> — someProject.api.clj
>
> `proto.clj` contains a single protocol with two methods - let’s call them X & 
> Y. Each implementation namespace (foo, bar, baz), requires 
> `[someProject.proto :as proto]`,  extends it to 3 types (bytes/chars/String), 
> and defines two public fns x & y which delegate to `proto/X` & `proto/Y` 
> respectively. Everything is good so far. I can fire up a REPL, load any of 
> the impl  namespaces (foo, bar, baz), call the corresponding x or y fn and 
> get the right result.
>
> Now, I want to provide a unified API so that the caller doesn’t need to 
> (potentially) require 3 namespaces. Hence the `someProject.api` ns, which 
> contains require clauses for all impl namespaces + two multi-methods `X-with` 
> & `Y-with` with 3 implementations (`defmethod`) each. Each implementation 
> delegates to the x or y fn in the right impl namespace. In other words,  
> `X-with :foo` calls `(foo/x)`, `X-with :bar` calls `(bar/x)` etc etc. 
> Remember, that calling x or y inside any impl namespace works correctly, so 
> all I’m doing here is providing a multi-method wrapper. However, things don’t 
> work as I was expecting in this namespace…Loading `someProject.api` in a 
> fresh REPL and calling  `X-with :foo` bottoms out at the protocol extension 
> for X in the baz ns, which is the last require clause in the api namespace.
>
> So basically,  the protocol extensions in each impl namespace work fine when 
> called from their wrapper fn in the namespace they were defined, but don’t 
> quite work when the same wrapper fn is called from some other namespace! What 
> am I missing? :(
>
> Many thanks in advance…
> Dimitris
>
>
> --
> 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/A549FB15-0B12-4E20-9D98-4F5A56330DC4%40gmail.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/CAGokn9L-8Stw4ucMJ4DueU5CFVabvTCr1DupOE95oyMhu5fkuw%40mail.gmail.com.


Re: Blocking behavior of >!! ?

2019-05-20 Thread Justin Smith
I might be missing something here, but when it is mentioned that
something blocks, it's implicit in all cases that there's some
condition that allows it to proceed (even immediately) if satisfied.
If there's no buffer space it blocks, until that value is consumed.
Just because we can construct a case where the consuption happens
immediately doesn't mean the call doesn't block.

On Mon, May 20, 2019 at 9:33 AM LaurentJ  wrote:
>
> ...waiting -offers +takers
>
> Le lundi 20 mai 2019 18:30:36 UTC+2, LaurentJ a écrit :
>>
>> You are not wrong.
>>
>> I think it was obvious for the author to consider that >!! will not block if 
>> there are waiting offers.
>>
>> You can see it in the code, if no buffer is set the write method will 
>> iterate over takers ready to consume the value.
>> https://github.com/clojure/core.async/blob/91e6971a05fa49ca639fc1b7793141dd5f3d32ce/src/main/clojure/clojure/core/async/impl/channels.clj#L116
>>
>>
>>
>> Le lundi 20 mai 2019 15:18:17 UTC+2, Brian Beckman a écrit :
>>>
>>> Thanks, Thomas. I shouldn't have included the quoted code about (>> my question because it distracts from what I really want to know, and what 
>>> I want to know is all about how (go (>> so that (>!! c 42) doesn't block.
>>>
>>> The following is an attempt to clarify my question. I first (go (>> give the name d to the result, which is a channel that I am going read-from 
>>> later. Channel d is "connected to" or "relayed from" c. I then (>!! c 42), 
>>> and then (>> wasted your attention by writing some code that would block (>> weren't quoted.
>>>
>>> Here is the part I don't understand: the documentation says that (>!! c 42) 
>>> will block "if there is no buffer space available," and the documentation 
>>> does not specify any other conditions. Well, I created c with no buffer 
>>> space, so, (>!! c 42) must block unless something else "makes buffer space 
>>> available," assuming the documentation is correct. The only other 
>>> interaction with c that could possibly be alive at the time when I do (>!! 
>>> c 42), is (go (>> assuming the documentation is correct. My understanding of (>> suspicious of my understanding), is that (>> available, not a buffer. If that understanding is correct, then (>!! c 42) 
>>> should block because there is no buffer available.
>>>
>>> On Sunday, May 19, 2019 at 1:48:16 PM UTC-7, Thomas Heller wrote:

 (>>> by the first go (running in a different thread). So it is blocking until 
 something puts another value into c. Since nothing ever does your program 
 hangs.

 If it helps you can read "go" as "please run this somewhere else, possibly 
 at a different time" and let the current thread continue after the go.

 I can't explain this very well but the documentation aspect is accurate.

 On Sunday, May 19, 2019 at 7:33:07 PM UTC+2, Brian Beckman wrote:
>
> The documentation for >!! reads:
>
> -
> clojure.core.async/>!!
> ([port val])
>   puts a val into port. nil values are not allowed. Will block if no
>   buffer space is available. Returns true unless port is already closed.
>
>
> I have a case where I believe that the channel has no buffer, I park a 
> "pseudothread" in a go block reading off that channel via  (lexically, not temporally), put to the unbuffered channel via >!!:
>
> (let [c (chan) ;; NO BUFFER!
>   d (go (   e (>!! c 42)] ;; blocking write to c, will unpark c's pseudothread
> (println {:c-coughs-up '(this will hang (   :d-coughs-up (   :what's-ee})
> (close! c) (close! d))
>
> {:c-coughs-up (this will hang (
>
> This case leads me to wonder whether the documentation might read
>
>  >!! will block if there is no buffer space available and if there is no 
> rendezvous available, that is, no pseudothread parked waiting for 
> but it's more likely that I completely misunderstand core.async because I 
> just made up the notion of a pseudothread in my struggle to understand!
>
>
>
> --
> 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/456c5363-a2fd-49e8-9de5-73ae9ffae075%40googlegroups.com.
> For more options, visit 

Re: results from sort-by are not sorted

2019-05-06 Thread Justin Smith
minor nitpick to the answer Sean provided: #{:age} as a function returns
:age for an argument equal to :age and nil for all other inputs, including
a hash map containing that key.

On Sun, May 5, 2019, 22:22  wrote:

> Thanks. What a newbie question.
>
> 在 2019年5月6日星期一 UTC+8上午11:34:36,se...@corfield.org写道:
>>
>> (sort-by #{:age} …) will use the set #{:age} as the keyfn, and both
>> (#{:age} {:age 3, :name “luo”}) and (#{:age} {:age 1, :name “sheng”}) both
>> return :age – because both maps contain the key in the set. As far as
>> sort-by is concerned, both hash maps compare equal.
>>
>>
>>
>> What you want is (sort-by :age …) so you the keyfn pulls the value
>> corresponding to :age out of the hash maps. That will produce 3 from {:age
>> 3, :name “luo”} and 1 from {:age 1, :name “sheng”} so they will sort
>> appropriately.
>>
>>
>>
>> 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: *sheng@gmail.com
>> *Sent: *Sunday, May 5, 2019 7:48 PM
>> *To: *Clojure
>> *Subject: *results from sort-by are not sorted
>>
>>
>>
>> Hey there,
>>
>>
>>
>> in my lein repl,
>>
>>
>>
>> (sort-by #{:age} [{:age 3,:name "luo"},{:age 1,:name "sheng"}])
>>
>>
>>
>> returns
>>
>>
>>
>> ({:age 3, :name "luo"} {:age 1, :name "sheng"})
>>
>>
>>
>> rather than
>>
>>
>>
>> ({:age 1, :name "sheng"}, {:age 3, :name "luo"}).
>>
>>
>>
>> Why?
>>
>> --
>> 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
>> clo...@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 clo...@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: Using map to produce side effects, not working

2019-02-07 Thread Justin Smith
also do note that clojure.core/run! is designed for two-arg map when
it's only run for side effects, and clojure.core/doseq is designed for
nested side-effecting iteration

On Thu, Feb 7, 2019 at 3:33 AM Pierpaolo Tofani
 wrote:
>
> Thanks ! Your diagnosis is correct. With two dorun works fine.
>
> Il giorno giovedì 7 febbraio 2019 12:19:40 UTC+1, Orestis Markou ha scritto:
>>
>> Without having ran your code, it seems that the inner map is not wrapped in 
>> a doall, so while the outer lazy-seq is forced, the inner is not.
>>
>> This might be of interest to you: 
>> http://clojure-doc.org/articles/language/laziness.html
>>
>> If you only want to do map for side effects, you could use dorun instead of 
>> doall.
>>
>> On 7 Feb 2019, at 12:04 PM, Pierpaolo Tofani  wrote:
>>
>> Hi
>> i am new in clojure sorry.
>> In the snippet of code i used two map functions only to produce side effects 
>> on two ref.
>> Even using doall no affect is produced on ref aaa and zzz, seems that the 
>> sequence is still lazy.
>> But if i remove the final :done , and the repl show me the sequence produced 
>> (that i don't care) the ref aaa and zzz are affected.Thanks in advance.
>> PS The two map are in effect doing a for.
>>
>> (def aaa (ref 0))
>> (def zzz (ref 0))
>> (def s1 [1 2 3 4 5])
>> (def s2 [1 2 3 4 5])
>> (defn make-side []
>> (do
>> (doall
>> (map
>>   (fn [x]
>> (map
>>   (fn [y]
>> (dosync
>>   (alter aaa inc)
>>   (alter zzz dec)
>> )
>> )
>>   s2))
>>   s1)
>> )
>> :done
>> )
>> )
>>
>>
>> --
>> 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: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Justin Smith
you are misusing the :: alias resolution operator, user is not an alias

Clojure 1.9.0
(ins)user=> (ns foo)
nil
(ins)foo=> ::user/a
RuntimeException Invalid token: ::user/a
clojure.lang.Util.runtimeException (Util.java:221)
(ins)foo=> :user/a
:user/a

On Tue, Jan 29, 2019 at 2:52 PM Philip Markgraf  wrote:
>
> I am moving some code to use spec and namespaced keywords under Clojure 
> 1.10.0 (release). One group of keywords starts with a numeric character after 
> the colon, which has worked fine in the non-namespaced context. Creating and 
> using the namespaced keyword works correctly in the local namespace (using 
> only the double-colon), but fails with "Invalid Token" when dereferencing 
> from another workspace.
>
> I'm not sure if this is a bug or if I have been taking advantage of an 
> undocumented/unsupported feature.
> Having a leading-digit keyword has been very useful, as the names are an 
> exacting fit of the problem domain and don't suffer from the addition of any 
> visual pollution.
>
> user=> (def example-a {:015-00 "015-00"})
> #'user/example-a
> user=> (def example-b {::015-00 "015-00"})
> #'user/example-b
> user=> (:015-00 example-a)
> "015-00"
> user=> (:015-00 example-b)
> nil
> user=> (::015-00 example-b)
> "015-00"
> user=> (::015-00 example-a)
> nil
> user=> (ns try)
> nil
> try=> (:015-00 user/example-a)
> "015-00"
> try=> (::user/015-00 user/example-b)
>
> Syntax error reading source at (REPL:1:15).
> Invalid token: ::user/015-00
> Syntax error reading source at (REPL:1:31).
> Unmatched delimiter: )
> try=>
>
> The current behavior is certainly inconsistent, even if it is not a serious 
> bug.
>
> Thank you!
>
>
> --
> 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 does Executors/newScheduledThreadPool know how or where to parallelize work?

2019-01-02 Thread Justin Smith
A ScheduledThreadPool doesn't parallelize or partition your work, it
schedules tasks and keeps a pool of Thread objects it can reuse for that
purpose. If you need a job to be broken into smaller pieces, executed on a
schedule, you'll need to implement some sort of coordination. There's some
prior art in frameworks like Quartz that assist with tracking individual
tasks across hosts or restarts of an app, and things like Spark that are
designed for coordinating subdivided tasks and combining results.

As far as I know there's no magic tool that knows how to reliably subdivide
your task.

On Wed, Jan 2, 2019 at 12:47 PM  wrote:

> I guess this is more of a JVM question than a Clojure question, unless
> Clojure exerts any special magic here. I'm open to a more Clojure approach
> than what I have now.
>
> Someone suggested I use Executors/newScheduledThreadPool for some
> recurring work, so I set it up like this:
>
> (def scheduler-aggregate
>   (Executors/newScheduledThreadPool 32))
>
> at the start I call:
>
>   (.scheduleAtFixedRate  scheduler-aggregate ^Runnable (cycle-aggregate
> to-database-queue) 1 30 TimeUnit/MINUTES)
>
> Aside from a try/catch block (which I just removed to simplify this
> example) the inner function looks like this:
>
> (defn- cycle-aggregate
>   [to-database-queue]
>   (fn []
>  (let [
>transcripts (query @global-database-connection {:item-type
> :transcript :processed { operators/$exists false }})
>]
>(doseq [x transcripts]
>  (aggregate-words x)
>  (set-transcript-processed  @global-database-connection x)))
>
> The function (aggregate-words) counts up a bunch of words, doing some prep
> work for a later NLP engine, and then there is this line:
>
> (log "The end of aggregate-words.")))
>
> The whole process takes about 5 minutes to run, about 300 seconds. I watch
> the database and I see the number of new records increase. About every 10
> seconds I see these words appear in the logs:
>
> "The end of aggregate-words."
>
> At the end of 5 minutes, these words have appeared 30 times, one for each
> of the transcripts I'm importing.
>
> This seems like I've done something wrong? Since the words "The end of
> aggregate-words."
> appear at roughly equal intervals, and the transcripts are all about the
> same size, it seems that all of the transcripts are being handled on one
> thread. After all, if the 30 transcripts were handled on 30 threads, I'd
> expect the 30 calls to aggregate-words would all end at roughly the same
> time, instead of sequentially.
>
> What else do I need to do to parallelize this work? If I call (future)
> inside of aggregate-words, would the new thread come from the pool? Is
> there a way I can call aggregate-words and make sure it runs on its own
> thread from the pool?
>
>
>
>
>
>
>
>
>
>
>
>
> --
> 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: Reify (run vs cloverage) (single node vs cluster)

2018-12-31 Thread Justin Smith
Just a hunch, but many cluster / distribution tools expect that a given
Class name will refer to the same Class on each peer. You cannot ensure
this with reify- the name is auto-generated. The solution might be using
deftype or gen-class so that the class name would be deterministic and
shared on each instance.

Another hunch, regarding cloverage, is that an error like that just from
checking test coverage means you have top level side effects (eg. top level
forms or defs that do some kind of IO or launch a process) - Clojure
doesn't have a "compile only" mode, and top level side effects will be
launched by any program that uses Clojure to load your file. The principled
solution is to move side effects into function bodies or delays, and pass
stateful resources as arguments to other code on startup rather than
binding them at the top level. There are multiple lifecycle management
libraries designed for managing this.

On Mon, Dec 31, 2018 at 1:53 PM cloje  wrote:

> I'm really struck at the point where I'm using reify in clojure to
> implement java interface "org.apache.spark.sql.api.java.UDF2" and define
> the method "call" in this interface.
>
> I've been able to use reify to implement and it works fine when I do a
> "lein run", I see that this udf is being applied on my dataframe. I've also
> written test cases to check if the udf is being applied on the dataframe
> and I see that udf is being applied as expected. Now, when I do a "lein
> cloverage" to check my code coverage, this test case fails, giving a
> classNotFoundException.
>
> Partial error stack trace: (running the app on virtual desktop, could not
> copy and paste)
> org.apache.spark.sparkException: Job aborted due to stage failure:
> classNotFoundException: ab.cd.ef.ef$fn$reify__2440
>
>
> *On Hadoop:*
> Getting the same kind of error when I run this application on Cluster mode
> used spark-submit, tried hadoop jar; all give the same error as above. *But,
> *when I run the same jar on a single node, it works fine without any
> issues.
>
> Using Clojure 1.9.0, Cloverage 1.0.13, Spark 2.1.3, Java 1.8.0_141
>
>
> Has anyone been facing this kind of issue? if so, was there a solution?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread Justin Smith
This isn't a clojure issue.

A reference to "process filter" indicates this is an emacs problem. Its
regex syntax matcher tends to blow up on long lines.

On Mon, Dec 24, 2018, 14:57 Andy Fingerhut  wrote:

> I would recommend trying to temporarily rename ~/.lein/profiles.clj to a
> different name, so that there is no such file with that name any more, and
> try your file-seq expression again to see if it behaves any differently.
>
> Andy
>
> On Mon, Dec 24, 2018 at 1:38 PM nenad mitrovic 
> wrote:
>
>> Sorry, here is profiles.clj
>>
>> {:user
>>   {
>>   :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java.exe"
>>   :plugins [
>>
>> [cider/cider-nrepl "0.8.1"]
>> [luminus/lein-template "2.9.9.2"]
>>
>> ]
>>}
>>  }
>>
>> On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>>>
>>> I am trying to execute this piece of code: (rest (file-seq (file (str
>>> "corpus/" "ham"))).
>>> When I execute I get this error: "error in process filter: Stack
>>> overflow in regexp matcher".
>>> I have 1400 files in corpus/ham folder. But when I execute only three
>>> file it works.
>>>
>> --
>> 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: Confusing Regex Behavior

2018-12-04 Thread Justin Smith
You don't need to use re-matcher in that example - the output of re-find
with the regex and the string is identical. If you are using the matcher to
collect a series of matches in one string, you can also uses re-seq which
returns a lazy-seq of the matches of your regex in the string.

On Tue, Dec 4, 2018 at 12:37 PM Randy J. Ray  wrote:

> Oh, that might be it. The newline at the end of the string might be what
> is throwing a wrench into things. Though, to be fair, when I used
> re-matches yesterday the newline wasn't an issue.
>
> Nonetheless, I can work with re-find/re-matcher for now.
>
> On Tue, Dec 4, 2018 at 11:28 AM Andy Fingerhut 
> wrote:
>
>> The doc string for re-matches says that it
>> uses java.util.regex.Matcher.matches().  The Java doc page for the class
>> java.util.regex.Matcher [1] says "The matches
>> 
>>  method
>> attempts to match the entire input sequence against the pattern."
>>
>> The doc string for re-find says that it
>> uses java.util.regex.Matcher.find().  On [1] you can find the statement "
>> The find
>> 
>>  method
>> scans the input sequence looking for the next subsequence that matches the
>> pattern."
>>
>> I haven't dug into your regex and string in detail, but most likely what
>> is happening is that the regex matches part of the string, but it doesn't
>> match the _entire_ string.
>>
>> Andy
>>
>> [1]
>> https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html
>>
>>
>>
>>
>> On Tue, Dec 4, 2018 at 11:16 AM Randy J. Ray  wrote:
>>
>>> I must be doing something wrong here, but I cannot figure this out.
>>>
>>> The following results in "nil" from re-matches:
>>>
>>> (re-matches #"\[((\d+)-(\d+)-(\d+) (\d\d):(\d\d))\] (.*)" "[1518-05-27
>>> 00:42] falls asleep\n")
>>>
>>> This, however, properly matches the line and produces the backreferences:
>>>
>>> (re-find (re-matcher #"\[((\d+)-(\d+)-(\d+) (\d\d):(\d\d))\] (.*)"
>>> "[1518-05-27 00:42] falls asleep\n"))
>>>
>>> I've used re-matches many times, but this has me stumped. This is
>>> behaving this way on both 1.8.0 and 1.9.0.
>>>
>>> Randy
>>> --
>>> Randy J. Ray - randy.j@gmail.com - twitter.com/rjray
>>> Silicon Valley Scale Modelers: http://www.svsm.org
>>> Sunnyvale, CA
>>>
>>> --
>>> 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.
>>
>
>
> --
> Randy J. Ray - randy.j@gmail.com - twitter.com/rjray
> Silicon Valley Scale Modelers: http://www.svsm.org
> Sunnyvale, CA
>
> --
> 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 

Re: Confused by a bit of syntax-- Clojure(script) or Hiccup?

2018-11-20 Thread Justin Smith
I'll add that I knew this, but it took me longer than I expected to
actually find the documentation to point to. I don't know how a new user of
the library would be expected to discover what that symbol means.

On Tue, Nov 20, 2018 at 12:43 PM Justin Smith  wrote:

> :> is a valid Clojure keyword, but has no special meaning on its own.
>
> In Reagent's version of the Hiccup DSL, :> introduces a Reagent component
> defined from a React component
>
> https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md#creating-reagent-components-from-react-components
>
> On Tue, Nov 20, 2018 at 11:27 AM Randy J. Ray  wrote:
>
>> I've been trying to read through and understand the examples in the
>> reagent repo, and I've come across something that I just don't quite get:
>>
>> :>
>>
>> I've looked over all the docs for Clojure, Clojurescript and Hiccup, but
>> find no reference to this. It appears as the first element in vectors in a
>> context that leads me to think it's part of Hiccup. But I'm expecting
>> keywords like ":div", ":p", etc. The ":>" sequence, I guess I'm just not
>> quite getting it?
>>
>> Randy
>> --
>> Randy J. Ray - randy.j@gmail.com - twitter.com/rjray
>> Silicon Valley Scale Modelers: http://www.svsm.org
>> San Jose, CA
>>
>> --
>> 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: Confused by a bit of syntax-- Clojure(script) or Hiccup?

2018-11-20 Thread Justin Smith
:> is a valid Clojure keyword, but has no special meaning on its own.

In Reagent's version of the Hiccup DSL, :> introduces a Reagent component
defined from a React component
https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md#creating-reagent-components-from-react-components

On Tue, Nov 20, 2018 at 11:27 AM Randy J. Ray  wrote:

> I've been trying to read through and understand the examples in the
> reagent repo, and I've come across something that I just don't quite get:
>
> :>
>
> I've looked over all the docs for Clojure, Clojurescript and Hiccup, but
> find no reference to this. It appears as the first element in vectors in a
> context that leads me to think it's part of Hiccup. But I'm expecting
> keywords like ":div", ":p", etc. The ":>" sequence, I guess I'm just not
> quite getting it?
>
> Randy
> --
> Randy J. Ray - randy.j@gmail.com - twitter.com/rjray
> Silicon Valley Scale Modelers: http://www.svsm.org
> San Jose, CA
>
> --
> 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: (type ...) vs (class ...)

2018-10-24 Thread Justin Smith
the type function in clojure.core lets you override the nominal class of an
object with the :type metadata

user=> (type {})

clojure.lang.PersistentArrayMap

user=> (type ^{:type :foo} {})

:foo

On Wed, Oct 24, 2018 at 9:41 AM alex  wrote:

> Looks like pre defrecord stuff used in early days to add "type" to map.
> Can still be used if you need "type" on a map without using defrecord.
>
> среда, 24 октября 2018 г., 10:30:14 UTC+3 пользователь Didier написал:
>
>> Reviving this thread, as I'd like to kmow if someone can explain the
>> purpose of the type metadata and what is responsible for adding 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.
>

-- 
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: OK idea to replace conj and cons with "prepend" and "append" macros that have consistent behavior and return same types as args?

2018-07-20 Thread Justin Smith
another false example above fixed:

user=> (into '(1) '(2 3))

(3 2 1)

On Fri, Jul 20, 2018 at 9:13 AM Christian Seberino 
wrote:

> Wow thanks.  That was pretty thorough.
>
> cs
>
>
> On Friday, July 20, 2018 at 10:51:48 AM UTC-5, Gary Johnson wrote:
>>
>> Hi Christian,
>>
>> You are looking for "into", which is already part of the Clojure standard
>> library.
>>
>> Appending:
>>
>> (into '(1 2) '(3)) ;=>  (1 2 3)
>> (into [1 2] [3])   ;=>  [1 2 3]
>> (into {:a 1 :b 2} {:c 3})  ;=>  {:a 1, :b 2, :c 3}
>> (into #{:a :b} #{:c})  ;=>  #{:c :b :a}
>>
>> Prepending:
>>
>> (into '(1) '(2 3)) ;=>  (1 2 3)
>> (into [1] [2 3])   ;=>  [1 2 3]
>> (into {:a 1} {:b 2 :c 3})  ;=>  {:a 1, :b 2, :c 3}
>> (into #{:a} #{:b :c})  ;=>  #{:c :b :a}
>>
>> The "into" function pours the contents of the second collection into the
>> first collection, returning a collection of the same type as the first
>> argument.
>>
>> That being said, I agree with Alex and James in this rather lengthy
>> discussion. Clojure is unique among the Lisps in that it moved beyond
>> having linked lists as the only first class data structure.
>>
>> Prior to Clojure, if you worked in a Lisp like Scheme or Common Lisp, you
>> would design your program around the creation, traversal, and manipulation
>> of linked lists using higher order functions and explicit recursions. The
>> standard library in both languages is heavily focused on these list-related
>> operations. After developing the initial version of your program, if you
>> found that it was too slow or used too much memory, the accepted practice
>> was to profile your application to identify the functions that were getting
>> hammered the most and were using up the majority of your computing
>> resources. You would then often end up rewriting those function bodies in
>> an imperative fashion using loops and mutable data structures (i.e., arrays
>> and hashtables). The "wisdom" here was that this would enable you to "first
>> make it right, then make it fast". If even further performance was required
>> from your program, you might then rewrite part of your program in C, build
>> a foreign function interface (FFI) to link the C code into your Lisp
>> program, and go from there. These were the Bad Old Days of Lisp(TM).
>>
>> What was IMHO quite possibly Rich's greatest contribution in the design
>> of Clojure to the Lisp world was his decision to make additional data
>> structures first class citizens of the language. Most importantly, he did
>> so by creating Clojure's vectors, maps, and sets to be immutable,
>> persistent, performant, recursively constructed, and representable as data
>> literals. This was already a wonderful improvement over previous Lisps, but
>> it created a new problem: How could we enjoy the pure delight of
>> list-oriented programming that Lisp had always offered us now that the data
>> structure space had been fragmented? A famous quote from Alan Perlis is a
>> popular gem in the Lisp world, and it goes like so:
>>
>> "It is better to have 100 functions operate on one data structure than to
>> have 10 functions operate on 10 data structures."
>>
>> Every Lisp had always satisfied this by simply giving programmers only
>> one first class data structure to use: the linked list. As I already
>> mentioned, the bulk of its standard library would then be built around list
>> manipulation functions. Clojure needed a way to preserve this unified style
>> of programming while still providing a collection of performant data
>> structures for real-world programming. So how did Rich accomplish this?
>>
>> He created the "sequence abstraction". A sequence in Clojure serves a
>> similar role to the linked list of previous Lisps in that it unifies the
>> API for interacting with all of Clojure's first class data structures
>> (list, vector, map, set). By calling the function "seq" on any data
>> structure, you are given a list-like view of that collection that allows
>> you to traverse it from beginning to end one element at a time and to add
>> new elements to the beginning of it. These operations are called "first",
>> "rest", and "cons", and they behave precisely as you would expect them to
>> if you were calling them on a linked list.
>>
>> By using seq throughout the Clojure sequence library (i.e., the set of
>> standard library functions responsible for creating, traversing,
>> transforming, and manipulating sequences), Clojure is able to have single
>> implementations of all of the common Lispy higher order list transformation
>> functions. For example, we have "map", "filter", "reduce", "iterate",
>> "take", "drop", "repeat", "cycle", and so on. The amazing thing is that
>> these can all take any of Clojure's data structures as their inputs. So you
>> can call map on a list, vector, map, or set without having to change the
>> function signature. Without the sequence abstraction, we could need
>> multiple functions for every data structure 

Re: core.async buffered channel behavior

2018-06-27 Thread Justin Smith
I should be more precise there, by "consumed" I meant buffered or consumed.

On Wed, Jun 27, 2018 at 10:17 AM Justin Smith  wrote:

> I doubt core.async would ever make promises about the behavior of a
> blocking put that gets forcibly cancelled. It promises that the blocking
> put doesn't return until the message is consumed, but that's not the same
> as promising that the message isn't consumed if the blocking put is
> forcibly cancelled.
>
> On Wed, Jun 27, 2018 at 9:47 AM Didier  wrote:
>
>> I think its due to ctrl+c, not sure what it actually does, but maybe it
>> didn't actually kill the blocked thread?
>>
>> --
>> 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: core.async buffered channel behavior

2018-06-27 Thread Justin Smith
I doubt core.async would ever make promises about the behavior of a
blocking put that gets forcibly cancelled. It promises that the blocking
put doesn't return until the message is consumed, but that's not the same
as promising that the message isn't consumed if the blocking put is
forcibly cancelled.

On Wed, Jun 27, 2018 at 9:47 AM Didier  wrote:

> I think its due to ctrl+c, not sure what it actually does, but maybe it
> didn't actually kill the blocked thread?
>
> --
> 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: Plain clojure 1.9 fails with Could not locate ... clojure/spec/alpha.clj on classpath. in Kubuntu 18.04

2018-05-21 Thread Justin Smith
I should have been more specific. Just uninstalling leaves old configs
around, and fixing this requires a full purge of the package.

these are my steps on a debian system:

$ sudo dpkg --purge --force-depends ca-certificates-java
$ sudo apt-get install ca-certificates-java


sourced from this stackoverflow answer
https://stackoverflow.com/a/33440168

On Mon, May 21, 2018 at 12:28 PM Andy Fingerhut 
wrote:

>
> Jesús:
>
> Agreed that this issue is frustrating.  It doesn't necessarily help you
> here, but realize that this issue appears like it might be unique to Ubuntu
> 18.04's OpenJDK installations.
>
> This issue did not occur with earlier versions of Ubuntu that I am aware
> of.
>
> Andy
>
> On Mon, May 21, 2018 at 10:29 AM, Jesús Gómez  wrote:
>
>> I followed the Getting Started guide and nothing worked well, except
>> for the boot with nix installation.
>>
>> The clj tools Linux instructions failed the same way the lein one
>> failed: Error with some certs [1]
>> I've been told that this problem could be solved if I install Oracle
>> Java instead of using OpenJDK. I don't want to do that.
>>
>> I avoided the local build instructions because it was going to require
>> maven. I don't want to use it for now.
>>
>> So, for now I'm working with the Clojure 1.8 jar.
>>
>> I must say, Clojure is a good language, but the tooling is awful, not
>> userfriendly, not beginers friendly. Maven is a beast, is the only
>> thing had keped me away of Java for years, and now I must live with
>> it, Voluntarily (I'm learning Clojure not because the work, but
>> because I like it too much).
>>
>> Probably I should try Clojurescript instead.
>>
>> Thank you.
>>
>> [1]
>> Could not transfer artifact
>> clojure-complete:clojure-complete:jar:0.2.4 from/to central
>> (https://repo1.maven.org/maven2/): java.lang.RuntimeException:
>> Unexpected error: java.security.InvalidAlgorithmParameterEx
>> ception: the trustAnchors parameter must be non-empty
>> .
>> .
>> .
>>
>>
>> 2018-05-21 14:40 GMT-02:30 Alex Miller :
>> > As of Clojure 1.9, the Clojure jar depends on two additional libraries
>> > (spec.alpha and core.specs.alpha). Using only the clojure jar is thus
>> not
>> > sufficient.
>> >
>> > There are several ways to handle this, as described on the
>> > https://clojure.org/guides/getting_started page.
>> >
>> > 1. Use the new command line clj tools (linux install instructions on
>> that
>> > page) - this will fetch the deps for you.
>> > 2. Do a local build into a single standalone jar (note this is a custom
>> jar
>> > containing deps and is different than just the artifact you downloaded).
>> > 3. Use a build tool like leiningen or boot that will fetch the deps for
>> you.
>> > 4. Download clojure and its deps manually and build your own custom
>> > classpath. (not recommended)
>> >
>> >
>> > On Monday, May 21, 2018 at 11:17:37 AM UTC-5, Jesús Gómez wrote:
>> >>
>> >> Simply: 1.7 works but 1.9 not.
>> >>
>> >> Test:
>> >>
>> >> $ # Download Clojure 1.7, 1.8 and 1.9 jars
>> >> $ seq 7 9 | xargs -L1 -I% wget
>> >>
>> http://repo1.maven.org/maven2/org/clojure/clojure/1.%.0/clojure-1.%.0.jar
>> >> $ seq 7 9 | xargs -L1 -I% java -jar clojure-1.%.0.jar -e '"1.%.0 is
>> >> Working"'
>> >> "1.7.0 is Working"
>> >> "1.8.0 is Working"
>> >> Exception in thread "main" java.lang.ExceptionInInitializerError
>> >> ...
>> >> Caused by: java.io.FileNotFoundException: Could not locate
>> >> clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath.
>> >> ...
>> >>
>> >> I've been trying to learn Clojure, so I've installed it in many ways:
>> >>
>> >>  * Lein - Not working due some SSL credential
>> >>  * boot vian nix - Working but ... I don't remember the why already...
>> >> something related with CIDR?... not important for this post anyways
>> >>  * via apt - Working but I can't make a simple clojure -m hello to work
>> >>
>> >> So I tried to understand the basics (No maven, no 3rd parties, etc.)
>> and
>> >> found the mentioned problem.
>> >>
>> >> I was expecting it to work flawless and to not be affected on what I
>> got
>> >> already installed in my system, but probably is the fact I installed
>> clojure
>> >> via APT, which installed 1.9.0, that is causing the jar for 1.9.0 to
>> fail
>> >> and not the others.
>> >>
>> >> In any case... 1.9.0 jar is not working for me.
>> >>
>> >> Thank you.
>> >
>> > --
>> > 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" 

Re: Plain clojure 1.9 fails with Could not locate ... clojure/spec/alpha.clj on classpath. in Kubuntu 18.04

2018-05-21 Thread Justin Smith
this is a problem with your distribution's config for installing the vm, on
debian based systems it can be fixed by forcing reinstall of ca-certs, it
does not require an oracle vm

On Mon, May 21, 2018 at 10:30 AM Jesús Gómez  wrote:

> I followed the Getting Started guide and nothing worked well, except
> for the boot with nix installation.
>
> The clj tools Linux instructions failed the same way the lein one
> failed: Error with some certs [1]
> I've been told that this problem could be solved if I install Oracle
> Java instead of using OpenJDK. I don't want to do that.
>
> I avoided the local build instructions because it was going to require
> maven. I don't want to use it for now.
>
> So, for now I'm working with the Clojure 1.8 jar.
>
> I must say, Clojure is a good language, but the tooling is awful, not
> userfriendly, not beginers friendly. Maven is a beast, is the only
> thing had keped me away of Java for years, and now I must live with
> it, Voluntarily (I'm learning Clojure not because the work, but
> because I like it too much).
>
> Probably I should try Clojurescript instead.
>
> Thank you.
>
> [1]
> Could not transfer artifact
> clojure-complete:clojure-complete:jar:0.2.4 from/to central
> (https://repo1.maven.org/maven2/): java.lang.RuntimeException:
> Unexpected error: java.security.InvalidAlgorithmParameterEx
> ception: the trustAnchors parameter must be non-empty
> .
> .
> .
>
>
> 2018-05-21 14:40 GMT-02:30 Alex Miller :
> > As of Clojure 1.9, the Clojure jar depends on two additional libraries
> > (spec.alpha and core.specs.alpha). Using only the clojure jar is thus not
> > sufficient.
> >
> > There are several ways to handle this, as described on the
> > https://clojure.org/guides/getting_started page.
> >
> > 1. Use the new command line clj tools (linux install instructions on that
> > page) - this will fetch the deps for you.
> > 2. Do a local build into a single standalone jar (note this is a custom
> jar
> > containing deps and is different than just the artifact you downloaded).
> > 3. Use a build tool like leiningen or boot that will fetch the deps for
> you.
> > 4. Download clojure and its deps manually and build your own custom
> > classpath. (not recommended)
> >
> >
> > On Monday, May 21, 2018 at 11:17:37 AM UTC-5, Jesús Gómez wrote:
> >>
> >> Simply: 1.7 works but 1.9 not.
> >>
> >> Test:
> >>
> >> $ # Download Clojure 1.7, 1.8 and 1.9 jars
> >> $ seq 7 9 | xargs -L1 -I% wget
> >>
> http://repo1.maven.org/maven2/org/clojure/clojure/1.%.0/clojure-1.%.0.jar
> >> $ seq 7 9 | xargs -L1 -I% java -jar clojure-1.%.0.jar -e '"1.%.0 is
> >> Working"'
> >> "1.7.0 is Working"
> >> "1.8.0 is Working"
> >> Exception in thread "main" java.lang.ExceptionInInitializerError
> >> ...
> >> Caused by: java.io.FileNotFoundException: Could not locate
> >> clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath.
> >> ...
> >>
> >> I've been trying to learn Clojure, so I've installed it in many ways:
> >>
> >>  * Lein - Not working due some SSL credential
> >>  * boot vian nix - Working but ... I don't remember the why already...
> >> something related with CIDR?... not important for this post anyways
> >>  * via apt - Working but I can't make a simple clojure -m hello to work
> >>
> >> So I tried to understand the basics (No maven, no 3rd parties, etc.) and
> >> found the mentioned problem.
> >>
> >> I was expecting it to work flawless and to not be affected on what I got
> >> already installed in my system, but probably is the fact I installed
> clojure
> >> via APT, which installed 1.9.0, that is causing the jar for 1.9.0 to
> fail
> >> and not the others.
> >>
> >> In any case... 1.9.0 jar is not working for me.
> >>
> >> Thank you.
> >
> > --
> > 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 

Re: doall

2018-05-16 Thread Justin Smith
as an aside, :1 etc. are bad keywords (accepted by some readers and not
others, technically not valid according to the docs), and usually the
presence of keywords like that indicates over-eager keywordizing of json
input, or a misunderstanding of clojure hash-maps

On Wed, May 16, 2018 at 12:38 PM Mauricio Aldazosa <
mauricio.aldaz...@gmail.com> wrote:

> Hi Renata,
>
> The problem with your code is that it is using *map* at the top level,
> which is a function that returns a lazy sequence. You are asking clojure to
> do something like:
>
> *Take each number n in inviteds and create a sequence of hash maps, where
> each hash map has n as a key and 1 as it's value.*
>
> But what you really want is a function at the top level that returns a
> hash map. As Colin shows, you can use *into* (here is a slightly
> different way than the one he used):
>
> *Take each number in inviteds and create a sequence of pairs. Each pair
> should have the number as it's first value, and 1 as the second. Then take
> those pairs, and "pour" them into a hash map.*
>
> (->> inviteds
>  (map (fn [number] (vector number 1)))
>  (into {}))
>
> You could also do it via *reduce*:
>
> *Start with an empty hash map, then assoc each number in inviteds with 1
> as it's value*:
>
> (reduce (fn [m number] (assoc m number 1))
> {}
> inviteds)
>
> Cheers,
> Mauricio
>
> --
> 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: Custom core.async go threadpools? Using go parking for heavy calculation parallelism throughput?

2018-05-01 Thread Justin Smith
Just a couple of small points (and not yet a full answer):

> A node can obviously not pmap over all the child nodes (would spawn
exponential amount of threads)

pmap is not that naive, it uses a pool sized with the assumption that its
work is CPU bound

> (2) Made me wonder why I couldn't use the go machinery for this. Parent
nodes that would "wait" for their child nodes to complete would park,
making their thread available to their child nodes.

This is why async/thread exists, it returns a channel you can park in, and
you can use channels coming into the blocks starting threads to control the
parallelism by hand.

On Tue, May 1, 2018, 03:41 Leon Grapenthin  wrote:

> Recently I worked on an algorithm where a distributed tree is (sort of)
> flattened in a way that each node runs a commutative aggregation over all
> of its child nodes calculations.
>
> 1 A node can obviously not pmap over all the child nodes (would spawn
> exponential amount of threads).
>
> 2 If I want to limit the threads using a threadpool, child nodes will
> quickly run out of threads and we can't reuse their parents threads because
> they are blocking, waiting for the child nodes to complete, calculating
> nothing.
>
> It sure could be possible to implement this with an unlimited threadpool
> and some machinery that ensures that no more than N computations are
> happening in parallel. Nonetheless an insane amount of threads would be
> spawned.
>
> (2) Made me wonder why I couldn't use the go machinery for this. Parent
> nodes that would "wait" for their child nodes to complete would park,
> making their thread available to their child nodes.
>
> So of course I could just do it, but the per node computations are
> presumably too heavy for the lightweight go threadpool.
>
> How realistic/useful would it be to have sth. like a (go-with threadpool
> []) in this scenario?
>
> --
> 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 in uberjar

2018-02-15 Thread Justin Smith
To elaborate on Nicola's correct answer, when -main is run from outside its
namespace, the binding of mx comes from the current environment (which
doesn't see a macro, and likely has no binding for mx). If you use ` in
-main, the currently visible binding is properly namespace qualified so
that it expands when called from outside the namespace.

On Thu, Feb 15, 2018, 03:12 Nicola Mometto  wrote:

> Use ` instead of '
>
>
> On 15 Feb 2018, at 08:45, 'Burt' via Clojure 
> wrote:
>
> Here is something strange, and I don't see why!
> Can anybody help?
>
> This is the code in m.clj
>
> (ns m
>   (:gen-class))
>
> (defmacro mx
>   [x]
>   (list 'y))
>
> (defn -main []
>   (println (macroexpand-1 '(mx P)))
>   (println (macroexpand-1 '(and P Q
>
>
> 1 When i load the namespace into a REPL and invoke (-main)
>
> the result is (as expected):
>
>
> (y)
> (clojure.core/let [and__5236__auto__ P] (if and__5236__auto__ 
> (clojure.core/and Q) and__5236__auto__))
> => nil
>
>
> 2 When I make an uberjar with leiningen (in IntelliJ with cursive) and run 
> the jar
>
> the result is (not as expected):
>
>
> (mx P)
> (clojure.core/let [and__5236__auto__ P] (if and__5236__auto__ 
> (clojure.core/and Q) and__5236__auto__))
>
>
> In the second case the macro mx is not expanded and I have no idea why this 
> is the case.
>
>
> Kind regards,
>
> Burt
>
>
> --
> 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: tlc Expect like library?

2018-02-13 Thread Justin Smith
I've long thought implementing something like TCL expect in Clojure would
be a fun project, as far as I know it hasn't been tried (though the google
results are drowned out by the Expectations testing library so who
knows...).

If I were doing this from scratch I'd start with the Process and
ProcessBuilder APIs, or use node child_process API with cljs. core.match
might be useful for program interaction dispatch.

On Tue, Feb 13, 2018 at 4:42 AM Stephen Feyrer 
wrote:

> Hi,
>
> I would like to ask, is there a Clojure version of the tlc expect library
> or an equivalent?
>
> Something to launch and control other applications.  Specifically I want
> to control text based terminal application.  Emulating the screen, moving
> the cursor around and firing character codes at it?
>
> Thanks.
>
>
> Stephen Feyrer.
>
> --
> 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: namespace - multiple people

2018-02-10 Thread Justin Smith
On further reflection, in most cases you can avoid defmulti and
defprotocol, and write functions that accept data and return data to
implement most of your logic. In that case a "stub" is simply a data
literal of the appropriate shape. Start with some conventions about how the
data should be structured, then write code that knows how to handle that
data.

On Sat, Feb 10, 2018 at 10:06 AM Justin Smith <noisesm...@gmail.com> wrote:

> One approach to this sort of parallel development is having each developer
> code against the interface of other modules, while implementing the
> interface of their own module, so that their code can use stubs of
> interfaces before the production versions are available.
>
> Perhaps in Clojure this could be done with defprotocol or defmulti in a
> bare bones shared namespace, calling methods from that namespace to
> implement your own functionality, while implementing some of the methods
> for others.
>
> On Sat, Feb 10, 2018 at 9:57 AM Alex Miller <a...@puredanger.com> wrote:
>
>> There are other options to manage multiple projects without creating jars
>> using either local or git deps in clj. Don’t have time to give a full
>> example atm but just wanted to mention it.
>>
>> https://clojure.org/guides/deps_and_cli
>>
>> --
>> 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: namespace - multiple people

2018-02-10 Thread Justin Smith
One approach to this sort of parallel development is having each developer
code against the interface of other modules, while implementing the
interface of their own module, so that their code can use stubs of
interfaces before the production versions are available.

Perhaps in Clojure this could be done with defprotocol or defmulti in a
bare bones shared namespace, calling methods from that namespace to
implement your own functionality, while implementing some of the methods
for others.

On Sat, Feb 10, 2018 at 9:57 AM Alex Miller  wrote:

> There are other options to manage multiple projects without creating jars
> using either local or git deps in clj. Don’t have time to give a full
> example atm but just wanted to mention it.
>
> https://clojure.org/guides/deps_and_cli
>
> --
> 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 does future do after fn finish ?

2018-02-02 Thread Justin Smith
-> is just a list transform performed after reading your code into a list
data structure containing symbols, and before compiling to byte code - it
doesn't do anything directly.

On Fri, Feb 2, 2018 at 3:55 PM Jacek Grzebyta 
wrote:

> OK I found what makes the memory leak.
>
> In the project I work with I use a  java Model class which is java
> Collection proxy/facade for a single transaction. Unfortunately it's not
> thread safe. In a few places I passed single instance of model into several
> threads Also I requested the instance with -> which makes new thread as
> well. I was surprised that -> makes trouble but after thinking that might
> be expected. Especially that internally the wrapper doesn't do simple
> mapping - it uses some iterator, etc. Anyway the machinery is fragile. It
> seems I need to rewrite code and replace all multithreading parts by
> something simpler.
>
>
>
> If you want see the stacktrace just look at:
> https://github.com/jgrzebyta/triple-loader/issues/53
>
> On 2 February 2018 at 11:16, Jacek Grzebyta 
> wrote:
>
>>
>> On 2 February 2018 at 08:34, Niels van Klaveren <
>> niels.vanklave...@gmail.com> wrote:
>>
>>> +1 for Claypoole, it removed the needs of using agents or futures in 95%
>>> of the cases in my code.
>>>
>>>
>> Thanks a lot. I modify the code using claypoole. I imagine with-shutdown
>> will close the pool properly after finish all tasks so there is no need to
>> watch them?
>>
>> J
>>
>>
>
> --
> 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 does future do after fn finish ?

2018-02-01 Thread Justin Smith
yes, that's the idea exactly

also, you might want more fine grained control of how much parallelism
occurs (eg. if every thread is writing to the same physical device, you can
often get better throughput by not parallelizing at all, or keeping the
parallelism quite limited - it's worth experimenting) - there are good ways
to control that using ThreadPoolExecutor directly, or using
clojure.lang.PersistentQueue/EMPTY as a control construct, or core.async
channels, or ztellman's manifold library, or the claypoole threading library

On Thu, Feb 1, 2018, 03:44 Jacek Grzebyta <grzebyta@gmail.com> wrote:

> Thanks folks. I see now! It should be a list of agents not list of futures
> within agent.  Also any task sent to a agent is processed within a
> thread anyway so I do not need to add future...
>
> On 1 February 2018 at 02:17, John Newman <john...@gmail.com> wrote:
>
>> Ah, he's using one agent, I see.
>>
>> On Jan 31, 2018 9:15 PM, "John Newman" <john...@gmail.com> wrote:
>>
>>> Multiple sen-doffs to one agent will serialize it's calls, but spawning
>>> agents on each new task will spawn threads on a bounded thread pool, I
>>> believe.
>>>
>>> On Jan 31, 2018 8:32 PM, "Justin Smith" <noisesm...@gmail.com> wrote:
>>>
>>>> Doing all the actions via one agent means that the actions are
>>>> serialized though - you end up with no performance improvement over doing
>>>> them all in a doseq in one future - the right way to do this tends to be
>>>> trickier than it looks at first glance, and depends on your requirements.
>>>> agents, the claypoole library, and reducers are all potentially useful. If
>>>> parallelization leads to complex coordination needs, core.async can help
>>>> too.
>>>>
>>>> On Wed, Jan 31, 2018 at 5:18 PM John Newman <john...@gmail.com> wrote:
>>>>
>>>>> Agents manage a pool of threads for you. Try doing it without the
>>>>> future call and see if that works (unless you're trying to do something
>>>>> else).
>>>>>
>>>>> John
>>>>>
>>>>> On Wed, Jan 31, 2018 at 7:31 PM, Jacek Grzebyta <
>>>>> grzebyta@gmail.com> wrote:
>>>>>
>>>>>> Thanks a lot. I will check it tomorrow.
>>>>>>
>>>>>> J
>>>>>>
>>>>>> On 1 Feb 2018 12:12 a.m., "Justin Smith" <noisesm...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> this is exactly the kind of problem code I was describing - there's
>>>>>>> no backpressure on existing future tasks to hold up the launching of 
>>>>>>> more
>>>>>>> futures - the work done by the agent calling conj is negligible. You 
>>>>>>> need
>>>>>>> to control the size of the pool of threads used, and you need to impose
>>>>>>> back-pressure.
>>>>>>>
>>>>>>> On Wed, Jan 31, 2018 at 3:46 PM Jacek Grzebyta <
>>>>>>> grzebyta@gmail.com> wrote:
>>>>>>>
>>>>>>>> On 31 January 2018 at 18:08, James Reeves <ja...@booleanknot.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> On 31 January 2018 at 17:59, Jacek Grzebyta <
>>>>>>>>> grzebyta@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> I have application with quite intense tripe store populating
>>>>>>>>>> ~30/40 k records per chunk (139 portions). The data are wrapped 
>>>>>>>>>> within the
>>>>>>>>>> future:
>>>>>>>>>>
>>>>>>>>>> (conj agent (future (apply task args)))
>>>>>>>>>>
>>>>>>>>>>  and that all together is send-off into (agent []).
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> What is "agent"? The first line of code indicates that it's a
>>>>>>>>> local collection shadowing the code function, while the second code 
>>>>>>>>> snippet
>>>>>>>>> indicates that you're using the core agent function.
>>>>>>>>>
>>>>>>>>> Also why are you sending off to an agent?
>>>

Re: what does future do after fn finish ?

2018-01-31 Thread Justin Smith
Doing all the actions via one agent means that the actions are serialized
though - you end up with no performance improvement over doing them all in
a doseq in one future - the right way to do this tends to be trickier than
it looks at first glance, and depends on your requirements. agents, the
claypoole library, and reducers are all potentially useful. If
parallelization leads to complex coordination needs, core.async can help
too.

On Wed, Jan 31, 2018 at 5:18 PM John Newman <john...@gmail.com> wrote:

> Agents manage a pool of threads for you. Try doing it without the future
> call and see if that works (unless you're trying to do something else).
>
> John
>
> On Wed, Jan 31, 2018 at 7:31 PM, Jacek Grzebyta <grzebyta@gmail.com>
> wrote:
>
>> Thanks a lot. I will check it tomorrow.
>>
>> J
>>
>> On 1 Feb 2018 12:12 a.m., "Justin Smith" <noisesm...@gmail.com> wrote:
>>
>>> this is exactly the kind of problem code I was describing - there's no
>>> backpressure on existing future tasks to hold up the launching of more
>>> futures - the work done by the agent calling conj is negligible. You need
>>> to control the size of the pool of threads used, and you need to impose
>>> back-pressure.
>>>
>>> On Wed, Jan 31, 2018 at 3:46 PM Jacek Grzebyta <grzebyta@gmail.com>
>>> wrote:
>>>
>>>> On 31 January 2018 at 18:08, James Reeves <ja...@booleanknot.com>
>>>> wrote:
>>>>
>>>>> On 31 January 2018 at 17:59, Jacek Grzebyta <grzebyta@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I have application with quite intense tripe store populating ~30/40 k
>>>>>> records per chunk (139 portions). The data are wrapped within the future:
>>>>>>
>>>>>> (conj agent (future (apply task args)))
>>>>>>
>>>>>>  and that all together is send-off into (agent []).
>>>>>>
>>>>>
>>>>> What is "agent"? The first line of code indicates that it's a local
>>>>> collection shadowing the code function, while the second code snippet
>>>>> indicates that you're using the core agent function.
>>>>>
>>>>> Also why are you sending off to an agent?
>>>>>
>>>>
>>>> I have ~8sec computing task for each input dataset which generates
>>>> those records. After that I write it into disk (in software-specific
>>>> transaction). I just wanted to separate hard computing and io operations. I
>>>> created a side-effect method which is injected together with the dataset
>>>> into a future. The futures are async collected within a list wrapped in
>>>> agent. After the computing the main thread is waiting until all io tasks
>>>> will be finished.
>>>>
>>>>
>>>>>
>>>>> At the end of the main thread function I just use await-for and after
>>>>>> that:
>>>>>>
>>>>>> (reduce + (map #(deref %) @data-loading-tasks))
>>>>>>
>>>>>
>>>> As a control, tasks return number of written records.
>>>>
>>>>
>>>>
>>>>>
>>>>>> For some reason I see the happy collecting (see attached screenshot
>>>>>> of jconsole).
>>>>>>
>>>>>
>>>>> "happy" = "heap"?
>>>>>
>>>>
>>>> Both. As you can see on attached screenshot the heap usage grows easy
>>>> until aver. ~2 1/4 G than keep that  for a few minutes. In that moment I
>>>> stopped. After that starts grow till ~4G with tendency to do jumps a bit
>>>> more that 4G.
>>>>
>>>>
>>>>>
>>>>>
>>>>>> After seeing the source code of future I suppose that the memory
>>>>>> (data are kept as #{} set) is not released. The task returns only integer
>>>>>> so I do not think that might cause the problem.
>>>>>>
>>>>>
>>>>> Can you provide more detail? You keep alluding to things that you
>>>>> don't provide code for, such as the sets of data.
>>>>>
>>>>
>>>>
>>>> The code is attached. However the important code is
>>>>
>>>> L123 .
>>>>   (let [;; keeps all data loading futures.
>>>> ;; waiting until all 

Re: what does future do after fn finish ?

2018-01-31 Thread Justin Smith
this is exactly the kind of problem code I was describing - there's no
backpressure on existing future tasks to hold up the launching of more
futures - the work done by the agent calling conj is negligible. You need
to control the size of the pool of threads used, and you need to impose
back-pressure.

On Wed, Jan 31, 2018 at 3:46 PM Jacek Grzebyta 
wrote:

> On 31 January 2018 at 18:08, James Reeves  wrote:
>
>> On 31 January 2018 at 17:59, Jacek Grzebyta 
>> wrote:
>>
>>> I have application with quite intense tripe store populating ~30/40 k
>>> records per chunk (139 portions). The data are wrapped within the future:
>>>
>>> (conj agent (future (apply task args)))
>>>
>>>  and that all together is send-off into (agent []).
>>>
>>
>> What is "agent"? The first line of code indicates that it's a local
>> collection shadowing the code function, while the second code snippet
>> indicates that you're using the core agent function.
>>
>> Also why are you sending off to an agent?
>>
>
> I have ~8sec computing task for each input dataset which generates those
> records. After that I write it into disk (in software-specific
> transaction). I just wanted to separate hard computing and io operations. I
> created a side-effect method which is injected together with the dataset
> into a future. The futures are async collected within a list wrapped in
> agent. After the computing the main thread is waiting until all io tasks
> will be finished.
>
>
>>
>> At the end of the main thread function I just use await-for and after
>>> that:
>>>
>>> (reduce + (map #(deref %) @data-loading-tasks))
>>>
>>
> As a control, tasks return number of written records.
>
>
>
>>
>>> For some reason I see the happy collecting (see attached screenshot of
>>> jconsole).
>>>
>>
>> "happy" = "heap"?
>>
>
> Both. As you can see on attached screenshot the heap usage grows easy
> until aver. ~2 1/4 G than keep that  for a few minutes. In that moment I
> stopped. After that starts grow till ~4G with tendency to do jumps a bit
> more that 4G.
>
>
>>
>>
>>> After seeing the source code of future I suppose that the memory (data
>>> are kept as #{} set) is not released. The task returns only integer so I do
>>> not think that might cause the problem.
>>>
>>
>> Can you provide more detail? You keep alluding to things that you don't
>> provide code for, such as the sets of data.
>>
>
>
> The code is attached. However the important code is
>
> L123 .
>   (let [;; keeps all data loading futures.
> ;; waiting until all futures are finished
> ;; should be done outside the main loop
> data-loading-tasks (agent [])]
>
> L128
> (doseq
>  (let [r1 (long operation)]   L133
>  (doseq
> (let [r2 (v.v. long)]   L155
>
>   L163   (send-off data-loading-task conj-task)
>
>  )
>  )
> )
> )
>
>
> I guess first I will move data-loading-tasks list into one of inner lets.
> Also I will create within an injecting function a separate abstract
> function let inside. The task will populate tmp variable which will be
> returned as a future result:
>
>
> L114 (conj agent (future (apply (fn [] (let [result (apply task args)]
> result)
>
>
>>
>> --
>> James Reeves
>> booleanknot.com
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to 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 

Re: what does future do after fn finish ?

2018-01-31 Thread Justin Smith
As a shot in the dark, a common problem with memory usage and futures that
I have seen is the antipattern of launching a future for each piece of data
in a collection. The problem that occurs is that the code works for small
input collections and a small load of running tasks / requests, but for a
larger input and more requests it uses up the heap easily. Then, a dev
assumes that somehow the future itself is leaking or otherwise taking up
space it shouldn't, when the true problem is that the undbounded creation
of futures happens to exhaust your available memory space. If you aren't
doing such a thing feel free to disregard.

On Wed, Jan 31, 2018 at 10:09 AM James Reeves  wrote:

> On 31 January 2018 at 17:59, Jacek Grzebyta 
> wrote:
>
>> I have application with quite intense tripe store populating ~30/40 k
>> records per chunk (139 portions). The data are wrapped within the future:
>>
>> (conj agent (future (apply task args)))
>>
>>  and that all together is send-off into (agent []).
>>
>
> What is "agent"? The first line of code indicates that it's a local
> collection shadowing the code function, while the second code snippet
> indicates that you're using the core agent function.
>
> Also why are you sending off to an agent?
>
> At the end of the main thread function I just use await-for and after that:
>>
>> (reduce + (map #(deref %) @data-loading-tasks))
>>
>> For some reason I see the happy collecting (see attached screenshot of
>> jconsole).
>>
>
> "happy" = "heap"?
>
>
>> After seeing the source code of future I suppose that the memory (data
>> are kept as #{} set) is not released. The task returns only integer so I do
>> not think that might cause the problem.
>>
>
> Can you provide more detail? You keep alluding to things that you don't
> provide code for, such as the sets of data.
>
> --
> James Reeves
> booleanknot.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to 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-26 Thread Justin Smith
a nitpick on point 1 - I would assume you can't expect hotspot to improve
anything in the timescale of a program startup

am I missing something here?

On Fri, Jan 26, 2018 at 10:32 AM Alex Miller  wrote:

> With a few custom patches (which are pending in jira) + AOT + direct
> linking + lazy vars + var meta elision + jvm flags, I have gotten raw
> startup as low as ~450 ms. Past that, radical changes are probably required
> which are unlikely to be worth doing.
>
> On your conclusions:
>
> 1. minimize CAS'es - I'm doubtful this would make much difference. Hotspot
> is usually pretty good at optimizing that stuff in single-threaded
> uncontended scenarios. I will wave in the general direction of immutable
> namespaces to a place that I think is an opportunity to improve a range of
> issues like this.
>
> 2. Lazy vars effectively do this (in tandem with AOT and direct linking)
> and it can help 20-30% (presuming you have compiled stuff to use). However,
> most startup cases don't have AOT compiled code to work with and thus this
> won't help at all.
>
> 3. Prefetching - as you found, I would not expect this to be useful enough
> to be worth the pain and fragility involved.
>
> 4. jaotc - I think this *is* likely to be useful for cases where you can
> pre-stage stuff like this, in particular core itself is a perfect
> opportunity. People have already tested this (
> https://mjg123.github.io/2017/10/04/AppCDS-and-Clojure.html) and found it
> useful. But again, requires pre-AOT'ed code.
>
> I don't think most of these changes help at all though in the most common
> case where you are spinning up a project with a lot of non-AOT'ed code -
> the 10s of seconds of read/compile/init times dwarf this stuff. Rich and I
> working on an idea to help with this.
>
> On Thursday, January 25, 2018 at 11:47:32 PM UTC-6, Nathan Fisher wrote:
>>
>> It's not a huge contributor but Class loading isn't free and Clojure
>> could optimise it in a couple of places. I think with a couple of months
>> effort in optimisation you might be able to get it down to 500ms for a
>> simple "hello world". I'm doubtful you can get it much lower than that. TBH
>> I'm not sure if the engineering effort would necessarily be worth it for
>> many users.
>>
>> I wanted to test dynamic loading and docker before I shared the article
>> more broadly but here's the results from implementing prefetching in
>> Clojure;
>>
>> https://junctionbox.ca/2018/01/04/clojure-class-prefetching.html
>> 
>>
>> It's a part of a series that I'm slowly plodding through as I have time.
>> I hope to cover off the 4 items from the conclusion of this article;
>>
>>
>> https://junctionbox.ca/2017/12/26/clojure-startup-walkthrough.html#conclusions
>> 
>>
>> Cheerio!
>> Nathan
>>
>>
>> On 26 January 2018 at 01:51, Timothy Baldridge 
>> wrote:
>>
>>> I would suggest everyone here read this document:
>>> https://dev.clojure.org/display/design/Improving+Clojure+Start+Time It
>>> goes into a lot of detail on prior work in this area, and I'd say the
>>> benchmarks on it should be quite informative.
>>>
>>> But let me also go into a bit more detail into how CLJS differs from CLJ
>>> in how it accesses global function definitions:
>>>
>>> In CLJs, clojure core contains a lot of definitions that look something
>>> like this:
>>>
>>> clojure.core.conj = function () {... clojure.core.some_fn(...) . }
>>>
>>> The cost of creating that global function is then the cost of 2 lookups
>>> (clojure in the global namespace, core in clojure), the creating of a JS
>>> function object, and the assigning of that function to the core object. The
>>> internal call to some_fn doesn't matter at load-time because of
>>> Javascript's late binding.
>>>
>>> In the JVM this happens:
>>>
>>> 1) A class is loaded that implements the IFn or AFn interfaces
>>> 2) The methods on this class must be loaded and the bytcode parsed, and
>>> validated
>>> 3) The static constructor on this method is run
>>> 4) Inside the static constructor there are calls to find Vars. In the
>>> case of the above function this would be a lookup to clojure.core.some_fn.
>>> This is done for every var referenced by this function
>>> 5) Any non-native constants must be new'd up. This includes hashmaps,
>>> vectors, lists, keywords (which must be interned), symbols, etc.
>>> 5) The clojure.core.conj var is created
>>> 6) The contents of the var are set to the function that was loaded (and
>>> new'd). Synchronization doesn't matter here as there are no other threads
>>> that can see this Var.
>>> 7) The metadata for the function is created. Most of the time this
>>> includes creating a 

Re: Call custom Clojure function with dependencies from Java

2017-12-24 Thread Justin Smith
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.


Re: Slow -main function termination by pmap

2017-12-19 Thread Justin Smith
any Clojure program that uses the built in thread pools (future, agent,
pmap, core.async, etc.) should call (shutdown-agents) if prompt exit is
needed

On Tue, Dec 19, 2017 at 12:05 PM Jacek Grzebyta 
wrote:

> Hi,
>
> I have multi -mains project. Thus the execution looks like:
>
> java -cp location/file.jar some.method ..
>
>
> One -main method looks like:
>
> (defn -main
>   [& args]
>   (let [validated (validate-args args)]
> (if (:msg validated)
>   (println (st/join \newline (:msg validated)))
>   (run validated))
> (log/debug "finish")))
>
>
> There is nothing special in that except in the run time I have displayed
> the last log "finish" and the program termination is done after ~1 min
> later what is annoying. I found it is caused by deeply hidden pmap even if
> it is wrapped by doall. I thought after pmap returns results all threads
> are finished i.e. the main thread waits until all sub threads will be
> finished. If I am right what else can cause the delay? The threads pool
> manager?
>
> Tanks a lot,
> Jacek
>
> --
> 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: Terminating 'clj' REPL session

2017-12-09 Thread Justin Smith
I find the fact that "exit" and "quit" work in leiningen repls to be weird
- this doesn't follow the otherwise consistent rules of the language. What
about an exit function, something like

(defn exit
  ([] (exit 0))
  ([n] (System/exit n))

so that it's not an out of band special case input?

On Sat, Dec 9, 2017 at 2:38 PM Alan Thompson  wrote:

> Hi - Just downloaded the new Clojure 1.9.0 package.  When I tried the repl
> I noticed that it doesn't respond to either `exit` or `quit` as one might
> expect from the lein repl:
>
> ~/cool/tools > clj
> Clojure 1.9.0
> user=> (+ 2 3)
> 5
> user=> exit
> CompilerException java.lang.RuntimeException: Unable to resolve symbol:
> exit in this context, compiling:(NO_SOURCE_PATH:0:0)
> user=>
> user=> quit
> CompilerException java.lang.RuntimeException: Unable to resolve symbol:
> quit in this context, compiling:(NO_SOURCE_PATH:0:0)
> user=> ^D
> ~/cool/tools >
>
>
> Lein repl for comparison:
>
> ~/tupelo > lein repl
> nREPL server started on port 37115 on host 127.0.0.1 - Clojure 1.9.0
> tupelo.core=> exit
> Bye for now!
>
> ~/tupelo >
>
> ~/tupelo > lein repl
> nREPL server started on port 40639 on host 127.0.0.1 - Clojure 1.9.0
> tupelo.core=> quit
> Bye for now!
> ~/tupelo >
>
>
> The new repl does terminate upon CRTL-D or CRTL-C, but many users will
> probably be confused that `quit` and `exit` are not accepted.
>
> Should I file a JIRA?
>
> Alan
>
> --
> 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 Justin Smith
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.


Re: What's up with IMeta?

2017-11-04 Thread Justin Smith
first class values on the jvm are objects

On Sat, Nov 4, 2017 at 5:57 PM Didier  wrote:

> > That said, metadata and its relationship to an object is immutable - an
>>> object with different metadata is a different object. One consequence of
>>> this is that applying metadata to a lazy sequence will realize the head of
>>> the sequence so that both objects can share the same sequence.
>>>
>>
>> What confuses you about it? Is it the "realize the head of the sequence"
>> part?
>>
>
> I think I'm firstly confused by the use of the word object. I'm guessing
> in this case it refers to things that implement IObj? I'm then confused by
> what is meant that an object with different meta is a different object, if
> they are still equal? I'm guessing it means that if you change the meta on
> an IObj, you get a copy? And then I'm confused as to why that would cause
> lazy-seq to realize their head? Can't two lazy-seq share the same head?
>
> On Saturday, 4 November 2017 11:40:54 UTC-7, James Reeves wrote:
>
>> On 3 November 2017 at 06:57, Didier  wrote:
>>
>>> Okay, I can see how I can maybe infer some of that by piecing together
>>> the code base, but if there was a book, or a reference somewhere describing
>>> more the implementation of Clojure itself I'd be interested to read it, if
>>> there is one out there. I'd understand if there's not, I know Clojure has
>>> no formal semantic spec.
>>>
>>
>> I don't know of one, I'm afraid.
>>
>>
>>> Also, I guess I'm still confused about that bit:
>>>
>>> > That said, metadata and its relationship to an object is immutable -
>>> an object with different metadata is a different object. One consequence of
>>> this is that applying metadata to a lazy sequence will realize the head of
>>> the sequence so that both objects can share the same sequence.
>>>
>>
>> What confuses you about it? Is it the "realize the head of the sequence"
>> part?
>>
>> --
>> James Reeves
>> booleanknot.com
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to 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: An Annotation within an Annotation

2017-11-01 Thread Justin Smith
when you use ^{}, that applies metadata to the next form. In the
highlighted code, you are trying to put metadata on the keyword :component
- perhaps the ^TestType metadata should go on the hash-map on that line
instead of turning the whole hash-map into metadata ?

On Wed, Nov 1, 2017 at 7:37 AM Jan Stavel  wrote:

> Hello,
> I have forgetten an error that 'lein compile' gives.
>
>
>   java.lang.IllegalArgumentException: Metadata can only be applied to
> IMetas, compiling:(rhsm/cockpit/tests/register_tests.clj:88:35)
>   Exception in thread "main" java.lang.IllegalArgumentException: Metadata
> can only be applied to IMetas,
> compiling:(rhsm/cockpit/tests/register_tests.clj:88:35)
>
>
> Have a good day,
> Jan Stavel
>
> --
> 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: Got NullpointerException when using loop/recur/let together

2017-10-24 Thread Justin Smith
you wrap a call to Thread/sleep in parens, in clojure this means you want
to call it, Thread/sleep returns nil and calling nil gives a
NullpointerException

Parens are not for grouping or sequencing things in clojure, and you don't
need them here - fn has an implicit do block already, in other contexts
where there isn't a do block implicitly, you can use do to sequence
expressions

On Tue, Oct 24, 2017 at 5:26 PM yihao yang  wrote:

> Hi, all
>
>   I want to do sth. like query until timeout. So I write a function below.
> (defn wait-ls-ready
>   []
>   (let [pair-fn (fn [] (
>  (Thread/sleep 1000)
>  (let [ret (try
>  (c/exec :ls)
>  0
>  (catch RuntimeException e -1)
>),
>time-now (quot (System/currentTimeMillis)
> 1000)]
>'(ret (- time-now start-time))
>  )
>))]
> (loop [start-time (quot (System/currentTimeMillis) 1000)
>time-out 10]
>   (let [[ret time-delta] (pair-fn)]
> (info node "Waiting gsql works...")
> (if (= 0 ret) 0
>   (if (> time-delta time-out)
> (throw (RuntimeException.
>  (str "'ls' not working in " time-out "seconds.")))
> (recur start-time time-out
> )
>   )
> )
>
> But it returns a NullpointerException after 1 seconds. Could anyone help
> me out?
>
> Thanks,
> Yihao
>
> --
> 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: hello world question !!!

2017-10-16 Thread Justin Smith
the uberjar option bundles clojure.jar (as well as any other dependencies
you specify in your project.clj) into the output jar for you

On Mon, Oct 16, 2017 at 6:36 AM Damien Mattei 
wrote:

> following this tutorial :
> https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md#tutorial
> i succeed with leiningen to build a project,run it and after make a jar
> file :
>
> lein new app my-stuff
> cd my-stuff
> lein uberjar
> lein run
> or : cd target; java -jar my-stuff-0.1.0-SNAPSHOT-standalone.jar
>
> with some simplified from tutorial files:
>
> project.clj
>
> (defproject my-stuff "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 my-stuff.core
>   :aot [my-stuff.core])
>
> core.clj
>
> (ns my-stuff.core
>   (:gen-class))
>
> (defn -main [& args]
>   (println "Welcome to my project! These are your args:" args))
>
> the jar file in target/ could be loaded in the netbeans project Netbeans
> as a library/jar file and i can see the classes and definition in the
> netbeans IDE,
> so it seems ok, note that at this point i can test it (on the tomcat
> server) but it should work (if i add also the clojure.jar runtime library i
> suppose)
> also i do not need to make a full .war file from scratch, so it is more
> easy.
>
> thank for your help
>
>
> Damien
>
>
> On Monday, October 16, 2017 at 8:10:24 AM UTC+2, Terje Sten Bjerkseth
> wrote:
>>
>> Damien: A good starting point for a simple web server might be to use
>>
>> lein new pedestal-service
>>
>> Then you can do lein uberjar to get a jar ready to run. Or check the
>> README for running local dev with a local REPL.
>>
>> If instead you want a WAR, you can switch from pedestal.jetty to
>> pedestal.immutant in project.clj and add the Immutant plugin:
>>
>> :plugins [[lein-immutant "2.1.0"]]
>>
>> Then do a lein immutant war to get your WAR for deployment to e.g.
>> WildFly 10.
>>
>> If you also want a nREPL to repl directly into the running server, have
>> in project.clj e.g.:
>>
>> :plugins [[lein-immutant "2.1.0"] [cider/cider-nrepl "0.15.1"]]
>> :immutant {:war {:nrepl {:port }}}
>>
>> and do a lein immutant war --nrepl-start when making your WAR (check your
>> security on the nREPL port).
>>
>> Cheers,
>> Terje
>>
>> (Haven't looked at WildFly 11 RC yet and don't know if Immutant works
>> with it. Considering moving some of our services from WildFly to separate
>> Jetty services instead, but WildFly 10 has worked very well.)
>>
>>
>>
>> søndag 15. oktober 2017 10.43.36 UTC+2 skrev Damien Mattei følgende:
>>>
>>> thanks for the answers and comments of John, James and others,
>>> the discussion has opened many aspect of web application development and
>>> it is is positive.
>>>
>>> about the IDE, i'm not using Netbeans with Scheme or LisP exclusively,
>>> in fact Netbeans was used in the office just to create web service in Java,
>>> this thing can be done by hand in command line too, Kawa Scheme also can
>>> do it itself :
>>>  https://www.gnu.org/software/kawa/Servlets.html
>>>
>>> from the discussion i see now many solution to test ,I will install
>>> Leiningen, also i see in the doc of Immutant that it is possible to
>>> generate some war files :
>>> http://immutant.org/documentation/current/apidoc/guide-wildfly.html#h3386
>>>
>>> i hope i could use Clojure for that because it seems a really fun and
>>> solid LisP dialect.
>>> I will post updates when i have a concrete usable solution.
>>>
>>> Regards,
>>>
>>> Damien
>>>
>>> On Saturday, October 14, 2017 at 5:07:08 PM UTC+2, John M. Switlik wrote:

 James,

 Thanks. I saw a writeup mentioning Leiningen that I will go back to.

 It is not the 'toy' issue that concerns me. It is that all sorts of
 browsers exist as well as a whole slew of different types of users. And, if
 I am going to push something down to a remote device, I want to expect that
 it would be handled in a nice manner.

 As for example projects, these are prime; but, they are supported by
 working professionals. So, Clojure does have a lot to offer.

http://base2s.com/work/

 I am sure that I'll look back and see that it was easy. But, this seems
 like an opportunity to step through the thing (that is, the hugely
 complicated world of the muddy cloud) and see how things evolved. Those
 little interpreters are up there as a lure in the meantime.

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

Re: form comment and meta data?

2017-10-13 Thread Justin Smith
what happens is that the metadata reader macro is applied before the
comment reader macro, so you comment out the name of the def (which also
had the metadata attached)

user=> '(def #_ ^:private foo 1)
(def 1)

On Fri, Oct 13, 2017 at 11:48 AM Rob Nikander 
wrote:

> Hi,
>
> Why doesn't this compile? I tried to comment out the "private" metadata.
>
>   (def #_^:private foo 1)
>   CompilerException java.lang.RuntimeException: First argument to def must
> be a Symbol, compiling:(null:1:1)
>
>
> Rob
>
>
> --
> 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: hello world question !!!

2017-10-13 Thread Justin Smith
also you don't need to do any of this for a basic example, you can just
type code into the repl and run it, or create a proper project with a
dependency manager when you want something more organized

On Fri, Oct 13, 2017 at 10:22 AM Justin Smith <noisesm...@gmail.com> wrote:

> paths have to reflect the package and be relative to the class path, so if
> "clojure/examples" is on the classpath, and the namespace is
> clojure.examples.hello, the file needs to be in
> "clojure/examples/clojure/examples/hello.clj"
>
> On Fri, Oct 13, 2017 at 10:13 AM Damien Mattei <damien.mat...@gmail.com>
> wrote:
>
>> i did not have , i just follow the tutorial:
>> https://clojure.org/reference/compilation
>> i made the file but still the same problem:
>>
>> [mattei@moita ~]$ export CLASSPATH=.:./clojure/examples
>> [mattei@moita ~]$ clojure
>> Clojure 1.5.1
>> user=> (compile 'clojure.examples.hello)
>>
>> FileNotFoundException Could not locate clojure/examples/hello__init.class
>> or clojure/examples/hello.clj on classpath:   clojure.lang.RT.load
>> (RT.java:443)
>> user=> ^C[mattei@moita ~]$
>>
>> [mattei@moita ~]$ cat clojure/examples/hello.clj
>> (ns clojure.examples.hello
>> (:gen-class))
>>
>>
>> (defn -main
>>   [greetee]
>>   (println (str "Hello " greetee "!")))
>>
>> On Friday, October 13, 2017 at 4:48:40 PM UTC+2, James Reeves wrote:
>>
>>> Maybe this is a dumb question, but do you have a file
>>> "clojure/examples/hello.clj" on the classpath? Since that's what the
>>> exception is complaining about.
>>>
>> On 13 October 2017 at 15:09, Damien Mattei <damien...@gmail.com> wrote:
>>>
>> hello,
>>>>
>>>> i'm new to clojure, just installed it on a CentOS box,
>>>>
>>>> and try to compile the code below from tutorial, but it does not work,
>>>> i searched a lot before posting, no answer... i do not want to use
>>>> leiningen at this stage,later perheaps...
>>>>
>>>> just want to compile and run
>>>>
>>>> user=> (ns clojure.examples.hello
>>>> (:gen-class))
>>>> nil
>>>> clojure.examples.hello=>
>>>> clojure.examples.hello=> (defn -main
>>>>   [greetee]
>>>>   (println (str "Hello " greetee "!")))
>>>> #'clojure.examples.hello/-main
>>>> clojure.examples.hello=> (compile 'clojure.examples.hello)
>>>> FileNotFoundException Could not locate
>>>> clojure/examples/hello__init.class or clojure/examples/hello.clj on
>>>> classpath:   clojure.lang.RT.load (RT.java:443)
>>>>
>>>> help greatly appreciated (because i'm just one step to leave Clojure
>>>> and continue using  Kawa or Bigloo i already use or dive into ABCL , but
>>>> Clojure has a so good reputation, i cannot imagine being sticked here by a
>>>> simple hello world!)
>>>>
>>>> damien
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>>
>>> To post to this group, send email to clo...@googlegroups.com
>>>
>>>
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>>
>>> clojure+u...@googlegroups.com
>>>
>>>
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>>
>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to clojure+u...@googlegroups.com.
>>>
>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> James Reeves
>>> booleanknot.com
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to 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: hello world question !!!

2017-10-13 Thread Justin Smith
paths have to reflect the package and be relative to the class path, so if
"clojure/examples" is on the classpath, and the namespace is
clojure.examples.hello, the file needs to be in
"clojure/examples/clojure/examples/hello.clj"

On Fri, Oct 13, 2017 at 10:13 AM Damien Mattei 
wrote:

> i did not have , i just follow the tutorial:
> https://clojure.org/reference/compilation
> i made the file but still the same problem:
>
> [mattei@moita ~]$ export CLASSPATH=.:./clojure/examples
> [mattei@moita ~]$ clojure
> Clojure 1.5.1
> user=> (compile 'clojure.examples.hello)
>
> FileNotFoundException Could not locate clojure/examples/hello__init.class
> or clojure/examples/hello.clj on classpath:   clojure.lang.RT.load
> (RT.java:443)
> user=> ^C[mattei@moita ~]$
>
> [mattei@moita ~]$ cat clojure/examples/hello.clj
> (ns clojure.examples.hello
> (:gen-class))
>
>
> (defn -main
>   [greetee]
>   (println (str "Hello " greetee "!")))
>
> On Friday, October 13, 2017 at 4:48:40 PM UTC+2, James Reeves wrote:
>
>> Maybe this is a dumb question, but do you have a file
>> "clojure/examples/hello.clj" on the classpath? Since that's what the
>> exception is complaining about.
>>
> On 13 October 2017 at 15:09, Damien Mattei  wrote:
>>
> hello,
>>>
>>> i'm new to clojure, just installed it on a CentOS box,
>>>
>>> and try to compile the code below from tutorial, but it does not work, i
>>> searched a lot before posting, no answer... i do not want to use leiningen
>>> at this stage,later perheaps...
>>>
>>> just want to compile and run
>>>
>>> user=> (ns clojure.examples.hello
>>> (:gen-class))
>>> nil
>>> clojure.examples.hello=>
>>> clojure.examples.hello=> (defn -main
>>>   [greetee]
>>>   (println (str "Hello " greetee "!")))
>>> #'clojure.examples.hello/-main
>>> clojure.examples.hello=> (compile 'clojure.examples.hello)
>>> FileNotFoundException Could not locate
>>> clojure/examples/hello__init.class or clojure/examples/hello.clj on
>>> classpath:   clojure.lang.RT.load (RT.java:443)
>>>
>>> help greatly appreciated (because i'm just one step to leave Clojure and
>>> continue using  Kawa or Bigloo i already use or dive into ABCL , but
>>> Clojure has a so good reputation, i cannot imagine being sticked here by a
>>> simple hello world!)
>>>
>>> damien
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>>
>> To post to this group, send email to clo...@googlegroups.com
>>
>>
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>>
>> clojure+u...@googlegroups.com
>>
>>
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to clojure+u...@googlegroups.com.
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> James Reeves
>> booleanknot.com
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to 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: hello world question !!!

2017-10-13 Thread Justin Smith
Sorry for the auto correct fail, it compiles all of your code to byte-code

On Fri, Oct 13, 2017, 08:29 Justin Smith <noisesm...@gmail.com> wrote:

> To pedantically specific, clojure compiles all of your coffee to be code
> in memory, but the 'compile' function expects to find a file on disk, and
> create a class file on disk. Using gen-class in the repl is a no-op.
>
> On Fri, Oct 13, 2017, 07:48 James Reeves <ja...@booleanknot.com> wrote:
>
>> Maybe this is a dumb question, but do you have a file
>> "clojure/examples/hello.clj" on the classpath? Since that's what the
>> exception is complaining about.
>>
>> On 13 October 2017 at 15:09, Damien Mattei <damien.mat...@gmail.com>
>> wrote:
>>
>>> hello,
>>>
>>> i'm new to clojure, just installed it on a CentOS box,
>>>
>>> and try to compile the code below from tutorial, but it does not work, i
>>> searched a lot before posting, no answer... i do not want to use leiningen
>>> at this stage,later perheaps...
>>>
>>> just want to compile and run
>>>
>>> user=> (ns clojure.examples.hello
>>> (:gen-class))
>>> nil
>>> clojure.examples.hello=>
>>> clojure.examples.hello=> (defn -main
>>>   [greetee]
>>>   (println (str "Hello " greetee "!")))
>>> #'clojure.examples.hello/-main
>>> clojure.examples.hello=> (compile 'clojure.examples.hello)
>>> FileNotFoundException Could not locate
>>> clojure/examples/hello__init.class or clojure/examples/hello.clj on
>>> classpath:   clojure.lang.RT.load (RT.java:443)
>>>
>>> help greatly appreciated (because i'm just one step to leave Clojure and
>>> continue using  Kawa or Bigloo i already use or dive into ABCL , but
>>> Clojure has a so good reputation, i cannot imagine being sticked here by a
>>> simple hello world!)
>>>
>>> damien
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> James Reeves
>> booleanknot.com
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to 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: hello world question !!!

2017-10-13 Thread Justin Smith
To pedantically specific, clojure compiles all of your coffee to be code in
memory, but the 'compile' function expects to find a file on disk, and
create a class file on disk. Using gen-class in the repl is a no-op.

On Fri, Oct 13, 2017, 07:48 James Reeves  wrote:

> Maybe this is a dumb question, but do you have a file
> "clojure/examples/hello.clj" on the classpath? Since that's what the
> exception is complaining about.
>
> On 13 October 2017 at 15:09, Damien Mattei 
> wrote:
>
>> hello,
>>
>> i'm new to clojure, just installed it on a CentOS box,
>>
>> and try to compile the code below from tutorial, but it does not work, i
>> searched a lot before posting, no answer... i do not want to use leiningen
>> at this stage,later perheaps...
>>
>> just want to compile and run
>>
>> user=> (ns clojure.examples.hello
>> (:gen-class))
>> nil
>> clojure.examples.hello=>
>> clojure.examples.hello=> (defn -main
>>   [greetee]
>>   (println (str "Hello " greetee "!")))
>> #'clojure.examples.hello/-main
>> clojure.examples.hello=> (compile 'clojure.examples.hello)
>> FileNotFoundException Could not locate clojure/examples/hello__init.class
>> or clojure/examples/hello.clj on classpath:   clojure.lang.RT.load
>> (RT.java:443)
>>
>> help greatly appreciated (because i'm just one step to leave Clojure and
>> continue using  Kawa or Bigloo i already use or dive into ABCL , but
>> Clojure has a so good reputation, i cannot imagine being sticked here by a
>> simple hello world!)
>>
>> damien
>>
>> --
>> 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.
>>
>
>
>
> --
> James Reeves
> booleanknot.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to 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-12 Thread Justin Smith
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 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: possibly a Clojure question or possibly an AWS question: slow writes to durable-queue

2017-10-11 Thread Justin Smith
a small thing here, if memory usage is important you should be building and
running an uberjar instead of using lein on the server (this also has other
benefits), and if you are doing that your project.clj jvm-opts are not
used, you have to configure your java command line in aws instead

On Wed, Oct 11, 2017 at 3:52 PM  wrote:

> I can't figure out if this is a Clojure question or an AWS question. And
> if it is a Clojure question, I can't figure out if it is more of a general
> JVM question, or if it is specific to some library such as durable-queue. I
> can redirect my question elsewhere, if people think this is an AWS
> question.
>
> In my project.clj, I try to give my app a lot of memory:
>
>   :jvm-opts ["-Xms7g" "-Xmx7g" "-XX:-UseCompressedOops"])
>
> And the app starts off pulling data from MySQL and writing it to
> Durable-Queue at a rapid rate. ( https://github.com/Factual/durable-queue
> )
>
> I have some logging set up to report every 30 seconds.
>
> :enqueued 370137,
>
> 30 seconds later:
>
> :enqueued 608967,
>
> 30 seconds later:
>
> :enqueued 828950,
>
> It's a dramatic slowdown. The app is initially writing to the queue at
> faster than 10,000 documents a second, but it slows steadily, and after 10
> minutes it writes less than 1,000 documents per second. Since I have to
> write a few million documents, 10,000 a second is the slowest speed I can
> live with.
>
> The queues are in the /tmp folder of an AWS instance that has plenty of
> disk space, 4 CPUs, and 16 gigs of RAM.
>
> Why does the app slow down so much? I had 4 thoughts:
>
> 1.) the app struggles as it hits a memory limit
>
> 2.) memory bandwidth is the problem
>
> 3.) AWS is enforcing some weird IOPS limit
>
> 4.) durable-queue is misbehaving
>
> As to possibility #1, I notice the app starts like this:
>
> Memory in use (percentage/used/max-heap): (\"66%\" \"2373M\" \"3568M\")
>
> but 60 seconds later I see:
>
> Memory in use (percentage/used/max-heap): (\"94%\" \"3613M\" \"3819M\")
>
> So I've run out of allowed memory. But why is that? I thought I gave this
> app 7 gigs:
>
>   :jvm-opts ["-Xms7g" "-Xmx7g" "-XX:-UseCompressedOops"])
>
> As to possibility #2, I found this old post on the Clojure mailist:
>
> Andy Fingerhut wrote, "one thing I've found in the past on a 2-core
> machine that was achieving much less than 2x speedup was memory bandwidth
> being the limiting factor."
>
>
> https://groups.google.com/forum/#!searchin/clojure/xmx$20xms$20maximum%7Csort:relevance/clojure/48W2eff3caU/HS6u547gtrAJ
>
> But I am not sure how to test this.
>
> As to possibility #3, I'm not sure how AWS enforces its IOPS limits. If
> people think this is the most likely possibility, then I will repost my
> question in an AWS forum.
>
> As to possibility #4, durable-queue is well-tested and used in a lot of
> projects, and Zach Tellman is smart and makes few mistakes, so I'm doubtful
> that it is to blame, but I do notice that it starts off with 4 active slabs
> and then after 120 seconds, it is only using 1 slab. Is that expected? If
> people think this is the possible problem then I'll ask somewhere specific
> to durable-queue
>
> Overall, my log information looks like this:
>
> ("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs
> 3, :num-active-slabs 2, :enqueued 370137, :retried 0, :completed 369934,
> :in-progress 10}})
>
> ("\nResource usage: " "Memory in use (percentage/used/max-heap):
> (\"66%\" \"2373M\" \"3568M\")\n\nCPU usage (how-many-cpu's/load-average):
>  [4 5.05]\n\nFree memory in jvm: [1171310752]")
>
> 30 seconds later
>
> ("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs
> 4, :num-active-slabs 4, :enqueued 608967, :retried 0, :completed 608511,
> :in-progress 10}})
>
> ("\nResource usage: " "Memory in use (percentage/used/max-heap):
> (\"76%\" \"2752M\" \"3611M\")\n\nCPU usage (how-many-cpu's/load-average):
>  [4 5.87]\n\nFree memory in jvm: [901122456]")
>
> 30 seconds later
>
> ("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs
> 4, :num-active-slabs 3, :enqueued 828950, :retried 0, :completed 828470,
> :in-progress 10}})
>
> ("\nResource usage: " "Memory in use (percentage/used/max-heap):
> (\"94%\" \"3613M\" \"3819M\")\n\nCPU usage (how-many-cpu's/load-average):
>  [4 6.5]\n\nFree memory in jvm: [216459664]")
>
> 30 seconds later
>
> ("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs
> 1, :num-active-slabs 1, :enqueued 1051974, :retried 0, :completed 1051974,
> :in-progress 0}})
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> 

Re: functions with metadata, 2 problems: performance hit and equality not preserved.

2017-09-20 Thread Justin Smith
I've had good luck with an approach suggested by Kevin Downey, defining a
defrecord that implements IFn so that it works when called and applied, and
transparently supporting attached data as if it were a hash-map. It's not
too hard to implement if you know the precise arg count you need to
support, and I'd be interested to see how the performance compares.

On Wed, Sep 20, 2017 at 11:57 AM John McDonald 
wrote:

> 2nd issue: Benchmarks
>
> I use both criterium and simple 'run repeatedly and divide the clock time'.
>
> I've had trouble getting consistent results from run to run with either.
>
> Most recently (yesterday) I've added many more warmup runs, giving HotSpot
> lots of time to do its stuff, which seems to be stabilizing the results.
> This might be unfair, because in practice a lot of important code might
> never run that many times.
> At least, it gives the limiting performance of code that runs a lot.
>
> Unfortunately, this benchmark is split over 3 github projects, so it might
> be a little hard to follow.
>
> The task I'm timing is computing the sum of squares of the elements in a
> moderately large (4m elements) double[] array (aka L2Norm).
>
> I've compared 8 implementations, all of which accumulate the sum in Java.
>
>   6.37ms inline --- naive sum of squares in Java.
>   6.37ms invokestatic --- call a static method in Java to square the
> elements.
>   6.38ms primitive --- calls square.invokePrim(x[i]) to square the elements
>   6.37ms boxprimitive --- calls square.invoke(x[i]) to square the elements
>   6.37ms funxprimitive --- calls funxSquare.invokePrim(), where funxSquare
> is square wrapped with MetaFn, an experiment metadata wrapper.
>   6.38ms funxboxed --- calls funxSquare.invoke()
>  43.55ms boxed --- calls boxedSquare.invoke() , where boxedSquare is a
> version of square without type hints.
> 151.61ms cljmeta --- calls metaSquare.invoke(), where metasquare is the
> result of (with-meta square {...})
>
> Clojure 1.8.0, Oracle JDK 1.8, Win10, Lenovo X1 i5-7300U.
> Sum of squares for each of 2 double[4194304], in 2 threads, concurrently.
>
> boxed and cljmeta create a lot of garbage, causing their clock times to be
> more variable, depending on exactly what GC does..
> It's possible they appear relatively faster with a small number of total
> calls, if they don't trigger a GC, and HotSpot doesn't fully optimize the
> others.
> I think this is a valid usage pattern, but many many calls to small
> functions is the case that I'm interested in at present.
>
>
> Main scripts:
>
> Using criterium:
>
> https://github.com/palisades-lakes/function-experiments/blob/dynesty/src/scripts/clojure/palisades/lakes/funx/l2norm/bench.clj
>
> Running the benchmark 4k times and dividing the clock time:
>
> https://github.com/palisades-lakes/function-experiments/blob/dynesty/src/scripts/clojure/palisades/lakes/funx/l2norm/msec.clj
>
> These both use general benchmarking code from
> https://github.com/palisades-lakes/benchtools
>
> The experimental metadata function wrapper is in:
>
> https://github.com/palisades-lakes/dynamic-functions/blob/dynesty/src/main/java/palisades/lakes/dynafun/java/MetaFn.java
>
>
> On Wed, Sep 20, 2017 at 11:17 AM, John McDonald  > wrote:
>
>> Thanks for the quick response.
>>
>> One issue at a time:
>>
>> (A) Putting metadata on Vars instead of on the functions themselves:
>>
>> I need to be able to associate facts with the function instances. I can't
>> rely on every function being bound to a Var.
>> For example, I'm constructing cost functions for machine learning, and
>> other applications, by summing, composing, etc. other functions.
>>
>>
>>
>> On Tue, Sep 19, 2017 at 11:34 PM, Alex Miller 
>> wrote:
>>
>>>
>>>
>>> On Tuesday, September 19, 2017 at 8:01:07 PM UTC-5, John Alan McDonald
>>> wrote:

 I'd like to be able to do something like:

 (defn square ^double [^double x] (* x x))
 (def meta-square (with-meta square {:domain Double/TYPE :codomain
 Double/TYPE :range {:from 0.0 :to Double/POSITIVE_INFINITY :also Double
 /NaN}})

 https://clojure.org/reference/metadata
 
 says "Symbols and collections support metadata...". Nothing about
 whether any other types do or do not support metadata.

>>>
>>> Functions are probably the big missing thing in that list of types that
>>> have metadata that you can modify.
>>>
>>> A few other things also have metadata that can be set at construction
>>> and read but not modified after construction: namespaces and the reference
>>> types (vars, atoms, refs, agents).
>>>
>>>
 The code above works, at least in the sense that it doesn't throw
 exceptions, and meta-square is a function that returns the right values,
 and has the right metadata.
 That's because square is an instance 

Re: varying realization of a lazy-seq of strings?

2017-09-17 Thread Justin Smith
my simplified reproduction of the issue:

+user=> (let [mk-str (fn [] (lazy-seq [(str ["ZiZi"])]))
  a (mk-str)
  b (mk-str)]
  (print-str a)
  (pr-str b)
  [a b])
[("[ZiZi]") ("[\"ZiZi\"]")]

isn't *print-readably* the difference between pr-str and print-str?

On Sun, Sep 17, 2017 at 5:59 PM Didier  wrote:

> Lazy sequences cache their values after the first time they are evaluated.
> Since print alters the output of str by binding *print-readably* to false,
> and also forces the sequence to realize itself, the values in your sequence
> are now cached the the result of str without *print-readably*. In
> subsequent calls to the sequence, you get the cache results, so even if you
> change the setting of *print-readably* it doesn't do anything.
>
> Either make sure that when you first access elements of the sequence, the
> bindings are the way you want str to be configured, or have the bindings
> set inside the lazy-seq.
>
> --
> 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 is the start function called -main

2017-09-06 Thread Justin Smith
To define a method in gen-class you need to use a prefix on the function
name, "-" is the default prefix

On Wed, Sep 6, 2017, 14:41 Cecil Westerhof  wrote:

> 2017-09-06 23:27 GMT+02:00 Matching Socks :
>
>> There is a hint, as to this, in the API doc of gen-class:
>>
>>
>> https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/gen-class
>>
>
> ​That explains what happens, not why. ;-)
>
> --
> Cecil Westerhof
>
> --
> 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: SRSLY? (= (true? identity) (false? identity)) => true

2017-09-01 Thread Justin Smith
identity isn't a boolean, so neither true? nor false? should return true
for it


On Fri, Sep 1, 2017 at 9:01 PM Rostislav Svoboda <
rostislav.svob...@gmail.com> wrote:

> > (true? identity) -> false
> > (false? identity) -> false
> > (= false false) -> true
>
> Well:
> (= identity identity) -> true
>
> My math books say booleans can't be true and false in the same 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: SRSLY? (= (true? identity) (false? identity)) => true

2017-09-01 Thread Justin Smith
You seem to be confused about what true? and false? are intended to do.

+user=> (doc true?)
-
clojure.core/true?
([x])
  Returns true if x is the value true, false otherwise.
nil
+user=> (doc false?)
-
clojure.core/false?
([x])
  Returns true if x is the value false, false otherwise.
nil


On Fri, Sep 1, 2017 at 8:57 PM Rostislav Svoboda <
rostislav.svob...@gmail.com> wrote:

> > This is what I would expect - the identity function is neither the value
> true, or the value false
>
> Hmm. No matter what's the value of the identity, the functions
> 'true?', 'false?', 'not' should then return an exception (or something
> else) instead of a boolean.
>
> 2017-09-02 5:49 GMT+02:00 Mark Engelberg :
> > (true? identity) -> false
> > (false? identity) -> false
> > (= false false) -> true
> >
> > On Fri, Sep 1, 2017 at 8:43 PM, Rostislav Svoboda
> >  wrote:
> >>
> >> Hi, can anybody explain it please?
> >>
> >> $ java -cp clojure-1.8.0.jar clojure.main
> >> Clojure 1.8.0
> >> user=> (= (true? identity) (false? identity))
> >> true
> >>
> >> And in 1.9.0-alpha19 it behaves the same.
> >>
> >> thx Bost
> >>
> >> --
> >> 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.
>

-- 
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: SRSLY? (= (true? identity) (false? identity)) => true

2017-09-01 Thread Justin Smith
This is what I would expect - the identity function is neither the value
true, or the value false

On Fri, Sep 1, 2017 at 8:44 PM Rostislav Svoboda <
rostislav.svob...@gmail.com> wrote:

> Hi, can anybody explain it please?
>
> $ java -cp clojure-1.8.0.jar clojure.main
> Clojure 1.8.0
> user=> (= (true? identity) (false? identity))
> true
>
> And in 1.9.0-alpha19 it behaves the same.
>
> thx Bost
>
> --
> 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 be notified when a Future is realized?

2017-08-02 Thread Justin Smith
for this sort of logic, I use core.async go blocks containing a call to
core.async/thread, doing some other operation asynchronously with the value
in the channel it returns

(go
  (let [result (https://gist.github.com/noisesmith/02ee2ee5dcb8c0290bd8004c4c4d36aa

On Wed, Aug 2, 2017 at 2:09 PM  wrote:

> I stumbled across this old post by Tomasz Nurkiewicz:
>
> http://www.nurkiewicz.com/2013/03/promises-and-futures-in-clojure.html
>
> He writes:
>
> "And here is where the greatest disappointment arrives: neither future
>  nor promise
>  in Clojure
> supports listening for completion/failure asynchronously. The API is pretty
> much equivalent to very limited java.util.concurrent.Future
> .
> We can create future, cancel it
> , check
> whether it is realized? (resolved)
>  and block
> waiting for a value. Just like Future in Java, as a matter of fact the
> result of future function even implements java.util.concurrent.Future.
> As much as I love Clojure concurrency primitives like STM and agents,
> futures feel a bit underdeveloped. Lack of event-driven, asynchronous
> callbacks that are invoked whenever futures completes (notice that
> add-watch  doesn't
> work futures - and is still in alpha) greatly reduces the usefulness of a
> future object. "
>
> That was written in 2013. I think since then the community has found other
> ways to achieve the same goals? I'm curious what patterns have become
> common? Would it be correct to say that for most of the use cases where one
> would otherwise want a notification of completion on a Future, people
> nowadays instead use something like core.async or a library such as
> Manifold?
>
>
>
>
>
>
>
>
> --
> 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: printing self referential data?

2017-07-24 Thread Justin Smith
One important thing to be aware of that I should have mentioned when
suggesting the adjacency list solution is the rationale for using that
representation. When you put atoms in the nodes of your data structure,
it's no longer an immutable data structure and you lose the usage patterns
that clojure provides for other idiomatic data. For example if you call
update or assoc you get a new data structure back that shares the same
mutable atoms under the unmodified keys, which means that any modifications
are reflected in all the other contexts the data is used. Of course you
could (and probably should) also use defensive copying, but then you need
some method of handling the cycles when copying ... in the big picture it's
much simpler to use the adjacency list format which preserves the usage
style we are used to with other clojure data.

On Mon, Jul 24, 2017 at 7:12 AM Rob Nikander  wrote:

> I think in my case here the easiest thing will be to remove the cycles,
> but still I'd like to understand a couple things...
>
>
> On Sunday, July 23, 2017 at 10:12:46 PM UTC-4, Didier wrote:
>>
>> I'm not sure I can fully help without you explaining more what you're
>> doing. It sounds like you've got a collection or container type which has
>> an implementation of print that loops over its elements, and calls print on
>> them. So if you have a cycle, the print will go on forever until memory
>> runs out.
>>
>
> My container type (the tree node) is simply the standard clojure map.
>
> If you're using a standard type, you might be able to limit *print-level*
>> . Most Clojure
>> collections will limit how deep they print based on the value of this
>> global dynamic Var.
>>
>
> Okay, *print-level* works but it looks like I have to call print myself. I
> can't rely on the REPL to print it.
>
> (binding [*print-level* 2] (println (find-route "/reports")))   ; okay
>
> Why does `alter-var-root` here seem to succeed, but have no effect?
>
> (alter-var-root #'*print-level* (constantly 2))
> => 2
> *print-level*
> => nil
> (find-route "/reports")
> stack overflow
>
>
>
> --
> 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: printing self referential data?

2017-07-23 Thread Justin Smith
You can prevent the need for mutable nodes by using an adjacency list to
represent a graph structure. In clojure this works nicely as a hash-map
from a node id to a set of connected node ids (eg for your case, a set of
parent nodes and a set of child nodes), and traversal becomes a series of
lookups.

On Sun, Jul 23, 2017 at 5:45 PM Rob Nikander  wrote:

> I'm translating some code from an object oriented language to Clojure. I'm
> a little confused about a tree structure I had where tree nodes have parent
> and children properties, so the structure forms cycles. I used atoms for
> those properties, so I could wire it all up. The code is clean and simple
> and I'm happy with it, except ... the things don't print in the REPL.
> (stack overflow)
>
> Are there any tricks to printing cyclical data structures in the REPL?
>
> Rob
>
> --
> 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.java.jdbc 0.7.0 Beta 2

2017-07-22 Thread Justin Smith
refer-clojure doesn't ever remove mappings, it only adds them

The reason a refer-clojure clause in your ns form can prevent bindings is
because your refer-clojure clause (which is likely more qualified than the
default) overrides the args that ns would otherwise provide to
refer-clojure.



On Sat, Jul 22, 2017 at 3:08 AM Phillip Lord 
wrote:

>
> I am confused about how to exclude clojure.core from a namespace already
> exists. That is, I have not just created the namespace, but it's been
> given to me by a tool.
>
> Consider, for example:
>
>
>
>
> lein repl
> nREPL server started on port 41054 on host 127.0.0.1 - nrepl://
> 127.0.0.1:41054
> REPL-y 0.3.7, nREPL 0.2.12
> Clojure 1.8.0
> OpenJDK 64-Bit Server VM 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11
>
> user=> (refer-clojure :only [])
> nil
> user=> (defn some[])
> WARNING: some already refers to: #'clojure.core/some in namespace: user,
> being replaced by: #'user/some
> #'user/some
> user=>
>
>
> Now, why do I get this warning? Surely some is not being replaced at
> all, since the refer-clojure form should have removed some
> clojure.core/some from the current namespace.
>
> Phil
>
> --
> 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 juxt really doing?

2017-07-15 Thread Justin Smith
juxt uses each of the functions supplied on all of your arguments. The
hash-map for :what is because (:what {} :default) returns :default - it's
invoking get, which takes an optional "not found" argument.

On Sat, Jul 15, 2017 at 8:52 PM  wrote:

> If I do this:
>
> ((juxt :who :what :when) {:who 1 :when 2} {:who 4 :what 99})
>
> I get:
>
> [1 {:who 4, :what 99} 2]
>
> Why does a map come back instead of a number?
>
> Does anyone use juxt in the real world, or is mostly for examples?
>
>
> --
> 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: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-11 Thread Justin Smith
Oh - this appears to be a separate issue that isn't just about leaving the
context of the db transaction, I don't know enough about those parts of
manifold to address the issue, sorry.

On Tue, Jul 11, 2017 at 1:18 PM <lawrence.krub...@gmail.com> wrote:

> Justin, thanks. I'd like to ask a follow up question. To be clear, if I go
> into (doseq) then this works fine:
>
> (defn start []
>   (let [
> config (get-config)
> mysql-db {
>   :dbtype "mysql"
>   :dbname (get-in  config [:database :config :connection
> :database])
>   :user (get-in  config [:database :config :connection
> :user] )
>   :password (get-in  config [:database :config :connection
> :password] )
>   :host (get-in  config [:database :config :connection
> :host])
>   }
> data (fetch mysql-db)
> ]
> (slingshot/try+
>  (doseq [row data]
>(queue/enqueue row))
>  (catch Object o
>(errors/error o ""  "error in query_database/start: ")
>
>
> but if I do this instead:
>
> ;;;  (doseq [row data]
>(queue/enqueue data))
>
> and then enqueue does this:
>
>(->> (ms/->source data)
> (ms/onto executor)
> (ms/map api/query))
>
>
> The first row comes through fine, but then the second row is never
> processed.
>
> So are you suggesting that simply passing "data" from one function to the
> next is enough to lose the database context? But only after the first row
> has been pulled?
>
>
>
>
>
>
> On Tuesday, July 11, 2017 at 1:44:15 PM UTC-4, Justin Smith wrote:
>
>> My first suspicion would be that by the time you access the second
>> element, you have exited the context of your database transaction, so
>> there's no data stream available to get it from. Lazyness doesn't tend to
>> mix well with stateful resources and contexts.
>>
>> On Mon, Jul 10, 2017 at 9:45 PM <lawrence...@gmail.com> wrote:
>>
> Okay, that was a deadend. After going through line by line, I could pretty
>>> well rule out any kind of Exception or Error. The first row from the
>>> database seems to go through all of the functions perfectly, without any
>>> errors. But the second row never gets called.
>>>
>>> Which takes me back to where I started. Why can't I give a lazy-seq to a
>>> Manifold Stream and simply have a function map over the stream?
>>>
>>>
>>> On Monday, July 10, 2017 at 11:25:43 PM UTC-4, lawrence...@gmail.com
>>> wrote:
>>>>
>>>>
>>>> Once again, my lack of knowledge of Java trips me up. Manifold relies
>>>> on Dirigiste, which relies on Java's Executor Service. I see a bit here:
>>>>
>>>>
>>>> http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
>>>>
>>>> Nurkiewicz writes:
>>>> "I got bitten by that too many times: it won't print *anything*. No
>>>> sign of java.lang.ArithmeticException: / by zero, nothing. Thread pool
>>>> just swallows this exception, as if it never happened. If it was a good'ol
>>>> java.lang.Thread created from scratch, UncaughtExceptionHandler
>>>> <https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.UncaughtExceptionHandler.html>
>>>>  could
>>>> work. "
>>>>
>>>> I suspect I'm facing something like that.
>>>>
>>>>
>>>>
>>>> On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com
>>>> wrote:
>>>>>
>>>>> By the way, this code works fine if I go into a (doseq) a level above
>>>>> enqueue, and then put each individual row onto the stream. Then the code
>>>>> loops over all of the rows. But that seems to defeat the whole point of
>>>>> using something like Manifold. I want to be able to put the whole lazy-seq
>>>>> on the stream. That is supposed to work, yes?
>>>>>
>>>>>
>>>>> On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com
>>>>> wrote:
>>>>>>
>>>>>> I'm using Zach Tellman's excellent Manifold library, though I admit I
>>>>>> don't fully understand it.
>>>>>>
>>>>>> My code queries a MySQL database and then needs to do some processing
>>>>>> on each row retrieved. I copy-and-pasted some code from the documentatio

Re: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-11 Thread Justin Smith
My first suspicion would be that by the time you access the second element,
you have exited the context of your database transaction, so there's no
data stream available to get it from. Lazyness doesn't tend to mix well
with stateful resources and contexts.

On Mon, Jul 10, 2017 at 9:45 PM  wrote:

> Okay, that was a deadend. After going through line by line, I could pretty
> well rule out any kind of Exception or Error. The first row from the
> database seems to go through all of the functions perfectly, without any
> errors. But the second row never gets called.
>
> Which takes me back to where I started. Why can't I give a lazy-seq to a
> Manifold Stream and simply have a function map over the stream?
>
>
> On Monday, July 10, 2017 at 11:25:43 PM UTC-4, lawrence...@gmail.com
> wrote:
>>
>>
>> Once again, my lack of knowledge of Java trips me up. Manifold relies on
>> Dirigiste, which relies on Java's Executor Service. I see a bit here:
>>
>> http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
>>
>> Nurkiewicz writes:
>> "I got bitten by that too many times: it won't print *anything*. No sign
>> of java.lang.ArithmeticException: / by zero, nothing. Thread pool just
>> swallows this exception, as if it never happened. If it was a good'ol
>> java.lang.Thread created from scratch, UncaughtExceptionHandler
>> 
>>  could
>> work. "
>>
>> I suspect I'm facing something like that.
>>
>>
>>
>> On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com
>> wrote:
>>>
>>> By the way, this code works fine if I go into a (doseq) a level above
>>> enqueue, and then put each individual row onto the stream. Then the code
>>> loops over all of the rows. But that seems to defeat the whole point of
>>> using something like Manifold. I want to be able to put the whole lazy-seq
>>> on the stream. That is supposed to work, yes?
>>>
>>>
>>> On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com
>>> wrote:

 I'm using Zach Tellman's excellent Manifold library, though I admit I
 don't fully understand it.

 My code queries a MySQL database and then needs to do some processing
 on each row retrieved. I copy-and-pasted some code from the documentation
 for Manifold:


 ;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200
 threads.
 ;; query_database/start will pull data from the database and dump it
 onto a
 ;; stream below, at which point each row should be assigned to one of
 the rows
 ;; on our thread pool.
 (def executor (me/fixed-thread-executor 200))


 (defn enqueue
   [sequence-from-database]
   (slingshot/try+
(println "the type of the object from the database: " (type
 sequence-from-database))
(->> (ms/->source sequence-from-database)
 (ms/onto executor)
 (ms/map api/query))
(catch Object o
  (println " message queue is not happy about the message we were
 given")
  (errors/error o "" " we tried to put something on the message
 queue, but we got an error "

 The line where I print out the type assures that I'm dealing with a
 LazySeq.

 The code prints out the type and the first row:


 the type of the object from the database:  clojure.lang.LazySeq

 in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive
 Group, :headquarters_addr1 90 Madison St., :headquarters_city Denver,
 :headquarters_state_code CO, :headquarters_country_code US, :url
 mikeshawauto.com}

 and then it stops. I assume there must be an Exception or Error
 happening, but I can't find it. I've added as many general Catch clauses as
 I could:


 (defn query
   [row & args]

   (println " in query_api/query " row)

   (let [config (if args
  (first args))
 ]
 ;; 2017-03-30 -- the API is overwhelmed and all I get is Socket
 Timeout errors
 (Thread/sleep 300)

 (slingshot/try+
  (call-api row)
  (catch Object o
(println " error : " o)

;;(errors/error o row " we tried to call-api, but we got this
 error ")


)

  (catch Error e
(println " there Error: " e))
  )))

 So if I do:

 java  -jar scan-database-find-similar-items-standalone.jar


 The code runs till it prints out the first row from the database, and
 then it stops. Nothing else happens. There are no error messages.

 What did I miss?







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

Re: def partially done when used in if

2017-06-29 Thread Justin Smith
It creates an "undefined" var if the def gets compiled but doesn't get run.
This isn't the same as an "undefined behavior" as is documented for
languages that have formal specifications (clojure of course has none). I
did qualify that def / defn inside other forms are "generally" a sign of
bad design. There are of course special cases where they might be the least
bad option.

On Thu, Jun 29, 2017 at 3:15 PM Kaiming Yang <yaxu...@gmail.com> wrote:

> Thanks Justin,
>
> Sadly in my case those mutable container will not work because I was
> making a monkey-patch to a bug in a macro from other package.
>
> Despite what I was doing, I think "a bad design" in clojure spec is too
> weak to fit this situation. If someone tells me "it is a bad design" I
> would think I will spend more development/computation time to make it work
> but I would still expect *correct* result. "An undefined behavior" would be
> a more suitable.
>
>
> On Thursday, June 29, 2017 at 1:15:23 PM UTC-7, Justin Smith wrote:
>
>> Clojure's compiler (there's no interpreter) creates vars for every def
>> inside a form it compiles. Before the def actually runs it's unbound (as if
>> you had used declare).
>>
>> Generally def and defn that are not top level forms are signs of a bad
>> design. If you need runtime rebinding use a proper mutable container like
>> and atom, ref, or agent, this is what they are for, and they eliminate a
>> number of gotchas that come with runtime redefinition.
>>
>> On Thu, Jun 29, 2017 at 1:07 PM Kaiming Yang <yax...@gmail.com> wrote:
>>
> Hi,
>>> Recently encountered a weird issue, A def in if clause declared a var
>>> but left it unbound.
>>>
>>> I encountered this issue when I was trying to implement something like
>>> "define a symbol if it is not defined yet". Naively I tried:
>>>
>>> (if (nil? (resolve 'foo))
>>>   (def foo 42))
>>> ; Cannot use (def foo (if (nil? (resolve 'foo)) foo 42)) because foo
>>> might be macro
>>>
>>> I tried in repl and the result really surprised me:
>>>
>>> user=> foo
>>>
>>> CompilerException java.lang.RuntimeException: Unable to resolve symbol:
>>> foo in this context,
>>> compiling:(/private/var/folders/1h/vhl8yb657mjf3pchm9cbc40m63f2d3/T/form-init8893781347079502941.clj:1:1062)
>>> user=> (if (nil? (resolve 'foo))
>>>   #_=>   (do (def foo 42) (prn "true-branch"))
>>>   #_=>   (prn "false-branch"))
>>> "false-branch"
>>> nil
>>> user=> foo
>>> #object[clojure.lang.Var$Unbound 0x6dc69f03 "Unbound: #'user/foo"]
>>>
>>> Seems once clojure interpreter declares the variable before really
>>> evaluate the clause with def.
>>>
>>> Is this an expected behavior? Should I ever use def in if or fn?
>>>
>>> Thanks!
>>> Kaiming
>>>
>>> --
>>> 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: def partially done when used in if

2017-06-29 Thread Justin Smith
Clojure's compiler (there's no interpreter) creates vars for every def
inside a form it compiles. Before the def actually runs it's unbound (as if
you had used declare).

Generally def and defn that are not top level forms are signs of a bad
design. If you need runtime rebinding use a proper mutable container like
and atom, ref, or agent, this is what they are for, and they eliminate a
number of gotchas that come with runtime redefinition.

On Thu, Jun 29, 2017 at 1:07 PM Kaiming Yang  wrote:

> Hi,
> Recently encountered a weird issue, A def in if clause declared a var but
> left it unbound.
>
> I encountered this issue when I was trying to implement something like
> "define a symbol if it is not defined yet". Naively I tried:
>
> (if (nil? (resolve 'foo))
>   (def foo 42))
> ; Cannot use (def foo (if (nil? (resolve 'foo)) foo 42)) because foo
> might be macro
>
> I tried in repl and the result really surprised me:
>
> user=> foo
>
> CompilerException java.lang.RuntimeException: Unable to resolve symbol:
> foo in this context,
> compiling:(/private/var/folders/1h/vhl8yb657mjf3pchm9cbc40m63f2d3/T/form-init8893781347079502941.clj:1:1062)
> user=> (if (nil? (resolve 'foo))
>   #_=>   (do (def foo 42) (prn "true-branch"))
>   #_=>   (prn "false-branch"))
> "false-branch"
> nil
> user=> foo
> #object[clojure.lang.Var$Unbound 0x6dc69f03 "Unbound: #'user/foo"]
>
> Seems once clojure interpreter declares the variable before really
> evaluate the clause with def.
>
> Is this an expected behavior? Should I ever use def in if or fn?
>
> Thanks!
> Kaiming
>
> --
> 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 does gen-class executes with *ns* bound to clojure.core?

2017-06-20 Thread Justin Smith
*ns* is a dynamic var, so it points to the current namespace when your
function is running. Most code doesn't switch into a target ns in order to
execute functions from it.

On Tue, Jun 20, 2017 at 4:51 PM Didier  wrote:

> Especially given this:
>
> (ns dda.main
>   (:gen-class))
>
> (def should-exist "Do I exist?")
>
> (defn -main [] (prn (str should-exist \space (ns-name *ns*
>
>
>
> The (def) is evaluated, since should-exist is found when -main is called
> from the generated class, but why isn't (ns) evaluated? Which should have
> changed *ns* to "dda.main".
>
>
>
> On Tuesday, 20 June 2017 16:46:27 UTC-7, Didier wrote:
>>
>> Take this code:
>>
>> (ns dda.main
>>   (:gen-class))
>>
>> (defn -main [] (prn (ns-name *ns*)))
>>
>>
>> If you bootstrap this through clojure.main, such as what lein does, it
>> will print the namespace as "user". But if you bootsrap it through the
>> generated java main class, it will return "clojure.core".
>>
>> My intuition would have assumed it would be running under "dda.main" as
>> the *ns*, or at least under "user", since that's a common convention.
>>
>> I'm curious to know why "clojure.core"?
>>
> --
> 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: Seeking a function to partially parallelize collection processing

2017-06-20 Thread Justin Smith
channel operations are io, and intermixing them with processing leads to
code that is difficult to read and debug. core.async has facilities to help
you code more declaratively over channels. I think TImothy Baldridge's talk
at the last Clojure/West does a great job of presenting the issue
https://www.youtube.com/watch?v=096pIlA3GDo

On Tue, Jun 20, 2017 at 11:44 AM Tom Connors  wrote:

> Thanks, Justin. Regarding the mixing of program logic with channel io, I'm
> don't understand why that's a problem in this case or how it could be
> improved. Do you mind explaining that a bit more?
>
> --
> 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: Seeking a function to partially parallelize collection processing

2017-06-20 Thread Justin Smith
Aside from style issues of mixing channel input/output with program logic,
and hiding the useful return value of go-loop, the real problem here is
doing your work inside a go block. Go blocks are not meant for blocking
tasks, whether CPU or IO bound; doing real work inside go blocks risks
starving all of core.async's implementation threads which prevents all your
go blocks from doing work. Use async/thread to do work in a real thread and
park on the channel it returns.

On Tue, Jun 20, 2017 at 10:15 AM Tom Connors  wrote:

> Thanks for the suggestion, Didier, but I was unable to find a way to make
> pmap work for my use case. For those interested, here's what I came up
> with, then some  questions:
>
> (defn parallel-per
>   "Handle records from input-chan in parallel, but records with matching
> `splitter` return values serially."
>   [splitter handler input-chan]
>   (let [blockers (atom {}) ;; map of group-key to [chan num-remaining]
> status-chan (async/chan)]
> (async/go-loop []
>   (let [[val port] (async/alts! [input-chan status-chan])]
> (if (= port input-chan)
>   (if (some? val)
> (let [group-key (splitter val)]
>   (if-let [blocker (get @blockers group-key)]
> (let [[blocker-chan ^long num-remaining] blocker
>   next-blocker-chan (async/chan)]
>   (swap! blockers assoc group-key [next-blocker-chan (inc
> num-remaining)])
>   (async/go
> (async/ (handler val)
> (async/put! status-chan group-key)
> (async/close! next-blocker-chan))
>   (recur))
> (let [blocker-chan (async/chan)]
>   (swap! blockers assoc group-key [blocker-chan 1])
>   (async/go
> (handler val)
> (async/put! status-chan group-key)
> (async/close! blocker-chan))
>   (recur
> (async/close! status-chan))
>   (let [group-key val
> [_ ^long num-remaining] (get @blockers group-key)]
> (if (> num-remaining 1)
>   (do
> (swap! blockers update-in [group-key 1] dec)
> (recur))
>   (do
> (swap! blockers dissoc group-key)
> (recur)))
> nil))
>
> Does anything in here look bad? Is there a way to gracefully handle
> input-chan closing without using loop/recur? I'm using a new channel for
> every new record to block the next record with the same `splitter` return
> value - my first approach used one channel per distinct `splitter` value,
> but I saw some results printed out of order. Does this mean that the order
> of takes from 
> --
> 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: Seeking a function to partially parallelize collection processing

2017-06-16 Thread Justin Smith
pmap is rarely actually useful, but point 1 is false, pmap doesn't require
that it's input or output fit in memory

On Fri, Jun 16, 2017 at 12:52 PM Tom Connors  wrote:

> Hello Jose,
> Thank you for the response, but pmap does not address my use case. It's
> insufficient for two reasons: 1) the entire collection must fit in memory.
> My use case is handling records from a Kinesis stream. and 2) pmap
> parallelizes over the whole collection, whereas I want to parallelize the
> collection handling while handling subsets of the data sequentially, as I
> discussed in my first post.
> - Tom
>
> On Friday, June 16, 2017 at 10:13:11 AM UTC-4, Tom Connors wrote:
>>
>> I'm looking for a function that would likely be named something like
>> "sequential-by" or "parallel-per" that takes some data-producing thing like
>> a lazy seq or a core async channel, a function to split records from that
>> input, and a function to handle each item. Each item with an identical
>> return value from the "split" function would be handled sequentially, while
>> the handling of the collection as a whole would be parallel.
>>
>> If we assume this signature:
>> (parallel-per splitter handler inputs)
>>
>>
>> Calling it like this:
>> (parallel-per :id
>>   (fn [m] (prn (update m :val inc)))
>>   [{:id 1 :val 1}, {:id 1 :val 2}, {:id 3 :val 1}])
>>
>>
>> Would result in the first two maps being handled sequentially, while the
>> third map is handled in parallel with the first two. The order of the
>> printed lines would probably be non-deterministic, except {:id 1 :val 2}
>> would be printed before {:id 1 :val 3}.
>>
>> Note that for my use case I don't care about return values, but if
>> something like this already exists it's plausible that it returns something
>> equivalent to (map handler inputs).
>>
>> Does anything like this already exist in core or some lib? If not, any
>> recommendations for how to build 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.
>

-- 
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 file parsing with Clojure

2017-06-16 Thread Justin Smith
The primary suggestion I'd make here is to replace the doseq/reset!
construction in your main loop with reduce using a hash-map accumulator
representing each value you are updating with a separate key. This isn't
just more idiomatic, it also performs better.

Instead of:

(let [hexagrams (atom (sorted-map))
  state (atom :do-nothing)
  current-hexagram (atom {})]
  (doseq [line (line-seq rdr)]
(let [state-machine (@state PRETTY-STATE-MACHINE)
  line-match (re-matches (:regex state-machine) line)
  [new-state new-hexagram] ((:handler state-machine) line-match
@current-hexagram)]
  (reset! state new-state)
  (reset! current-hexagram new-hexagram)
  (swap! hexagrams assoc (:king-wen-number new-hexagram)
new-hexagram

something like:

(reduce (fn [acc line]
  (let [{:keys [state hexagrams current-hexagram]} acc
state-machine (state PRETTY-STATE-MACHINE)
line-match (re-matches (:regex state-machine) line)
[new-state new-hexagram] ((:handler state-machine)
line-match current-hexagram)]
{:state new-state
 :current-hexagram new-hexagram
 :hexagrams (assoc (:king-wen-number new-hexagram)
new-hexagram)}))
(line-seq rdr))

as a more minor issue, we idiomatically use [a b] instead of (vector a b)

On Fri, Jun 16, 2017 at 9:16 AM AndyK  wrote:

> hello,
>
> i'm looking for some feedback on how i've used Clojure to do some file
> parsing
> still getting the hang of Clojure ways of thinking and i'd love to hear
> any advice on how to improve what i've done
> for example, i'm guessing the way i've used cond blocks is a bit sketchy -
> at that point, i was kind of in a just-get-it-done mindset
>
> the file being parsed is here
>
> https://github.com/AndyKriger/i-ching/blob/master/clojure/resources/i-ching.html
>
> the code doing the parsing is here
>
> https://github.com/AndyKriger/i-ching/blob/master/clojure/src/i_ching/parser.clj
>
> the output is here (a browser JSON viewer is advised)
>
> https://raw.githubusercontent.com/AndyKriger/i-ching/master/clojure/resources/i-ching.json
>
> thank you for any help
> a
>
> --
> 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: potential bug with pr-str+print

2017-05-02 Thread Justin Smith
there's something going on with dynamic bindings here

peregrine.circle=> (let [xs (map #(pr-str %) ["a" "b"])] (println xs))
(a b)
nil
peregrine.circle=> (let [xs (doall (map #(pr-str %) ["a" "b"]))] (println
xs))
("a" "b")
nil


On Tue, May 2, 2017 at 1:55 AM Paulus Esterhazy 
wrote:

> Looks like a bug to me. ClojureScript doesn't seem to have this problem.
>
> On Tue, May 2, 2017 at 7:50 AM, Jenny Finkel  wrote:
> > Hello!
> >
> > I think I may have found a bug in clojure. When pr-str is called from
> within
> > print, it doesn't produce a read-string-able string. Here is a simple
> > example:
> >
> > user> (let [xs (doall (map #(pr-str %) ["a" "b"]))] (print xs))
> > ("a" "b")
> > user> (let [xs (map #(pr-str %) ["a" "b"])] (print xs))
> > (a b)
> >
> > The reason is that print binds *print-readably* to nil, whereas pr-str
> does
> > not bind it to true, even though I believe it should. If this really is a
> > bug, I'd be happy to submit a patch for it.
> >
> > Thanks, Jenny
> >
> > --
> > 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: Interop with strange java type: java.lang.String

2015-08-20 Thread Justin Smith
I suspect this is it. Also, remember that internally a varargs string 
method will take an Array of String as its last arg.

On Thursday, August 20, 2015 at 9:35:19 AM UTC-7, squeegee wrote:


 On Aug 20, 2015, at 3:32 AM, Andy Dwelly andyd...@gmail.com javascript: 
 wrote:

 Does anyone know how how to create a java.lang.String ? Ideally how to 
 convert a Clojure some string which is a java.lang.String to a 
 java.lang.String.
 Also, although this is merely idle curiosity on my part, does anyone know 
 what a java.lang.String actually is? The  suggests a generic, but 
 java.lang.String is not a container - although the  is empty of course.


 I don’t have a complete answer, but maybe these references will help:

 I recall seeing a  in this post:

 http://tech.puredanger.com/2011/08/12/subclassing-in-clojure/

 and I see it mentioned here:


 http://dishevelled.net/Tricky-uses-of-Clojure-gen-class-and-AOT-compilation.html

 Maybe that argument is an array of Object where the objects are Strings. 
 In other contexts I have seen the class name for an array of Strings 
 displayed as “class [Ljava.lang.String”, but perhaps it’s printed 
 differently by this reflection API.

 —Steve



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


Re: The following behavior of into function is a bug or the intended result?

2015-08-09 Thread Justin Smith
PersistentArrayMap is automatically promoted to PersistentHashMap when it 
reaches a specific size. This is done for performance reasons. Neither 
collection is considered ordered, and you should use a different datatype 
if you want ordered data.

On Sunday, August 9, 2015 at 6:31:20 PM UTC-7, Philos Kim wrote:

 This works well as expected. The order of input elements is maintained.

 (into (array-map) [[1 :a] [2 :b] [3 :c] [4 :d] [5 :e] [6 :f] [7 :g] [8 
 :h]])
 ; = {1 :a, 2 :b, 3 :c, 4 :d, 5 :e, 6 :f, 7 :g, 8 :h}

 However, as soon as the number of the input elements exceeds 9, the order 
 is not maintained any more.

 (into (array-map) [[1 :a] [2 :b] [3 :c] [4 :d] [5 :e] [6 :f] [7 :g] [8 :h] 
 [9 :i]])
 ; = {7 :g, 1 :a, 4 :d, 6 :f, 3 :c, 2 :b, 9 :i, 5 :e, 8 :h}

 Is this a bug or the intended result?


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

2015-07-28 Thread Justin Smith
I use agents instead of atoms when the function altering the value has side 
effects, or is especially expensive (and thus should not retry).

I haven't had to use refs yet, but my use case would be if the mutable data 
has enough parallel modification that splitting one atomic map into 
separate ref maps would be a performance boost.

On Monday, July 27, 2015 at 11:00:56 PM UTC-7, Daniel Compton wrote:

 I think this is pretty unlikely. While megarefs look very cool, I'm not 
 sure what the benefit to having these directly in Clojure would be over 
 having them in a library. 

 Anecdotally, everyone I have talked to about Clojure's reference types 
 have said that they have never needed to use ref's or agents in real world 
 code (I'm sure some people have to good effect though).

 That being said, you can always open a JIRA or design doc about this if 
 you feel strongly about it to start a discussion.

 --
 Daniel.

 On Tue, 28 Jul 2015 at 9:05 AM Lawrence Krubner lawr...@rollioforce.com 
 javascript: wrote:

 Off topic, but I wonder if there was ever any discussion of megarefs 
 being added to Clojure?

 https://github.com/cgrand/megaref


 On Tuesday, July 21, 2015 at 3:30:46 PM UTC-4, Rangel Spasov wrote:

 Ok, I think someone already mentioned this - sorry. Got it to compile by 
 bumping to [potemkin 0.4.1] - thanks Zach + all : ) 

 On Tuesday, July 21, 2015 at 12:24:43 PM UTC-7, Rangel Spasov wrote:

 Hey guys,

 Getting this error with 1.8.0-alpha2, I think related to aleph (using 
 0.4.0, latest version at the moment).

 #error {

  :cause IllegalName: 
 compile__stub.aleph.http.core.aleph.http.core/HeaderMap

  :via

  [{:type clojure.lang.Compiler$CompilerException

:message java.lang.NoClassDefFoundError: IllegalName: 
 compile__stub.aleph.http.core.aleph.http.core/HeaderMap, 
 compiling:(aleph/http/core.clj:81:1)

:at [clojure.lang.Compiler analyzeSeq Compiler.java 6798]}

   {:type java.lang.NoClassDefFoundError

:message IllegalName: 
 compile__stub.aleph.http.core.aleph.http.core/HeaderMap

:at [java.lang.ClassLoader preDefineClass ClassLoader.java 654]}]

  :trace

  [[java.lang.ClassLoader preDefineClass ClassLoader.java 654]

   [java.lang.ClassLoader defineClass ClassLoader.java 758]

   [java.lang.ClassLoader defineClass ClassLoader.java 642]

   [clojure.lang.DynamicClassLoader defineClass DynamicClassLoader.java 
 46]

   [clojure.lang.Compiler$NewInstanceExpr compileStub Compiler.java 7815]

   [clojure.lang.Compiler$NewInstanceExpr build Compiler.java 7680]

   [clojure.lang.Compiler$NewInstanceExpr$DeftypeParser parse 
 Compiler.java 7590]

   [clojure.lang.Compiler analyzeSeq Compiler.java 6791]

   [clojure.lang.Compiler analyze Compiler.java 6592]

   [clojure.lang.Compiler analyze Compiler.java 6553]

   [clojure.lang.Compiler$BodyExpr$Parser parse Compiler.java 5929]

   [clojure.lang.Compiler$LetExpr$Parser parse Compiler.java 6247]

   [clojure.lang.Compiler analyzeSeq Compiler.java 6791]

   [clojure.lang.Compiler analyze Compiler.java 6592]

   [clojure.lang.Compiler analyze Compiler.java 6553]

   [clojure.lang.Compiler$BodyExpr$Parser parse Compiler.java 5929]

   [clojure.lang.Compiler$FnMethod parse Compiler.java 5359]

   [clojure.lang.Compiler$FnExpr parse Compiler.java 3959]

   [clojure.lang.Compiler analyzeSeq Compiler.java 6789]

   [clojure.lang.Compiler analyze Compiler.java 6592]

   [clojure.lang.Compiler eval Compiler.java 6847]

   [clojure.lang.Compiler eval Compiler.java 6839]

   [clojure.lang.Compiler load Compiler.java 7295]

   [clojure.lang.RT loadResourceScript RT.java 372]

   [clojure.lang.RT loadResourceScript RT.java 363]

   [clojure.lang.RT load RT.java 453]

   [clojure.lang.RT load RT.java 419]

   [clojure.core$load$fn__5448 invoke core.clj 5866]

   [clojure.core$load doInvoke core.clj 5865]

   [clojure.lang.RestFn invoke RestFn.java 408]

   [clojure.core$load_one invoke core.clj 5671]

   [clojure.core$load_lib$fn__5397 invoke core.clj 5711]

   [clojure.core$load_lib doInvoke core.clj 5710]

   [clojure.lang.RestFn applyTo RestFn.java 142]

   [clojure.core$apply invoke core.clj 632]

   [clojure.core$load_libs doInvoke core.clj 5749]

   [clojure.lang.RestFn applyTo RestFn.java 137]

   [clojure.core$apply invoke core.clj 632]

   [clojure.core$require doInvoke core.clj 5832]

   [clojure.lang.RestFn invoke RestFn.java 551]

   [aleph.http.server$eval9251$loading__5340__auto9252 invoke 
 server.clj 1]

   [aleph.http.server$eval9251 invoke server.clj 1]

   [clojure.lang.Compiler eval Compiler.java 6850]

   [clojure.lang.Compiler eval Compiler.java 6839]

   [clojure.lang.Compiler load Compiler.java 7295]

   [clojure.lang.RT loadResourceScript RT.java 372]

   [clojure.lang.RT loadResourceScript RT.java 363]

   [clojure.lang.RT load RT.java 453]

   [clojure.lang.RT load RT.java 419]

   [clojure.core$load$fn__5448 invoke core.clj 5866]

   [clojure.core$load doInvoke core.clj 5865]

   [clojure.lang.RestFn 

Re: [ANN] Pink 0.2.0, Score 0.3.0

2015-07-28 Thread Justin Smith
Overtone has its own composition logic, but for synthesis it is a client 
for the open source Supercollider audio synthesis server (which is a cross 
platform C++ program that can be controlled via the network). Pink and 
Score are built in Clojure and Java without using an external server.

On Tuesday, July 28, 2015 at 9:54:14 AM UTC-7, W. David Jarvis wrote:

 This might be a naive question, but for someone who's only tangentially 
 familiar with the space, where does this fit in to the overall Clojure 
 music/sound ecosystem (re: overtone et al)?

 On Saturday, July 25, 2015 at 1:03:44 PM UTC-4, Steven Yi wrote:

 Thanks Ruslan and best of luck in your musical work! 

 On Sat, Jul 25, 2015 at 12:24 AM, Ruslan Prokopchuk fer@gmail.com 
 wrote: 
  Steven, thank you for continuing to develop Pink  Score! I have some 
 music 
  projects as my slowly-moving-forward-hobbies, and having pure java, no 
 deps 
  like Supercollider, engine for one of them is very precious! 
  
  пятница, 24 июля 2015 г., 23:47:30 UTC+3 пользователь Steven Yi 
 написал: 
  
  Hi All, 
  
  I'd like to announce the release of Pink 0.2.0 and Score 0.3.0: 
  
  [kunstmusik/pink 0.2.0] 
  [kunstmusik/score 0.3.0] 
  
  Pink is an audio engine library, and Score is a library for 
  higher-level music representations (e.g. notes, phrases, parts, 
  scores). 
  
  ChangeLogs are available at: 
  
  https://github.com/kunstmusik/pink/blob/master/CHANGELOG.md 
  https://github.com/kunstmusik/score/blob/master/CHANGELOG.md 
  
  The quick version is Pink now has some new effects (ringmod, freeverb, 
  chorus) as well as some new filters and delay-based audio functions. 
  Score has a new sieves namespace for Xenakis-style sieves. (An example 
  of sieves and freeverb is available in the music-examples project 
  [1]). 
  
  For any questions, please feel free to email me or post on the 
  pink-users list.  For issues and PR's, please use the facilities on 
  Github for each of the projects. 
  
  Thanks! 
  steven 
  
  
  [1] - 
  
 https://github.com/kunstmusik/music-examples/blob/master/src/music_examples/sieves.clj
  



-- 
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: One more argument for cyclic dependencies

2015-05-20 Thread Justin Smith
I'll second the recommendation to use protocols or interfaces to solve this.

Clojure is fairly opinionated in that the tools available should push you 
toward developing against interfaces or protocols rather than concrete 
implementations. Things become much simpler when you accept this. You can 
even have a single file that defines all the protocols you might need, and 
each of your classes can implement one or more protocols, while defining 
methods or fields that use other protocols with no circularity needed.

On Tuesday, May 19, 2015 at 8:57:19 AM UTC-7, Mars0i wrote:

 Gary wrote: 

 * I was under the impression that Clojure only restricted cyclic 
 dependencies between ns forms. Have you tried calling 
 import/require/gen-class directly? 

 Not much.  I did try one trick that involved switching namespaces inside a 
 file, but it didn't work. I can try other things.

-- 
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 needs a web framework with more momentum

2015-05-05 Thread Justin Smith
Wow, what a thread!

As one of the authors and designers of Caribou, I have a couple of 
clarifications to offer.

When the initial post compared contributors and commits, it picked our 
caribou repo, which, while extensive, holds no code, only our docs. The 
actual code is in caribou-core (persistence layer via edn abstraction), polaris 
(routing via edn data structures), caribou-api (rest api to caribou-core), 
antlers (an extended edn friendly mustache for templating), lichen (automated 
caching image resizer with optional s3 integration and stand alone http 
server), schmetterling (web ui for debugging exceptions, with in frame 
evaluation and locals display), caribou-frontend (pulling together core, 
antler, lichen, polaris and ring to make a site), and caribou-admin (crud ui 
for caribou-core models, including a drag and drop ui to define routes that can 
be imported by polaris).

Caribou is not abandoned, though it did lose funding. I currently use core plus 
polaris without the other components at my day job, though working on Caribou 
itself is not strictly in scope for my salaried work.

Which is to say, Caribou is very much a modular framework ( though much of it 
does rely on the caribou-core persistence abstraction). It's imperfect but 
useful, and work is slowed but not abandoned.

 I'm always always in #caribou on freenode, and we have extensive docs.

-- 
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, not the go to for data science

2015-04-02 Thread Justin Smith
Emacs can use the native windowing system on every major platform. It still 
*looks* like a terminal app, but doesn't have to be one.

Pretty much everything you are saying here doesn't apply to Emacs at all, 
and you would know it's all false if you knew anything about Emacs.

On Wednesday, April 1, 2015 at 4:55:08 PM UTC-7, Fluid Dynamics wrote:

 On Tuesday, March 31, 2015 at 8:45:31 AM UTC-4, Phillip Lord wrote:

 The benefit is that Emacs is that its not constantly changing, and it 
 gives you some stability over the years. I like latex, for instance, for 
 the same reason. I can still access a 10 year old document and use it.


 First of all, there are other posts in this thread complaining about 
 constantly changing stuff breaking things! One such post is by Colin Yates.

 Second, to the extent that it isn't changing, it is legacy. Which helps to 
 explain the Wordperfect for DOS style of UI, which is dependent on vast 
 numbers of complex key-combinations being memorized by the user, instead of 
 a just-sit-down-and-start-using-it UI like everything originating after, 
 say, 1995 or so has tended to have. Of course, the result is that 
 Wordperfect (and emacs) seemed to require a great deal of specialized 
 training just to accomplish even the most basic tasks, whereas with modern 
 interfaces the way to do such basic tasks (save, open, copy and paste, move 
 around, select, etc.) tends to be obvious and special training can focus 
 exclusively on doing advanced things (scripting, complicated Photoshop 
 filters and tricks, things like those).

 Legacy also, obviously, tends to present problems in other areas besides 
 UI-boneheadedness:

 * I18n and l10n
 * Compatibility, with modern hardware and with modern operating systems, 
 though that can be alleviated by people porting the code
 * Boneheaded internal limits, along the same general lines as 640K ought 
 to be enough for anybody. It may be unable to use more than a small 
 fraction of what modern hardware can offer it in the way of memory, 
 storage, cores, ...
 * Accessibility. Interposing a terminal emulator between the app and 
 screen reading software might cause problems, though on the other hand a 
 text mode app may ultimately have advantages in that area too. On the other 
 hand, it may not play well with accessibility tools
   that rely on standard UI conventions. Anything that responds to some 
 voice command by generating control-V keystrokes to paste, or that relies 
 on the presence of normal menus and/or mouse support is going to blow up 
 spectacularly when used with 1980s-vintage Unix
   (or MS-DOS) software, or at best will end up controlling the 
 xterm/Command Prompt window instead of the underlying app.
 * Interoperation with other (non-operating-system) software. On Windows it 
 won't speak OLE, DDE, OCX, or etc., and copying text in it and attempting 
 to paste into something else (web browser, calculator, etc.) is doomed to 
 failure. This is a general problem with
   pre-window-system software, much like the stuff listed under 
 Accessibility, with no easy solution. Terminal emulators tend to provide 
 some way to copy from their display into the host-native clipboard, but it 
 tends to be clunky (the Windows command prompt appears to
   require mouse use, with no keyboard shortcuts) and runs into the obvious 
 difficulties as soon as you want to copy more than will fit on one screen. 
 Ironically, really primitive stuff like ls and dir that just dump 
 possibly-paginated noninteractive listings to the term are easier
   to make big copies from than text-mode, interactive applications like 
 screen-oriented editors, because you can copy from the backscroll buffer of 
 the terminal emulator in the first case. Pre-window-system *graphical* apps 
 are the absolute worst, e.g. later, WYSIWYG
   word processor versions on MS-DOS, or pre-window-system X applications. 
 No internal support for the host clipboard and, at the same time, nothing 
 the emulator will recognize as text, meaning if you try to native copy and 
 paste you'll end up with a PNG or something.
   OCR might work on that, if you can find cheap or free OCR software 
 that's any good. Your better bet would be to save the document as some 
 format that can be read by a native windowed app and then open the file in 
 that, then copy, and at that point you might as well
   edit in the native windowed app and throw out the legacy cruft entirely, 
 since you'll have to deal with the native app anyway, and the cost of 
 switching between them constantly, reloading in the native app so it sees 
 changes, and re-locating the places you want to copy
   from in the native app will quickly grow to outweigh any advantage the 
 legacy app might somehow have due to some feature it has that you haven't 
 found in any native app.

 Put more simply, there are giant costs to not playing well with others, 
 and these are inevitably incurred by all applications developed prior 

Re: How do I upgrade nREPL?

2015-03-30 Thread Justin Smith
You can use a newer version by putting your nrepl dep under the :dev 
profile, which will override the version that leiningen wants.

On Sunday, March 29, 2015 at 11:46:55 PM UTC-7, Tassilo Horn wrote:

 Shannon Severance s...@s53.me javascript: writes: 

  I would like to upgrade nREPL, but it appears I am still using version 
  0.2.6. 

 Yes, that's the version Leiningen depends on, so I think we all have to 
 wait until the next Leiningen upgrade to satisfy CIDER. 

 Bye, 
 Tassilo 


-- 
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: Incanter rendering a blank window

2015-03-28 Thread Justin Smith
I've had issues with JVM GUIs and tiling window managers, sometimes 
floating and then tiling the window (or even hiding/ showing the window, or 
resizing) will make the contents show up. I don't know if there is an 
application level fix for this, and I'm not sure whether it should be 
considered a WM bug (not propagating the resize / expose events the apps 
expect) or a bug in the lib.

On Saturday, March 28, 2015 at 6:44:07 PM UTC-7, Bill Piel wrote:

 I decided to try out incanter. Following the instructions, I ran this in 
 the repl:

 *user= (view (histogram (sample-normal 1000)))*

 A blank, grey window popped up. I can right-click and save it to a png. 
 The png shows the graph as expected. I get the same results for other 
 commands. I googled around, but came up with nothing.

 I'm running Ubuntu 14.04 with xmonad.

 Here's my project.clj:

 (defproject try-incanter 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.6.0]
  [incanter/incanter-core 1.9.0]
  [incanter/incanter-charts 1.9.0]]
   :main ^:skip-aot try-incanter.core
   :target-path target/%s
   :profiles {:uberjar {:aot :all}})


 Any ideas? thanks


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


Re: How to persist a value while doing do-seq

2015-03-04 Thread Justin Smith
Consider using for, and returning the new set of values

(for [[a b] (partition 2 1 coll)]
   (if (= (:foo a) (:foo b))
   (dissoc a :foo)
   a))

Here I use partition so that each item can be compared to the one that 
follows it. You would likely want a final step that tacks on the last item 
in the input coll (since it is not processed by this code).

On Wednesday, March 4, 2015 at 11:36:34 AM UTC-8, mlimotte wrote:

 Probably a reduce is more appropriate.

 (reduce 
   (fn [x a] 
 (your-compare-expression x a)  ; the result of this expr is the result 
 of the fn and will be 'x' for the next iteration
 ) 
   0 b)


 BTW, a let to bind an atom outside your do-seq, while _not recommended_, 
 should work.  We would have to see your code to know why it didn't for 
 you.  Show you code if you're curious, but please don't actually do it this 
 way.



 On Tue, Mar 3, 2015 at 10:26 PM, noobcoder kel...@gmail.com javascript:
  wrote:

 Hi, 
 I have the following code structure

 (do-seq [a b]
 .
 .
 .
 )

 For each a in b, I want to check a particular value in a, store it and 
 compare it with the same value in next a. If it is same I want to clear it 
 before next a. I tried to define an x (atom 0) by having a let outside of 
 the do-seq. I can successfully compare the value of the atom and reset it, 
 but when I get the second a the atom value is again 0. How do I go about 
 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 
 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+u...@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+u...@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: Is Caribou Dormant ?

2015-02-28 Thread Justin Smith
I'm one of the core devs of the Caribou project.

Caribou has been less actively developed, but I still use it frequently.

We previously were funded to work on Caribou, but the company funding us 
decided to discontinue using Clojure (except for supporting some clients 
where Clojure code was deployed). Now we've all moved on to other 
employment situations, and I'm the only one actively using Caribou out of 
the core team. Bug reports and pull requests will be acknowledged, and 
likely acted on. There has been some work quite recently on polaris, our 
routing lib.

On Saturday, February 28, 2015 at 9:11:52 AM UTC-8, Sven Richter wrote:

 I am glad you like it. It is still pretty young, so like I said, just open 
 issues if you need more.

 Best Regards,
 Sven

 Am Samstag, 28. Februar 2015 16:22:41 UTC+1 schrieb g vim:

 On 27/02/2015 07:26, Sven Richter wrote: 
  Hi, 
  
  Please have a look at: https://github.com/sveri/closp/ and tell me 
 what 
  you are missing. 
  You might as well open feature / pull requests and I will consider 
  adding them. 
  
  Best Regards, 
  Sven 

 Great work, Sven. Just what I was looking for. Next - THE BOOK :) 

 gvim 



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


Re: javac-options are ignored

2015-02-20 Thread Justin Smith
This would make sense because javac isn't used to generate those classes.

On Thursday, February 19, 2015 at 5:08:33 PM UTC-8, Jeremy Heiler wrote:

 On February 19, 2015 at 4:40:16 PM, Felipe Gerard (fge...@interware.com.mx 
 javascript:) wrote: 
  When you set: 

  :javac-options [-target 1.6 -source 1.6” ] 

 This option is only for when you are compiling Java source. 


 https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L249:L251
  

  I think this is a bug. Any help please? 

 It looks like that 1.5 is hardcoded in the Clojure compiler. 

 See: 
 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java
  

 And search for “V1_5”. 


-- 
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: Generalisation of pre-conditions

2015-02-19 Thread Justin Smith
People complain about stack traces, but precisely the point of having stack 
traces is that if a pre-condition fails, you don't look at the function 
with the pre-condition, you look at the function that was calling it. 
Duplicating pre-conditions to callers, as a general pattern, would scale 
very badly.

On Thursday, February 19, 2015 at 4:35:54 AM UTC-8, Cecil Westerhof wrote:

 I have two different functions for the same functionality. I would like to 
 share the pre-conditions between them.

 The general function is:
 (defn test-lucky-numbers-general
   Performance test of lucky numbers general
   [fn desc nr]
   {:pre [(= nr 1)
  (= nr 7)]}
   (println desc)
   (dotimes [i 25]
 (let [lucky (time (fn 10))]))
   (println)
   (dotimes [i nr]
 (time
   (let [upto (int (Math/pow 10 (inc i)))]
 (printf With upto %d there are %d lucky numbers\n upto 
 (count (fn upto)
 (println)))


 The functions themselves are:
 ​(defn test-lucky-numbers
   Performance test of lucky numbers
   ([]
(test-lucky-numbers 6))
   ([nr]
(test-lucky-numbers-general lucky-numbers Testing performance 
 lucky-numbers nr)))
 and:
 (defn test-lucky-numbers-3
   Performance test of lucky numbers (3)
   ([]
(test-lucky-numbers-3 6))
   ([nr]
(test-lucky-numbers-general lucky-numbers-3 Testing performance 
 lucky-numbers-3 nr)))
 ​

 And to call all test functions I have:
 (defn test-lucky-numbers-all
   Test all lucky number performance
   ([]
(test-lucky-numbers-all 6))
   ([nr]
(test-lucky-numbers nr)
(test-lucky-numbers-3 nr)))


 When I call a function with the wrong parameter, I get an error from 
 test-lucky-numbers-general, but I need it from the calling function. I 
 could copy the pre-condition to all functions, but that is not really DRY. 
 Is there a way I can share the pre-conditions with all (at this moment) 
 four functions?


 The first dotimes in test-lucky-numbers-general is to warm-up the JVM. Is 
 there a way to know if this is already done for the function that is given? 
 Then it could be done only when necessary.

 -- 
 Cecil Westerhof
  

-- 
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: Using type to change the behaviour of a function

2015-02-19 Thread Justin Smith
one approach would be a multi-method for the condition check that doesn't 
enforce the limit on BigInt

user= (defmulti lucky-numbers-limit type)
#'user/lucky-numbers-limit
user= (defmethod lucky-numbers-limit :default [n] ( 0 n 1001))
#MultiFn clojure.lang.MultiFn@7533f6b5
user= (defmethod lucky-numbers-limit clojure.lang.BigInt [n] true)
#MultiFn clojure.lang.MultiFn@7533f6b5
user= (lucky-numbers-limit 2)
false
user= (lucky-numbers-limit 2)
true
user= (lucky-numbers-limit 2N)
true




On Thursday, February 19, 2015 at 3:52:38 AM UTC-8, Cecil Westerhof wrote:

 I have the following function:
 (defn lucky-numbers
   Lucky numbers from 1 up-to upto-value.
   1 = upto-value = 10.000.000
   http://en.wikipedia.org/wiki/Lucky_number;
   ; doc-string and pre-condition should match
   [upto]
   {:pre [(= upto 1)
  (= upto (* 10 1000 1000))]}
   (if ( upto 3)
   ; for 1 and 2 the algorithm does not work, so return value 
 manually
   (list 1)
 (loop [coll (range 1 (inc upto) 2), survivor-idx 1]
   (let [i (nth coll survivor-idx)]
 (if ( (count coll) i)
 (recur (drop-every-nth coll i) (inc survivor-idx))
   coll)

 ​In this function I limit the maximum value that ​can be given to the 
 function. But this is pure for performance reasons. So I would like to have 
 the possibility to disable it. I read somewhere that you can use types for 
 this. Sadly I do not remember where.

 At the moment the following:
 (lucky-numbers 1001)
 gives:
 AssertionError Assert failed: (= upto (* 10 1000 1000))  
 user/lucky-numbers

 But I would like the following to be executed:
 (lucky-numbers :no-max-check 1001)

 ​How would I implement that?

 -- 
 Cecil Westerhof
  

-- 
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] strange behaviour in self-referential primes lazy-seq attempt

2015-02-12 Thread Justin Smith
This is excellent, I was just working out something similar myself.

The version using an atom is not idiomatic Clojure, and isn't a translation 
of the Haskell version either.

On Thursday, February 12, 2015 at 4:30:02 PM UTC-8, Armando Blancas wrote:

 Jorge, I tried this on 1.6 and seemed to work:

 (def primes
   (cons 2 (for [n (iterate inc 3) :when (prime? primes n)] n)))

 On Thursday, February 12, 2015 at 4:21:45 PM UTC-8, Jorge Marques 
 Pelizzoni wrote:

 Neither did delay help:

 (defn primes [] (let [primes' (atom nil)]
   (reset! primes' (delay (cons 2 (filter #(prime? (force 
 (deref primes')) %) (drop 3 (range


 Serious this is not a bug?

 Em quinta-feira, 12 de fevereiro de 2015 22:14:46 UTC-2, Jorge Marques 
 Pelizzoni escreveu:

 Thanks, Michael, for your analysis and explanation. However not even 
 this worked:

 (defn primes [] (let [primes' (atom nil)]
   (lazy-seq (reset! primes' (lazy-seq (cons 2 (lazy-seq 
 (filter #(prime? (deref primes') %) (drop 3 (range))


  

-- 
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] strange behaviour in self-referential primes lazy-seq attempt

2015-02-12 Thread Justin Smith
it's an infinite lazy sequence with itself as a dependency. The first n 
elements see a value of the initial non-lazy prefix. The alternative would be a 
compilation 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: [newbie] strange behaviour in self-referential primes lazy-seq attempt

2015-02-12 Thread Justin Smith
it's an infinite lazy sequence with itself as a dependency. The first n 
elements see a value of the initial non-lazy prefix. The alternative would be a 
compilation 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.


  1   2   >