Re: Optimizaton for finding the next key in a sorted-map

2020-05-25 Thread Carlo Zancanaro
Hey Harmon, On Tue, May 26 2020, Harmon Nine wrote: > Does such an optimization exist? If not, is there an means of getting the > next-key in a sorted-map given a current-key that is better than O(n)? I just had a look at clojure.core and found that subseq operates on a sorted collection.

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

2019-11-22 Thread Carlo Zancanaro
Hey Dimitris, I think what you're running into here is a fundamental misunderstanding of protocols. Specifically, this is not true: As I understand it, protocol extensions are namespace-specific. In Clojure, protocol extensions are global. If you extend a protocol for a type then it

Re: mu4e:view show email address after display name in message headers

2018-09-24 Thread Carlo Zancanaro
Hey Jeff, On Tue, Sep 25 2018, Jeff Kowalczyk wrote: I would like to configure mu4e:view to display the email address along with the display name in the To: From: Cc: Bcc: etc fields. This is definitely the wrong list, but given how easy it is to do this, I thought I'd help you out.

Re: IF, WHEN or SOME

2018-09-20 Thread Carlo Zancanaro
Hey Stephen, On Fri, Sep 21 2018, Stephen Feyrer wrote: user=> (def some-numbers ‘(2 4 6 8)) #This is my value to test later. #’user/some-numbers At this point we have some-numbers = '(2 4 6 8) user=> (def evens? (partial (when (apply = (map even? some-numbers) #’user/evens? Let's

Re: Why does interruptible-eval from tools.nrepl queue evaluations?

2018-05-03 Thread Carlo Zancanaro
On Thu, May 03 2018, Gary Fredericks wrote: Separately, I use this macro for running background things in the repl. It probably targets different concerns, but seems related at least. My use case is quite different. Requiring someone to decide

Re: Why does interruptible-eval from tools.nrepl queue evaluations?

2018-05-03 Thread Carlo Zancanaro
Apologies, I forgot to cc the list. On Thu, May 03 2018, Gary Fredericks wrote: You would also have race conditions on the meaning of *1, *2, *3, and *e. On Thu, May 3, 2018 at 5:43 AM, Carlo Zancanaro <carlozancan...@gmail.com> wrote: >But what happens when a user se

Re: Why does interruptible-eval from tools.nrepl queue evaluations?

2018-05-02 Thread Carlo Zancanaro
>I think dynamic vars in particular would be problematic. The repl is built >around being able to set! certain vars, and you can't do that to the same >binding from multiple threads. The dynamic thread bindings are established within the function passed to queue-eval, though, so it seems

Why does interruptible-eval from tools.nrepl queue evaluations?

2018-05-02 Thread Carlo Zancanaro
Hey there! With tools.nrepl, if you eval two expressions they get queued up and evaluated in sequence. This means that if I evaluate (Thread/sleep 1), and then immediately evaluate (+ 1 2), then I have to wait ten seconds for the result of 3 to come back. Is there a particular reason

[ANN] dont-give-up 0.1.0: Common Lisp style restarts in Clojure

2018-04-14 Thread Carlo Zancanaro
Hey! Last week I sent an email announcing some code that I've been working on to bring Common Lisp style restarts to Clojure. I just released the first version! You can see it at https://github.com/czan/dont-give-up. More interestingly, though, I also have a working CIDER interface for

[ANN] dont-give-up: Common Lisp style restarts

2018-04-05 Thread Carlo Zancanaro
Hey! I've been playing around a little bit with Common Lisp lately, and I've found the interactive restarts to be pretty amazing. So, I've implemented something similar to them in Clojure/Cider! https://github.com/czan/dont-give-up It has support for programmatic restarts, but also

Re: What if ^:const could inline everything before macroexpanssion?

2018-03-15 Thread Carlo Zancanaro
On Thu, Mar 15 2018, Didier wrote: I feel it would be really cool to be able to factor some input to macros into constants, is this something I could open a ticket for, to extend ^:const so it can inline all literal values and also does the inlining before macroexpanssion so that the above

[ANN] stateful-check 0.4.0 - test stateful systems with test.check

2018-02-12 Thread Carlo Zancanaro
Hey everyone! I've just released a new version of my library for testing stateful systems with test.check! Now with added race condition detection! [org.clojars.czan/stateful-check "0.4.0"] https://github.com/czan/stateful-check https://clojars.org/org.clojars.czan/stateful-check This

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

2017-01-04 Thread Carlo Zancanaro
On Thu, Jan 05 2017, Tianxiang Xiong wrote > We can have: > > user=> {(+ 1 2) 1 (+ 2 1) 2} > IllegalArgumentException Duplicate key: 3 > clojure.lang.PersistentArrayMap.createWithCheck > (PersistentArrayMap.java:71) > > > So clearly a check is also made *after* evaluating the key forms. I'm

Re: How to email PDF attachments

2015-09-24 Thread Carlo Zancanaro
I don't know anything about your PDF/email problem, but I was under the impression that you could use the local filesystem in Heroku, but that you can't rely on it for persistance. https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem So, if you had a solution that was "write to disk,

Re: Unexpected behavior for symbols or keywords used in the operator position

2015-09-15 Thread Carlo Zancanaro
Symbols and keywords act as functions which look themselves up in their argument. Essentially: ('sym map) => (get map 'sym) ('sym map not-found) => (get map 'sym not-found) (:key map) => (get map :key) (:key map not-found) => (get map :key not-found) It's often pretty useful, in my

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Carlo Zancanaro
Hey Mayank! Similarly to your attempt last time, you need to use gen/bind to get the result of a generator which you can then use to make a new generator. (defn- rand-interleave* [coll acc] (if (seq coll) (gen/bind (gen/choose 0 (dec (count coll))) (fn [index]

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Carlo Zancanaro
have used a gen/return at the end of the generator? Thanks again for your help! :) On Fri, Aug 14, 2015 at 8:13 PM, Carlo Zancanaro carlozancan...@gmail.com wrote: Hey Mayank! Similarly to your attempt last time, you need to use gen/bind to get the result of a generator which you can

[ANN] stateful-check 0.3.1 - test stateful systems with test.check

2015-08-13 Thread Carlo Zancanaro
Hey everyone! I've just released a new version of my library for testing stateful systems with test.check! [org.clojars.czan/stateful-check 0.3.1] https://github.com/czan/stateful-check https://clojars.org/org.clojars.czan/stateful-check Changes in this version: + :real/setup and

[ANN] stateful-check 0.3.0 - test stateful systems with test.check

2015-07-30 Thread Carlo Zancanaro
Hey everyone! I've just released a new version of my library for testing stateful systems with test.check! [org.clojars.czan/stateful-check 0.3.0] https://github.com/czan/stateful-check https://clojars.org/org.clojars.czan/stateful-check Important changes in this version: + Updated to

Re: Generating varying sized map using test.check

2015-07-27 Thread Carlo Zancanaro
Whoops, forgot the group on this. On 27 July 2015 at 18:10, Carlo Zancanaro carlozancan...@gmail.com wrote: You're generating two random things: the map, and the subset of the keys. You can't generate the subset of the keys without first knowing the full set of keys, so bind lets you make

Re: Generating varying sized map using test.check

2015-07-25 Thread Carlo Zancanaro
Hey Mayank! What you've done here might appear to work, but it will get you into trouble when test.check starts to shrink your inputs. When test.check runs your generators it relies you you using it as your only source of randomness, and so your use of `rand-int` will cause some problems. The

Re: core.match: order of patterns

2015-01-29 Thread Carlo Zancanaro
On Thu, Jan 29, 2015 at 10:46:45AM +, László Török wrote: One thing that isn't obvious to me, how it should work when matching more than one pattern. I can't seem to find it anywhere in the core.match wiki, but I'm fairly sure it tries them in order, returning the first one that matches.

Re: [ANN] stateful-check 0.1.0 - test stateful systems with test.check

2014-12-02 Thread Carlo Zancanaro
On Sat, Nov 29, 2014 at 11:34:37AM -0800, tcrayford wrote: Nice! I wrote a sketch of this idea the day after I watched the talk: https://github.com/tcrayford/laundromat, but never pursued it much further (though I do use it in my test suite). Thanks for laundromat. I shamelessly stole the

[ANN] stateful-check 0.2.0 - test stateful systems with test.check

2014-12-02 Thread Carlo Zancanaro
On Fri, Nov 28, 2014 at 11:43:56AM +1100, Carlo Zancanaro wrote: I've been working on a library for a little bit which I'm calling stateful-check (at least for now). It's mainly my attempt to work towards the sort of stateful testing that I first saw in John Hughes' talk Testing the Hard Stuff

Re: [ANN] stateful-check 0.1.0 - test stateful systems with test.check

2014-11-28 Thread Carlo Zancanaro
Hey Jan! On Fri, Nov 28, 2014 at 06:37:06AM -0800, Jan Stępień wrote: Thanks for sharing! I see that generative testing of statful computations is a popular topic in the Clojure world these days; Yeah, it certainly seems to be that way. I was re-invigorated to work on stateful-check after

[ANN] stateful-check 0.1.0 - test stateful systems with test.check

2014-11-27 Thread Carlo Zancanaro
I've been working on a library for a little bit which I'm calling stateful-check (at least for now). It's mainly my attempt to work towards the sort of stateful testing that I first saw in John Hughes' talk Testing the Hard Stuff and Staying Sane[1]. https://github.com/czan/stateful-check

Re: Cyclic Agents

2014-09-11 Thread Carlo Zancanaro
Hey Greg, On Thu, Sep 11, 2014 at 12:30:11AM -0700, Greg MacDonald wrote: So how come two agents can't contain one another? The following code causes a StackOverflowError. In the real world things can't contain other things cyclically so I suspect that's why, but if someone could explain

Re: how to define a variable of type collection to keep other functions.

2014-05-28 Thread Carlo Zancanaro
On Wed, May 28, 2014 at 12:56:43AM -0700, sorin cristea wrote: *( defn some-method[arg] (def thred (. Thread currentThred) (println on current thread thread use variable arg))* 'thred' - is only visible inside of some-methd, because is a little confuse for me your statement -

Re: emacs - some output goes to stdout when using cider

2014-05-26 Thread Carlo Zancanaro
On Mon, May 26, 2014 at 08:32:45AM -0700, Don Hill wrote: I am in a project with a test.clj file and if I do a (println Hi) C-x C-e it goes to repl as expected. If I do something like (+ 1 2 3) it seems to go to stdout below the status bar. This is the correct behaviour. When you evaluate

Re: passing a non-anoymous function as an argument to another clojure function

2014-05-22 Thread Carlo Zancanaro
On Wed, May 21, 2014 at 07:53:18PM -0700, David Gartner wrote: (defn div [x y] (/ x y)) (defn throw-catch [f] [(try (f) (catch ArithmeticException e No dividing by zero!) (catch Exception e (str You are so bad (.getMessage e))) (finally (println returning... )))])

Re: (eval `(def ~(symbol varname) lineseq)

2014-04-28 Thread Carlo Zancanaro
On Mon, Apr 28, 2014 at 06:06:32PM +1000, Peter B. West wrote: This is the technique used in the old contrib/io.clj read-lines function, isn't it? That's handy to know. Correct. Still, Stuart is skeptical about it. I don't think it's a good general solution to the problem, so Stuart's

Re: (eval `(def ~(symbol varname) lineseq)

2014-04-27 Thread Carlo Zancanaro
I'm struggling to understand the problem that you're actually trying to solve. The solution that you are proposing doesn't seem like an elegant solution to any problem, so could you elaborate on what you're trying to do? On Fri, Apr 25, 2014 at 08:58:42AM -0700, Peter West wrote: One interesting

Re: (eval `(def ~(symbol varname) lineseq)

2014-04-27 Thread Carlo Zancanaro
On Mon, Apr 28, 2014 at 12:30:00AM +1000, Peter B. West wrote: I have no ambitions to solve the general problem; just to find a workable solution for my own use. What is your own use? Your current solution involves using a shared global variable to communicate between two functions, and tying

Re: (eval `(def ~(symbol varname) lineseq)

2014-04-08 Thread Carlo Zancanaro
On Mon, Apr 07, 2014 at 11:23:31PM -0700, Peter West wrote: On Tuesday, 8 April 2014 12:20:16 UTC+10, Carlo wrote: Your issue here is that the symbol lineseq in the eval form doesn't have a name to refer to. You do have a local binding for lineseq, but it's not visible to the eval:

Re: (eval `(def ~(symbol varname) lineseq)

2014-04-07 Thread Carlo Zancanaro
On Mon, Apr 07, 2014 at 04:08:03AM -0700, Peter West wrote: I'm trying to understand the difference between two alternatives in the following code that reads from a resource file. (defn vcf-res-reader [res] (- res io/resource io/reader)) (defn lines-only [varname

Re: let bindings

2014-01-20 Thread Carlo Zancanaro
Hey Andy! On Mon, Jan 20, 2014 at 12:38:23PM -0800, Andy Smith wrote: So if we can always reformulate in this was, why cant let be implemented as a macro rather than a special form? It can. Quite easily, in fact: (defmacro my-let [bindings body] (if (empty? bindings) `(do ~@body)

Re: map vs map in core.async

2013-12-12 Thread Carlo Zancanaro
On Thu, Dec 12, 2013 at 06:08:11PM -0800, Joachim De Beule wrote: I expected to see a sequence of the form However, only one or very few get printed, so I get a sequence Why? They're getting buffered. Try this: (as/pipe (as/map (fn [x] (print ) (flush) x) source)

Re: Working with zippers and trees

2013-11-26 Thread Carlo Zancanaro
On Tue, Nov 26, 2013 at 08:30:15PM -0800, martin_clausen wrote: To use the zipper library you have to be able to provide branch? children and make-node functions that apply to your data structure. I don't see a way to provide a meaningful branch? or children function for the structure you

Re: Working with zippers and trees

2013-11-26 Thread Carlo Zancanaro
Okay, now after actually reading the documentation I can come back with an actually correct response! You should only have to change one function: (defn make-node [n children] (vec (cons (first n) children))) Your issue was that your original `make-node` function didn't return a

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-11-20 Thread Carlo Zancanaro
Hi Mark! On Wed, Nov 20, 2013 at 01:11:11PM -0800, Mark wrote: I'm using the 2.0 snapshot. How should I express a join on multiple columns, ie SELECT blah FROM t1 JOIN t2 ON (t1.a=t2.b) AND (t1.c=t2.d) ? Something like this should work: (let [t1 (- (table :t1) (project

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-09-18 Thread Carlo Zancanaro
On Wed, Sep 18, 2013 at 09:27:22AM -0700, Daniel Neal wrote: One other difference I did notice with clojureql is that in clojureql the database/connection is part of the query definition `(table db :users)`, where as in clojure-sql the database/connection is a separate thing. This seemed

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-09-17 Thread Carlo Zancanaro
On Tue, Sep 17, 2013 at 02:28:08AM -0700, Daniel Neal wrote: I'd be interested in knowing some more about your approach compared to that of ClojureQL and the motivation behind it. Sure! The basic difference is that I tried to be a little bit more rigid in how queries must be constructed. I

Re: Can I refer all but specified symbols with 'ns' macro?

2013-08-01 Thread Carlo Zancanaro
I think the way to do it is: (ns foo (:require [bar :refer :all :exclude (quux)])) On 1 August 2013 18:19, Yoshinori Kohyama yykohy...@gmail.com wrote: Hi group. Assumed that I want to refer 'baz, 'qux and etc and don't want to refer 'quux of 'bar namespace within my 'foo namespace.

Re: Ring: How to auto-redirect URI's missing trailing slash

2013-07-25 Thread Carlo Zancanaro
On 26 July 2013 11:17, Sebastian Rojas sebastian.rojas.viva...@gmail.comwrote: Checkout this middleware in lib-noir https://github.com/noir-clojure/lib-noir/blob/master/src/noir/util/middleware.clj#L70 Unfortunately that middleware only changes the way your handlers see the URI of the

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-07-06 Thread Carlo Zancanaro
This is a fairly restricted composition, though: (def triangles (compose (select [:color :num_sides] (from :shapes)) (where '(= :num_sides 3 (def green-triangles (compose triangles (where '(= :color green (sql green-triangles) ;=

Re: Walking a tree

2013-07-06 Thread Carlo Zancanaro
Give this a go: (defn ^:private walk-tree* [all seen to-do] (when-let [[curr others] to-do] (if (contains? seen curr) (recur all seen others) (lazy-seq (when-let [node (first (filter #(= (:v %) curr) all))] (println node) (cons curr

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-07-05 Thread Carlo Zancanaro
Hey Roman, The issue that I see with `sqlingvo`, and the thing which I was trying to solve for myself, is that it doesn't compose well. Unless I'm missing something, you have to generate the entire query in the one `sql` form. To me, this is a big restriction and was the number one thing I was

Re: [ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-07-05 Thread Carlo Zancanaro
Hey Sean, Most of the points in my reply to Roman also apply to `HoneySQL`. In particular this phrase in the README summarises a good deal of my criticism: When using the vanilla helper functions, new clauses will replace old clauses. You have to go out of your way to get the composability that I

[ANN] clojure-sql 0.1.0: relational algebra in clojure

2013-07-03 Thread Carlo Zancanaro
Hey guys! I've been working on a small library to make writing SQL queries a little bit easier. It's along the same lines as ClojureQL, but takes a different approach and compiles into quite different SQL in the end. At the moment it's quite immature, but it should be able to support any queries

Re: Lazy seq race condition?

2013-06-24 Thread Carlo Zancanaro
On Mon, Jun 24, 2013 at 4:17 PM, Cedric Greevey cgree...@gmail.com wrote: Ah, thanks. The locking granularity is local to the cons cell (or analogue; first/rest pair) being realized, I hope? So one thread actually calculates an element and neither call returns until it's calculated, and then

Re: database wrapper lib

2013-06-21 Thread Carlo Zancanaro
Hey Justin, I'm also working on a wrapper lib for SQL queries (which can optionally use jdbc for performing the queries). At the moment it's pretty new, so it might not actually work for you, but if you want to take a look the code's at https://bitbucket.org/czan/clojure-sql. It's also been

Re: First day with Macros

2013-06-17 Thread Carlo Zancanaro
I can't speak to the issues that Gary raised, but I can help you with your macro. (defmacro servlet [servlet-name meths] `(reify Servlet ~@(for [meth meths] (let [[method-name args body] meth method-name (hyphenated-camel-case method-name)]

Re: binding funkiness

2013-04-22 Thread Carlo Zancanaro
If you want to capture the binding and have laziness together you can also use `bound-fn`. (binding [*funkybind* true] (map (fn [_] *funkybind*) [0 1])) ;= (false false) (binding [*funkybind* true] (map (bound-fn [_] *funkybind*) [0 1])) ;= (true true) On Tue, Apr 23, 2013 at 11:52 AM, Travis

Re: limit keys from client JSON (select-keys but nested?)

2013-01-01 Thread Carlo Zancanaro
2) Is there a good way of doing this with nested maps? An example: { :user { :first John :last Doe :dob { :month 12 :day 30 :year 2012 :garbage asdf } } } I would want to make sure :dob only contains keys :month, :day, :year. I'd write a simple little helper function to do this, if I were

Re: core.match - how to simplify patterns with repeated guards

2012-11-14 Thread Carlo Zancanaro
Hey David, I guess its got something to do with the fact that match itself is a macro? Correct. The match macro just takes the list `(!nil? a)`, which isn't a valid match form, so it complains about it. Is there some other way that I could extend match to only match when the variable is not

Re: function calling itself using a generic self reference call?

2012-08-06 Thread Carlo Zancanaro
1. would it be, or is it possible to have something generic like this? You could use: (def v1 (fn self ([x] (self x [])) ([x r] (conj r x))) 2. What about anonymous fns? The same idea, just without the def. (fn call-self ([x] (call-self x 0)) ([x y] ...))) -- You received this

Re: swap! and atom behavior

2012-07-31 Thread Carlo Zancanaro
1) I assumed that printing out [i @a] instead of [@a i] should realize 'i' first and @a should be correctly displayed as 5. This does not happen, it simply prints [(1 2 3 4 5) 0] if the order is reversed. So, this evaluates in two stages. First the terms `i` and `@a` are evaluated to get

Re: Classpath set by lein swank or clojure-jack-in

2012-06-16 Thread Carlo Zancanaro
On Sat, Jun 16, 2012 at 10:10 AM, Dave Kincaid kincaid.d...@gmail.com wrote: Sure can. Here is the project.clj: (defproject swank-test 0.1   :source-path src/main/clj Are you using lein 1.x or lein 2.x? In lein 2.x you need to use `:source-paths [src/main/clj]` here.   :test-path test/clj  

Re: Strange evaluation result of the quoted form on 1.3

2012-06-07 Thread Carlo Zancanaro
A quoted symbol is just a literal symbol typed object. These symbols act as functions where they evaluate like this: ('x 1) = (get 1 'x) - look itself up in its argument ('x 1 2) = (get 1 'x 2) - look itself up in its argument with a not-found value. So, in your example: (bar '(foo 1 2)) tries

Re: Parallel doseq?

2012-05-25 Thread Carlo Zancanaro
You're doing all your computation in the generation of the lazy sequence (which is in order). Then you're mapping identity in parallel, but that doesn't do anything. If you're willing to lose the for style bindings, try something more like this: (defmacro pdoseq Run over a sequence in parallel