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

2021-06-24 Thread Justin Smith
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

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

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 funct

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

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

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 ma

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 outpu

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 conside

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

2020-11-02 Thread Justin Smith
ang.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: > > >

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

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 va

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

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 Ern

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 m

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

2019-11-22 Thread Justin Smith
e 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

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 defproto

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

2019-11-21 Thread Justin Smith
ottom > 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 j

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 pr

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

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 ca

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

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

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

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 a

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 e

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,

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

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

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

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 a

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

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 >

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 cancell

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
7; still fails the same way afterwards when using Ubuntu's OpenJDK > installation (and still succeeds when using Oracle's JDK installation). > > Andy > > On Mon, May 21, 2018 at 1:04 PM, Justin Smith > wrote: > >> I should have been more specific. Just uninstalling leaves

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 stac

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,

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

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

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

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 Proces

Re: namespace - multiple people

2018-02-10 Thread Justin Smith
should be structured, then write code that knows how to handle that data. On Sat, Feb 10, 2018 at 10:06 AM Justin Smith 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 t

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 b

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 wor

Re: what does future do after fn finish ?

2018-02-01 Thread Justin Smith
27;s using one agent, I see. >> >> On Jan 31, 2018 9:15 PM, "John Newman" 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 >>> belie

Re: what does future do after fn finish ?

2018-01-31 Thread Justin Smith
works (unless you're trying to do something else). > > John > > On Wed, Jan 31, 2018 at 7:31 PM, Jacek Grzebyta > wrote: > >> Thanks a lot. I will check it tomorrow. >> >> J >> >> On 1 Feb 2018 12:12 a.m., "Justin Smith" wrote: >>

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

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

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

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

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 locatio

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 S

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

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 wi

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 J

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 cont

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

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 compi

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 wrote: > paths have to reflect the packag

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

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

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,

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

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

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

2017-09-20 Thread Justin Smith
on now implements something > like IPersistentMap rather than IObj. The problem I had was if the function > was some Map-like object to begin with, I'd get confused about what was > 'data' and what was 'metadata'. > > On Wed, Sep 20, 2017 at 12:04 PM, Justin Smith

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

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 p

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.

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

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

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

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 wro

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

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 lookup

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

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

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

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:

Re: def partially done when used in if

2017-06-29 Thread Justin Smith
rk > 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 >&

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 mutabl

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

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

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

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 en

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

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 lik

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 > > wrote: > > Does anyone know how how to create a java.lan

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

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 Tue

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 r

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

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

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

Re: How do I upgrade nREPL?

2015-03-29 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 > writes: > > > I would like to upgrade nREPL, but it appears I am still u

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

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 it

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 depl

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 > ) wrote: > > When you set: > > > > :javac-options ["-target" "1.

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)) # user=> (defmethod lucky-numbers-limit clojure.lang.Big

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

Re: [newbie] strange behaviour in self-referential primes lazy-seq attempt

2015-02-12 Thread Justin Smith
urse not something you can simply figure out from first principles, it takes a bit of exploration and a few mistakes along the way). On Thursday, February 12, 2015 at 9:05:24 PM UTC-8, Justin Smith wrote: > > it's an infinite lazy sequence with itself as a dependency. The first n &g

  1   2   >