Re: Two suggestions re: core.spec, `ns`, and clojure 1.9alpha11

2016-08-25 Thread Timothy Baldridge
nnotations they carry in common parlance. I can see how my choice of wording here can be taken as a personal attack. And so for that, I do apologize, Brian. In the future I will attempt to use less loaded verbiage. Timothy Baldridge On Thu, Aug 25, 2016 at 10:33 AM, Timothy Baldridge wrote: &

Re: Why is this not considered to be in a go block?

2016-08-25 Thread Timothy Baldridge
I'm not sure I've ever addressed this publicly, so I assume now's as good a time as ever. The reason the go block stops at function boundaries, is that changing a function to be "async" changes it return type. With code transforms like these a function that performs a parking take on a channel no

Re: Connecting to nREPL on Intel Edison (via Cider) - why so slow?

2016-08-31 Thread Timothy Baldridge
Another option is to use Clojure's built-in socket server (requires Clojure 1.8) it is really nothing more than a TCP socket attached to a normal Clojure repl, so you'll be loading no extra middleware or really anything at all that could slow it down. http://clojure.org/reference/repl_and_main#_lau

Re: Deref Nil

2016-09-10 Thread Timothy Baldridge
I've worked with a model much like this, and as an experience report: it resulted in a lot of pain. Atoms inside atoms, or really more than one atom for the entire state of your app results in to many sources of mutability. On top of that, you have the problem of async updates: some part of your st

Re: idiomatic way of counting loop iteration

2016-09-12 Thread Timothy Baldridge
Also consider map-indexed if you just need to count how many things go through a lazy seq. It works like map, but takes a (fn [idx itm] ...) where idx is the index of the item in the overall seq. On Mon, Sep 12, 2016 at 3:10 PM, Gary Johnson wrote: > Almost right. The iterate function is an infi

Re: definterface odd error

2016-09-23 Thread Timothy Baldridge
Two things: a) I don't think the "..." need to be there. I think that was probably placeholder text from a tutorial? b) I'd suggest using defprotocol (http://clojure.org/reference/protocols) protocols have a number of benefits over interfaces. Timothy On Fri, Sep 23, 2016 at 1:21 PM, Jeff Murphy

Re: Is there a way to alpha 11 or higher, but disable a single spec?

2016-09-23 Thread Timothy Baldridge
Why not submit a PR against Lighttable as that's where the real bug is? On Fri, Sep 23, 2016 at 2:08 PM, Boris V. Schmid wrote: > lighttable has some trouble with the newer alpha's, in that it throws this > error: > > >> Call to clojure.core/ns did not conform to spec: ... ((require >> [clojure.

Re: Keywords with colon on the backside?

2016-09-23 Thread Timothy Baldridge
Almost all of Clojure's reader macros are prefix driven. For example, 'foo quotes the symbol "foo", a string "foo" starts with a prefix quote and terminates with another string. Same for lists (prefixed with a parentheses), vectors, maps, etc. Even var literals #'my-var are prefixed. So it's very n

Re: parallel sequence side-effect processor

2016-09-23 Thread Timothy Baldridge
How is fluokitten's fold any better than using seqs like (map f a b) would? Both create intermediate collections. On Fri, Sep 23, 2016 at 11:40 AM, Dragan Djuric wrote: > If you do not insist on vanilla clojure, but can use a library, fold from > fluokitten might enable you to do this. It is sim

Re: parallel sequence side-effect processor

2016-09-23 Thread Timothy Baldridge
But that would print 1 to 32 items depending on a ton of things. No the correct way to write code like that is (doseq [s coll] (println s)) If you need to iterate over multiple items then use (map f a b). Also I would suggest benchmarking things, sure (map f coll) is slower than a transducer,

Re: parallel sequence side-effect processor

2016-09-23 Thread Timothy Baldridge
How is this done, I searched the source, but there was so much indirection I can't find it. I'm familiar with how Haskell does rfold vs lfold, but one of those does create allocations, they may be in the form of closures, but they are allocations none the less. So does fold use iterators or somethi

Re: parallel sequence side-effect processor

2016-09-23 Thread Timothy Baldridge
Yeah, I have to call you out on this one Dragan. I ran the following code: (ns fold-test (:require [uncomplicate.fluokitten.core :refer [foldmap]])) (defn fa [& args] (println "fa " args) 1) (defn fb [& args] (println "fb " args) 1) (defn test-fold [] (foldmap fa nil fb [1 2 3] [4 5 6])) (test

Re: parallel sequence side-effect processor

2016-09-24 Thread Timothy Baldridge
Francis is correct, and I want to make a point about something he said. If you are mapping over two collections at once, you will either be using Java iterators, or you will be creating lazy sequences when you walk over the input collections. Sure, how many lazy sequences are create here and there

Re: Data Transformation Question

2016-10-12 Thread Timothy Baldridge
group-by is slightly different in that it wraps every value in a vector, and those vectors will contain multiple items if there is an id collision. So that may be what the OP wanted, but it also is a change in semantics. I we can simplify the code a bit to (zipmap (map :id data) data) which is abo

Re: core.async top use cases

2016-10-13 Thread Timothy Baldridge
>> When using clojurescript, adding async really increases the load time. That's one place where you might want to use agents when you can. But Clojurescript doesn't support agents. On Thu, Oct 13, 2016 at 7:16 PM, William la Forge wrote: > On Thursday, October 13, 2016 at 3:38:16 PM UTC-4, lar

Re: core.async top use cases

2016-10-13 Thread Timothy Baldridge
ed to a mutable reference without having to import core.async. On Thu, Oct 13, 2016 at 7:28 PM, Timothy Baldridge wrote: > >> When using clojurescript, adding async really increases the load time. > That's one place where you might want to use agents when you can. > > But

Re: core.async top use cases

2016-10-13 Thread Timothy Baldridge
Yeah, I used to do that, but once core.async came out I started to desire the back pressure aspects of channels. I don't think I've used agents for logging since. You always run the risk of something backing up the queue of the agent and causing your thread to crash when it runs out of memory. On

Re: Java like static typing for Clojure?

2016-10-17 Thread Timothy Baldridge
I highly recommend this talk on Spec by Stu Halloway. Spec is a new feature coming in Clojure 1.9, and this talk goes into the pros/cons of static typing and tests and shows how there can be a better way. https://www.youtube.com/watch?v=VNTQ-M_uSo8 On Sun, Oct 16, 2016 at 5:58 PM, Alan Thompson

Re: Java like static typing for Clojure?

2016-10-23 Thread Timothy Baldridge
>> but I might end up needing users with e.g. genuine Norwegian addresses. I think that's an interesting point, and it's a problem I've encountered several times myself. However I think it can be solved several ways. 1) If your validation function "norwegian-addr?" is a simple predicate, then the

Re: comp and partial vs ->>

2016-10-27 Thread Timothy Baldridge
I use comp all the time, not only for transducers, but also for digging into maps: (map (comp first :pets) [{:pets [:fluffy]} {:pets [:spot]}]) => (:fluffy, :spot) Partial is also handy when used with a lot of sequence functions (->> [1 2 3 4 5] (filter (partial > 3))) Sure I co

Re: comp and partial vs ->>

2016-10-28 Thread Timothy Baldridge
That was fixed in a patch that added special cases to partial when used with smaller numbers of arguments. It was never much slower, but it should be just as fast as hand made functions now. http://dev.clojure.org/jira/browse/CLJ-1430 On Fri, Oct 28, 2016 at 5:35 AM, Bobby Eickhoff wrote: > I a

Re: How would you spec deref-ables?

2016-10-29 Thread Timothy Baldridge
Specs are for checking the shape of data. "deferreds" are not data, they are opaque objects. So in short the answer is "you can't" or more correctly: you may be able to, but shouldn't. One of the problems with even trying to spec something like IDeref is that the very act of observing it may have

Re: How would you spec deref-ables?

2016-10-29 Thread Timothy Baldridge
I would stop the specing at the boundary of a IDeref. For example you can say "this function takes a integer and returns a instance of IDeref". Digging into the details of that object isn't something I would try to spec. Beyond that I would probably try to write functions that take data and retur

Re: Parsing Java with Instaparse

2016-11-03 Thread Timothy Baldridge
+1 for JavaParser. I used it recently on a project, and it *just works*. On Thu, Nov 3, 2016 at 8:39 AM, Vitaly Peressada wrote: > Thanks, Alex. Will give javaparser a try. > > > On Thursday, 3 November 2016 14:06:31 UTC, Alex Miller wrote: >> >> While writing a parser for Java with instaparse w

Re: Controlling how maps/records/atoms etc. are printed out

2016-11-12 Thread Timothy Baldridge
clojure.core/print-method is a multi method that handles the printing of objects. You can override or implement the print method by: (defmethod print-method my.class.Foo [^my.class.Foo instance ^Writer w] (.write w ...)) I do that to provide custom printing for deftypes, but you can easil

Re: def partial vs let partial

2016-12-01 Thread Timothy Baldridge
It's because the value of the + is captured when the partial is created (or when the var is implicitly derefed). The value of the var is implicitly captured (via deref) at the point where it appears in the form. It's a bit of a complex topic, but this blog post I wrote a few months ago may help a

Re: recursive bindings not available in let form?

2016-12-03 Thread Timothy Baldridge
The question of how vars work comes up enough that I recently wrote a blog post on the subject. Maybe it will be useful to you. http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots Timothy On Fri, Dec 2, 2016 at 2:44 PM Paul Gowder wrote: > Thanks Bo

Re: recursive bindings not available in let form?

2016-12-04 Thread Timothy Baldridge
Let bindings map pretty much directly to Java style local variables: (let [x 42] (let [x 3] (+ x 3)) Becomes something like this when compiled to byte code: x_1 = 42 x_2 = 3 return x_2 +3 So let bindings with the same names are kept separate via modifying the stored name in the byte code,

[ANN] Odin 0.2.0 - Query DSL for Clojure

2016-12-10 Thread Timothy Baldridge
I just released the first official version of Odin ( https://github.com/halgari/odin). Odin is a declarative, extensible query DSL for Clojure that leverages transducers to provide a high amount of generality while still maintaining acceptable performance. One of the biggest features of Odin is it

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Timothy Baldridge
I'm not aware of such a construct, but it's trivial enough to write something like this using `range` or perhaps write a function that will yield a lazy seq: (defn inf-list ([x y] (cons x (cons y (inf-list x y 2 ([x y c] (cons (+ x (* c (- y x))) (lazy-seq (inf-list x y (inc

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Timothy Baldridge
Ah! I knew there was a way to do it via iterate, but it was 9:30pm at the time and I was tired. Nice example though. On Tue, Dec 13, 2016 at 10:03 PM, Ghadi Shayban wrote: > A common way to do it in Clojure is `iterate`, no macros necessary. As of > Clojure 1.7 this doesn't allocate a list at al

Re: What is the correct way to use 'into'?

2016-12-17 Thread Timothy Baldridge
did a tutorial video on into you may also find interesting: https://www.youtube.com/watch?v=5_eRZRIuqiY Timothy Baldridge On Sat, Dec 17, 2016 at 11:22 AM, larry google groups < lawrencecloj...@gmail.com> wrote: > I was trying to combine 2 maps into a new map, as you can see here. I > pr

Re: Order preservation and duplicate removal policy in `distinct`

2016-12-28 Thread Timothy Baldridge
This is one of those odd questions where the answer of what "could" happen and what "will most likely happen" are completely different. There is no reason why `distinct` should reorder or which item will be preserved. However there's really only one logical way to implement this (the way it's curre

Re: Cyclic namespace dependencies!

2016-12-30 Thread Timothy Baldridge
I've been programming Clojure for something like 6 years now, and yes, I've hit the cyclic dependency error a few times. How did I solve it? Each time via abstraction, and parameterization of functions. Most of the time this means writing a "interfaces.clj" file that contains all my defprotocols an

Re: Cyclic namespace dependencies!

2016-12-30 Thread Timothy Baldridge
exity addition to the compiler and the redefinition of compilation units. The declare method seems like the cleaner route. On Fri, Dec 30, 2016 at 5:45 PM, Mark Engelberg wrote: > On Fri, Dec 30, 2016 at 4:38 PM, Timothy Baldridge > wrote: > >> >> So the layout looks like

Re: Cyclic namespace dependencies!

2016-12-31 Thread Timothy Baldridge
x27;t designed to do what Potemkin tries to make it do when it comes to vars. I really recommend against using the library. On Sat, Dec 31, 2016 at 7:32 AM, squeegee wrote: > > > On Friday, December 30, 2016 at 8:59:46 PM UTC-5, puzzler wrote: >> >> On Fri, Dec 30, 2016 at

Re: Literal map keys are checked for duplication before evaluation?

2017-01-04 Thread Timothy Baldridge
The check is made at read-time, by the time to form gets to the compiler it's already a hash-map and one of your forms will have been dropped. So the decision was made to make the reader check. One way you could solve your problem here is with tagged literals, as the literal would be created, and t

Re: structuring parallel code

2017-01-30 Thread Timothy Baldridge
Instead of looking at the state as a ref with a vector in it, think of it as a vector of refs. That then allows multiple refs to be modified at once without stepping on other unrelated refs. On Mon, Jan 30, 2017 at 5:26 PM, Brian Craft wrote: > I'm experimenting with ref, dosync, and alter to ru

Re: structuring parallel code

2017-01-30 Thread Timothy Baldridge
As you mentioned, what you're battling right now is contention. In your existing code the threads always conflict. No matter what, only one thread's update can succeed, the others will fail and have to re-run. With the refs-in-a-vector approach as long as two threads don't touch the same cell (ref)

Re: structuring parallel code

2017-01-30 Thread Timothy Baldridge
Please define "scales badly" what are you measuring to reach that conclusion? On Mon, Jan 30, 2017 at 7:38 PM, Brian Craft wrote: > ans: this scales badly. > > There must be a way in clojure to operate on large data structures in > parallel, no? > > > On Monday, January 30, 2017 at 6:03:39 PM UT

Re: structuring parallel code

2017-01-30 Thread Timothy Baldridge
We really need more information if you're expecting us to offer any help at all. How many items are you updating, what are your update patterns, what is in these refs, are do you need to modify more than one ref in a single "transaction". All this impacts the correct approach. But with such a lack

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Timothy Baldridge
A good editor should auto-complete your keywords for you. Since using this feature in Cursive (same sort of thing is available in other editors) the cases where I've mis-spelled a keyword have dropped dramatically. It's a lot harder to mis-spell a keyword when you can just do: :egg/th and the rest

Re: Contribute Specter to Clojure core?

2017-02-14 Thread Timothy Baldridge
While I've looked at Specter several times, I have yet to use it in a project for many of the same reasons that Rangel mentioned. Either my data is shallow enough that clojure.core functions work just fine, or my data is complex enough that I need cross-entity joins, and arbitrary clojure logic. In

Re: Is this a bug that is already fixed?

2017-02-19 Thread Timothy Baldridge
That's a pretty old version of ClojureScript. Try upgrading to the latest. Timothy On Sun, Feb 19, 2017 at 2:17 PM, William la Forge wrote: > I'll note that when I add a second entry to the map, everything is fine: >> >> > {:fix nil :local/contacts-capability contacts-capability} > > -- > You

Re: Prgram uses a lot of swap

2017-02-24 Thread Timothy Baldridge
What are the JVM memory settings set at? And how much physical memory does the box have? Timothy -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are modera

Re: [ANN] Odin 0.2.0 - Query DSL for Clojure

2017-02-24 Thread Timothy Baldridge
idier wrote: > How does this compare to Specter? > > > On Thursday, 23 February 2017 13:34:16 UTC-8, Alan Thompson wrote: > > Just came across this - it looks very cool! > Alan > > On Sat, Dec 10, 2016 at 7:14 AM, Timothy Baldridge > wrote: > > I just re

Re: Contribute Specter to Clojure core?

2017-03-05 Thread Timothy Baldridge
>> Specter is not a DSL. Specter implements a set of terms (navigators) specific to the library that are interpreted by the library (the transform function) to accomplish some task for a specific domain (manipulating data structures). In the same way, `update-in` is a DSL. Both Specter and `updat

Re: go local variable binding

2017-03-15 Thread Timothy Baldridge
Yes, that should work fine, do your tests confirm otherwise? Also if you're not doing a recur there's no reason to use `go-loop` you can just use `go`. On Wed, Mar 15, 2017 at 4:44 PM, Eran Levi wrote: > Hi, > can I bind variables, same as I do for threads, for go routines, to be > local only fo

Re: go local variable binding

2017-03-16 Thread Timothy Baldridge
t in case you expect to write cross-platform code with dynamic bindings. > > > Am 16.03.2017 um 01:01 schrieb Timothy Baldridge: > > Yes, that should work fine, do your tests confirm otherwise? Also if > > you're not doing a recur there's no reason to use `go-loop` you

Re: was Re: ANN: Orchestra, complete instrumentation for clojure.spec

2017-04-06 Thread Timothy Baldridge
The power offered by spec is probably better compared against dependent type systems like Idris. True static type systems run analysis at compile-time, but spec allows you to perform very complex checks because you have the power of full blown language. For example, with spec you can write a funct

Re: Using transducers in a new transducing context

2017-04-09 Thread Timothy Baldridge
The volatile! is needed for the case where a transducer is only used by one thread at a time, but the thread executing the transducer may change from one call to the next. This happens fairly often with core.async. If you used a non-atomic, non-volatile mutable field, the JVM would be free to perfo

Re: Using transducers in a new transducing context

2017-04-09 Thread Timothy Baldridge
Transducers were never designed to work in parallel context. So I'd define any behavior that arises from using the same transducers in multiple threads *at the same time*, as undefined behavior. On Sun, Apr 9, 2017 at 4:39 PM, Alexander Gunnarson < alexandergunnar...@gmail.com> wrote: > I should

Re: Using transducers in a new transducing context

2017-04-09 Thread Timothy Baldridge
In your example transducer, the problem is with the `result` parameter. The specification of transducers is that the result of `(rf result x)` should be fed into the next call to `rf`. In other words: (-> result (rf x1) (rf x2) (rf x3))` trying to do that in a parallel context is next to impossible

Re: Derefs broken after clojure.tools.namespace.repl/refresh

2017-04-10 Thread Timothy Baldridge
You're reloading your namespaces from a non-repl thread, concurrently while editing code in the repl. I don't think this is use case is supported by tools.namespace. On Mon, Apr 10, 2017 at 2:56 PM, Didier wrote: > Hum, not sure why you would do this, but I'm guessing refresh goes in an > infini

Re: Derefs broken after clojure.tools.namespace.repl/refresh

2017-04-11 Thread Timothy Baldridge
Cursive has had a really good debugger for a long time. I don't use it much, but when I need it it *just works*. Timothy On Tue, Apr 11, 2017 at 7:37 PM, Didier wrote: > A good debugger is indeed extremely useful for Clojure - I use one every >> day :-) >> > > Am I living in the past? I thought

Re: Faster diffing for large-ish nested data structures

2017-04-19 Thread Timothy Baldridge
I've gotten really fast diffing in Clojure by using the following concepts: 1) If you can sometimes make parts of A and B be identical, then your differ can skip checking those parts by doing a (identical? A B), this improves performance 2) Take a side effecting approach, pass into the differ a fu

Re: Faster diffing for large-ish nested data structures

2017-04-22 Thread Timothy Baldridge
Can Specter walk two sequences in lock-step? That's what's needed for a good diffing engine, and that seems quite far removed from Specter's design. On Fri, Apr 21, 2017 at 11:22 PM, Mars0i wrote: > This might be a job for which Specter is particularly useful. You might > have to dive pretty de

Re: How to Create Clojure `defn` Functions automatically?

2017-05-11 Thread Timothy Baldridge
This is a somewhat weird answer to a overcomplicated problem. As mentioned, the data is a map to start with, and maps are functions so treating the maps as data is probably the best approach. And like Dragan, I'm unsure why this example doesn't use `(data :able)`. When I do need to generate functi

Re: How to Create Clojure `defn` Functions automatically?

2017-05-11 Thread Timothy Baldridge
Thu, May 11, 2017 at 9:18 AM, Alan Thompson wrote: > >> I like the idea of using `eval` and `memoize`. I'll have to keep that >> in mind. >> Alan >> >> On Thu, May 11, 2017 at 7:58 AM, Timothy Baldridge >> wrote: >> >>> This is a som

Re: In search of the little transducer

2017-05-12 Thread Timothy Baldridge
Sure, you can contact me at the address used in this reply :) Timothy Baldridge On Fri, May 12, 2017 at 11:19 AM, Erlis Vidal wrote: > Is there a way I can contact Tim Baldridge for questions about the > subscription? > > Thanks! > > On Sun, Jan 31, 2016 at 12:40 PM, Mars0i

Re: class and case

2017-05-13 Thread Timothy Baldridge
Using a protocol is probably the optimal choice, since it also opens up the dispatch allowing for extension without modifying exiting code. Downstream users of your library can add extensions to your code without having to create a patch. On Sat, May 13, 2017 at 7:43 AM, Alex Miller wrote: > O

Re: How to Create Clojure `defn` Functions automatically?

2017-05-13 Thread Timothy Baldridge
el Spolsky, creator of StackOverflow, has often >> encouraged people to post both a question and its answer on the site: >> https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-ans >> wer-your-own-questions In fact, they even have a special button for >> this purpo

Re: How to Create Clojure `defn` Functions automatically?

2017-05-13 Thread Timothy Baldridge
-to-generate-functions> > was incomplete for the new question and I was trying to fill in the missing > parts. > > > > On Sat, May 13, 2017 at 3:40 PM, Timothy Baldridge > wrote: > >> Sorry, but this use of intern is a pointless. What does intern give you &g

Re: slackpocalypse?

2017-05-18 Thread Timothy Baldridge
It's not working for me. I'm in the US, connecting via Chrome. On Thu, May 18, 2017 at 2:40 PM, Dragan Djuric wrote: > It works for me as always. > > On Thursday, May 18, 2017 at 10:34:33 PM UTC+2, Gregg Reynolds wrote: >> >> >> >> On May 18, 2017 3:32 PM, "Jason Stewart" wrote: >> >> I'm exper

Re: slackpocalypse?

2017-05-18 Thread Timothy Baldridge
You know, there's this awesome bit of tech called IRC...someone should check that out. On Thu, May 18, 2017 at 3:31 PM, Gregg Reynolds wrote: > looks like access is restored, for me at least. still, slack is making me > a little nervous. and that's in addition to the 10K msg limit, which is a >

Re: [ANN] Chestnut 0.15.0

2017-05-29 Thread Timothy Baldridge
Might be good to provide a quick overview of what Chestnut is. It's been a year, so I either missed the last announcement, or have forgotten in that time. Also I see a link that would take me to the project page. On Mon, May 29, 2017 at 5:03 AM, Arne Brasseur wrote: > After almost a year I'm ple

Re: New guide: Reading Clojure Characters

2017-06-17 Thread Timothy Baldridge
Anonymous implies there might be some sort of auto gen going on (as there is with anonymous functions), Irrelevant has my vote therefore. The other characteristics are a side-effect of it being a naming convention (with no official support by the compiler). Maybe that could be pointed out in greate

Re: core.async/close! locks on chans with pending transforms

2017-07-03 Thread Timothy Baldridge
Transducers on channels lock the channel while they are running. This is by design. So yes, the side-effect of this means that no other operation (puts, takes or closes) can succeed while the transducer is running. So the short answer is: If you have code that can take awhile to run, don't put it

Re: core.async/close! locks on chans with pending transforms

2017-07-03 Thread Timothy Baldridge
A big reason they have to be run inside the lock is that they have to operate in the context of the channel. For example: (chan (take 10)) Firstly we must recognize that transducer instances are *not* thread safe. They should only ever be executed by one thread at a time. But channels allow mult

Re: core.async vs continuations

2017-07-10 Thread Timothy Baldridge
Yes, calls to ! could be written with continuations, or call/cc, but they are not implemented that way. Instead the code inside the body of the `go` macro is rewritten into a statemachine. This sort of rewrite is a lot like the rewrites that C# does for yield, and Cython does much of the same sort

Re: Been away a while

2017-07-14 Thread Timothy Baldridge
I recommend starting with this excellent talk, if you haven't already seen it: https://www.youtube.com/watch?v=qDNPQo9UmJA Aside from that I recommend taking a look at Pedestal. It's async and streaming capabilities are some of the most advanced you can find in the Clojure space, and its protocols

Re: Modern opengl bindings in clojure

2017-07-14 Thread Timothy Baldridge
Are the docs out of sync? Because the README talks about immutable APIs and seq to array conversions, but the library itself is just a renaming wrapper mapping stuff like GL/GLVertex to gl-vertex. I don't understand how that makes the API "modern". Unless that part isn't written yet. Timothy On F

Re: How to eval one "step" of a form?

2017-07-20 Thread Timothy Baldridge
The answer lies in the term "REPL". You start by reading the string, you can use `clojure.core/read-string` for this case. This will convert your string into Clojure data: "(+ 1 (* 2 2))" => (+ 1 (* 2 2)) That's the "R" part of "REPL", read. Next step is "E" for "eval". We need to evaluate the s

Re: Should the completion arity of a stateful transducer reset state?

2017-07-22 Thread Timothy Baldridge
Once a transducer is completed it should never be called again. This is why transduce takes both a transducer and a reducing function and combines them internally. The thought here is that it will be harder to shoot yourself in the foot by reusing a stateful reducing function if you don't have to c

Re: How is this code to create a stateful lazy sequence?

2017-07-22 Thread Timothy Baldridge
If we think about what we're doing here is a stateful filter, then maybe we could leverage a few more core Clojure functions: (defn distinct-by [f coll] (let [seen (atom #{})] (filter (fn [itm] (let [m (f itm)] (when-not (@seen m) (swap!

Re: CHAMP an improvement on HAMT?

2017-08-14 Thread Timothy Baldridge
It came up today in the Clojurian's Slack mailing list, and it sounds like the gist is that the papers did a bit of a apples-to-oranges comparison by using a different hashing algorithm when comparing CHAMP to Clojure's hashmaps. Once this difference is rectified the performance improvements are mu

Re: Is Clojure victim of Spec ?

2017-08-18 Thread Timothy Baldridge
Relevant discussion: https://groups.google.com/d/msg/clojure/10dbF7w2IQo/ec37TzP5AQAJ On Fri, Aug 18, 2017 at 10:53 AM, Rafik NACCACHE wrote: > Hey guys, > > Seems to be a long while we are waiting for 1.9 > > I kinda feel that core.spec seems to always need more polishing so that's > why it's s

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
I find the arguments for variants very unconvincing. As you stated with specs and s/keys you can spec the same sort of data, and in a way that's much more open-ended. For example: [:person {:name "Tim" :grade "B"}] What is the type of this data? We would probably guess a :person. But what if we

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
ever want variants. They complicate the code for really no benefit. The complexity they are attempting to solve can be solved by simply using maps and records instead of bare values. On Tue, Aug 22, 2017 at 5:43 PM, James Reeves wrote: > On 22 August 2017 at 23:04, Timothy Baldridge >

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
I think the article is a bit misleading. Variants were never that popular in Clojure. Infact I've never seen them used in production code or the most common Clojure libraries. So I'm a bit perplexed as to why the article recommends them so strongly. So I think the answer is, they are a fun thought

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
Nope, ClojureScript uses nested hash maps (try it for yourself here: http://vps124502.vps.ovh.ca/rage/resources/public/). As does tools.analyer. Instaparse and Hiccup use a variant of variants, but funny enough the first thing I ever do when writing code with instaparse is write a converter from it

Re: Sum types in Clojure? Better to represent as tagged records or asvariant vectors?

2017-08-22 Thread Timothy Baldridge
) 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: *Timothy Baldridge > *Sent: *Tuesday, August 22, 2017 6:00 PM > *To: *c

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
draw :4s nil]. You can mistake the order: [:event/draw :player1 > :4s]. > > I think to represent the type of a single element, I agree with you, but > if you've got a compound type, at first glance, they'd appear less > practical and more error prone to me. So your second exa

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
But Datomic has E in [e a v] which links multiple [a v] pairs into an entity...which is basically a map. So I don't think that applies here. GET /example HTTP/1.1 Host: www.example.com [:request/method :get] [:request/uri "/example"] [:request/protocol "HTTP/1.1"] [:request/header ["h

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-22 Thread Timothy Baldridge
p. On Tue, Aug 22, 2017 at 9:43 PM, James Reeves wrote: > On 23 August 2017 at 03:58, Timothy Baldridge > wrote: > >> Put let's take that and look at it under a engineering lens a bit: >> >> >> For example, a series of events that represent a player's m

Re: CPU & platform for best compilation performance

2017-08-23 Thread Timothy Baldridge
"My codebase (mix of CLJ, CLJS and CLJS) is about fifty thousand lines of code, and compilation times are starting to interfere with my workflow happiness. In addition, Chrome Devtools is becoming somewhat sluggish due to the high number of separate namespaces loaded through Figwheel." That's not

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-25 Thread Timothy Baldridge
>> they're a little nicer to type and read And that's where I have to disagree. The problem with most of these options is they complect ordering with meaning. [:image/file "/images/image" :jpeg] Here I have no idea what these values mean. I have to have out-of-band information about what offset

Re: Sum types in Clojure? Better to represent as tagged records or as variant vectors?

2017-08-28 Thread Timothy Baldridge
>> https://github.com/arrdem/guten-tag The name alone deserves a +1. :D On Mon, Aug 28, 2017 at 2:53 PM, Reid McKenzie wrote: > FWIW I wrote a library around defining tagged map types > https://github.com/arrdem/guten-tag and used it heavily in the Grimoire > implementation almost entirely to

Re: core.async got in a bad state?

2017-08-29 Thread Timothy Baldridge
To add to what Alex said, look at this trace: https://gist.github.com/anonymous/65049ffdd37d43df8f23630928e8fed0#file-thread-dump-out-L1337-L1372 Here we see a go block calling mapcat, and inside the inner map something is calling >!!. As Alex mentioned this can be a source of deadlocks. No code c

Re: SRSLY? (= (true? identity) (false? identity)) => true

2017-09-01 Thread Timothy Baldridge
Think about what you're asking: "Hey, is identity a boolean true value?" "No, it is a function, not a boolean" "Is, identity a boolean false value?" "No, it's a function, not a boolean" Makes plenty sense to me. On Fri, Sep 1, 2017 at 10:06 PM, Rostislav Svoboda < rostislav.svob...@gmail.c

Re: Using memory with futures

2017-09-05 Thread Timothy Baldridge
Every thread created on the JVM takes about 2MB of memory. Multiply that by that number of threads, and I'm surprised your memory usage is that low. But the futures thread pool will also re-use previously created threads for new futures. In order to optimize this, a certain number of threads will b

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

2017-10-08 Thread Timothy Baldridge
I don't think you can catch an Object on the JVM can you? What happens if you catch Throwable? On Sun, Oct 8, 2017 at 9:43 PM, wrote: > So, for instance, this says that 10 documents were retried: > > {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 10, > :completed 378, :in

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

2017-10-08 Thread Timothy Baldridge
What REPL are you using? A rather nasty side-effect of NRepl is that it tends to send messages from non-main-threads to weird places. On Sun, Oct 8, 2017 at 10:29 PM, wrote: > I just re-wrote much of the code to run on the main thread. And so now I > can see the error message (which was about a

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

2017-10-09 Thread Timothy Baldridge
The problem isn't the macro, it's your use of syntax quoting. `(= x y) gets expanded at read-time into `(clojure.core/= x y)`. Not much you can do about that. Although I'd suggest perhaps changing your code a bit to not require macros. deftest mostly just creates a defn with some extra metadata an

Re: Updating repeated nested structures?

2017-10-10 Thread Timothy Baldridge
My answer to most of these questions is often "write it once, stuff it in a function, and forget about it". Really though I often see this as a data-modeling and naming problem. For example, you could go and write a `(update-cells cell-list f & args)` that wraps custom logic for finding and manipu

Re: About determinism of async

2017-10-11 Thread Timothy Baldridge
If you want to simply keep some messages in order, then a cat transducer will do the trick just fine: ;; need a buffer or buffer size to get to the transducer param (def c (chan 20 cat)) (async/onto-chan c [1]) (async/>!! c [2 3 4]) (async/close! c) ( wrote: > If you don't want to split at th

Re: beginners' puzzle

2017-10-11 Thread Timothy Baldridge
Best answer for that is probably the source code itself: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java On Wed, Oct 11, 2017 at 9:07 AM, wrote: > how these keywords in clojure implemented > could anyone anwer me ? > > -- > You received this message because you

Re: What's up with IMeta?

2017-11-01 Thread Timothy Baldridge
To start with, IObj and its .meta method are used with clojure.core/meta to get the metadata on an object. Since this method can be the same between refs and immutable data, they all use the same interface. IMeta is used with withMeta and clojure.core/with-meta to return a new object with the give

Re: Who Uses import-vars?

2017-11-07 Thread Timothy Baldridge
I structure my code very explicitly. Normally the most common constructs are put in a single file named after the library itself (not in core.clj, do that half your files will be named core). https://github.com/halgari/odin/blob/master/src/com/tbaldridge/odin.clj Anything not in the API that shou

Re: Dynamically Reify Interfaces

2017-11-08 Thread Timothy Baldridge
Eval gets a bad reputation from languages like JS where it's messy and a bit of a security risk. In Clojure, there's nothing wrong with using eval for something like this. On Tue, Nov 7, 2017 at 11:43 PM, Nick Mudge wrote: > I need to dynamically reify some java interfaces based on data from a >

<    1   2   3   4   5   6   7   8   9   >