Shot in the dark: check that arguments passed to your memoized functions
use consistent typing. A BigDecimal such as 1M does not necessarily equal 1
(a Long):
(= 1 1M)
false
(== 1 1M)
true
Your memoized functions could be recomputing values unnecessarily if you're
giving them different
You may find this ns cheatsheet helpful:
http://gist.github.com/284277
Justin
On Jan 24, 10:28 am, Manfred Lotz manfred.l...@arcor.de wrote:
Hi all,
I'm stumbling about the very basics.
Calling clojure like this:
rlwrap java
-cp
Check out clojure.contrib.io (Clojure 1.2) or clojure.contrib.duck-
streams (Clojure 1.1):
(use 'clojure.contrib.io)
(defn save-map [f m]
(write-lines f (for [[k v] m] (str k \tab v
Or, using your code...
(defn save-map [f m]
(spit f (apply str (interleave (apply concat m) (cycle
Per Phil Hagelberg's suggestion on IRC, I downloaded and used his
package.el, which fixed the issue for me:
http://github.com/technomancy/package.el/raw/master/package.el
Phil said the bug hasn't been patched upstream.
Justin
On May 17, 4:18 pm, Terrence Brannon scheme...@gmail.com wrote:
I've done Perl coding and I still mix up chomp and chop. The meaning
of trim, ltrim, and rtrim is immediately clear to me.
trim, ltrim, and rtrim could take an optional argument for characters
to strip:
(rtrim foo) ;; strip trailing whitespace
(rtrim foo \r\n) ;; equivalent to chomp
If
user (loop [thm (transient {}),
i 0]
(if (= 10 i)
(persistent! thm)
(recur (assoc! thm i i)
(inc i
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9}
By the way, FYI:
(reduce #(assoc %1 %2 %2) {} (range 10))
or
Here's one way.
(defn tails [coll]
(take-while seq (iterate rest coll)))
(defn calc [total-values daily-values]
(map * daily-values (for [tail (tails total-values)]
(reduce #(* %1 (inc (/ %2 100.0)))
1.0
See also David Nolan's post:
http://dosync.posterous.com/lispers-know-the-value-of-everything-and-the
Justin
On Tuesday, August 9, 2011 6:02:00 PM UTC-4, pmbauer wrote:
For the sieve, if performance matters, clojure's native data structures may
not be the best choice.
A mutable array of
There are many ways one could model a tree/graph:
;; collection of edges
[[:a :b] [:b :c] [:b :d] [:c :e] [:d :e]]
;; adjacency list
{:a [:b] :b [:c :d] :c [:e] :d [:e]}
If you're looking for a pre-made solution, the loom graph library
(https://github.com/jkk/loom) may work:
(ns example
(candidates :e :e)
()
On 19 Aug, 16:12, Justin Kramer jkkr...@gmail.com wrote:
There are many ways one could model a tree/graph:
;; collection of edges
[[:a :b] [:b :c] [:b :d] [:c :e] [:d :e]]
;; adjacency list
{:a [:b] :b [:c :d] :c [:e] :d [:e]}
If you're looking for a pre
Here's another way, which constructs a sequence of edges using candidates,
which are then fed into reduce to build an adjacency list.
(defn candidates-edges [candidates from to]
(when-let [kids (seq (candidates from to))]
(concat (for [k kids] [from k])
(mapcat #(get-edges
Oops, renamed the function: get-edges = candidates-edges.
Justin
On Friday, August 19, 2011 4:03:27 PM UTC-4, Ulrik Sandberg wrote:
And get-edges?
On 19 Aug, 20:52, Justin Kramer jkkr...@gmail.com wrote:
Here's another way, which constructs a sequence of edges using
candidates
Prompted by a question on IRC a couple days ago, I built a tool that allows
you to browse the dependency graph of Clojure projects from GitHub
Clojars:
http://clojuresphere.herokuapp.com/
You can see dependencies of a project, but also projects which depend on it.
You can also see how many
specific versions are dependent:
http://clojuresphere.herokuapp.com/clojure-contrib/org.clojure/1.2.0
Will probably make some changes to clarify that...
Justin
On Tuesday, September 6, 2011 7:03:23 PM UTC-4, Sean Corfield wrote:
On Tue, Sep 6, 2011 at 8:17 AM, Justin Kramer jkkr...@gmail.com wrote
Here's a fleshed-out version that tests for any type of primitive:
(definterface IPrimitiveTester
(getType [^int x])
(getType [^long x])
(getType [^float x])
(getType [^double x])
(getType [^byte x])
(getType [^short x])
(getType [^char x])
(getType [^boolean x])
(getType
* install Leiningen
* install the swank-clojure plugin: lein plugin install swank-clojure
1.3.2
* install clojure-mode (you can do this from git)
* navigate to a project and do M-x clojure-jack-in
That's all it takes. It might work with Aquamacs, but since that fork
is not
Not currently. That and a number of other features are in the queue.
Justin
On Sunday, October 2, 2011 12:45:44 AM UTC-4, Daniel wrote:
Say I want to get a full list of _current_ dependents for clojure-1.2
or contrib, for upgrade purposes ... is there currently a way to do
that on
Here's a quick proof using an interface-based primitive detector:
(definterface IPrimitiveTester
(getType [^int x])
(getType [^long x])
;; other types elided
)
(deftype PrimitiveTester []
IPrimitiveTester
(getType [this ^int x] :int)
(getType [this ^long x] :long)
;; other types
1:13:03 PM UTC-4, Justin Kramer wrote:
Here's a quick proof using an interface-based primitive detector:
(definterface IPrimitiveTester
(getType [^int x])
(getType [^long x])
;; other types elided
)
(deftype PrimitiveTester []
IPrimitiveTester
(getType [this ^int x] :int
tree-seq makes this pretty simple:
(defn nested-vals [key coll]
(for [x (tree-seq coll? seq coll) :when (contains? x key)]
(get x key)))
This works with any type of key and all associative Clojure
structures. It could be made compatible with Java structures by
swapping out the 'coll?'
Here's my version. Main points:
* Use with-open line-seq for worry-free laziness
* Do everything in one swoop (reduce)
* Perform one regexp match per line
* Leverage -
;;
(ns user
(use [clojure.java.io :only [reader]]))
(def re-vote #([A-z]{1,16})(\+\+|\-\-))
(defn extract-votes
[line]
On Dec 22, 10:59 am, Benny Tsai benny.t...@gmail.com wrote:
It does, but doesn't that make it less lazy? To reverse something, it
needs to evaluate the whole sequence. I yet have to learn how to
deal with lazyness.
You're right, I hadn't realized 'reverse' is not lazy (I have a lot to
If you're setting values in an array, use aset:
(dotimes [i number]
(aset strip i (.createCompatibleImage gc width height transparency))
...)
If you want to get a value, use aget:
(let [stripGC (.createGraphics (aget strip i))]
...)
Hope that helps,
Justin
On Jan 21, 11:07 am,
Checking out clojure.core/destructure and clojure.core/let might be
helpful.
Here's a macro I hacked together. It doesn't work with :keys, :as,
or :or. I take no responsibility if you use it for anything real. But
maybe it will provide you with some ideas.
(defmacro destructure-map
[bvec val]
'for' can be handy when unpacking compound lines:
(ns foobar
(:require [clojure.java.io :as io]))
(defn parse-acl [acl-file]
(with-open [r (io/reader acl-file)]
(apply
merge-with into
(for [[status users path] (map #(.split % \\|) (line-seq r))
:when (= avail status)
https://github.com/ninjudd/ordered-set
Justin
On Mar 7, 1:14 pm, Tassilo Horn tass...@member.fsf.org wrote:
Hello all,
does clojure have sets that keep the insertion order, like Java's
LinkedHashSet?
Currently, I use lazy vectors in conjunction with `distinct', but that
seems to perform
Another option is to create a function which pulls examples from
clojuredocs.org on the fly (it has an API) and displays them in the
REPL. I made a proof-of-concept for this but using the now-defunct
Clojure Examples Wiki: https://gist.github.com/470031.
The utility of something like this would
I should be straightforward to implement a closed map (or record)
yourself using deftype. It could implement all the same interfaces as
Clojure's built-in maps, ensuring compatibility with assoc and such.
Here's an example of a map variant implemented using deftype:
'read' and 'read-string' are what you're looking for. They each read a
single Clojure object from an input source (PushbackReader for read,
String for read-string).
Alternatively, something like this can read all top-level forms from a
file:
(defn read-all
Reads all top-level forms from f,
Vector-as-map destructuring makes sense when you consider that vectors are
associative: they map index to value.
(let [{a 1 b 3 :as c} [:a 1 :b 2]] [a b c])
= [1 2 [:a 1 :b 2]]
Justin
On Tuesday, August 28, 2012 8:30:58 AM UTC-4, Douglas Orr wrote:
One possibly confusing titbit I came across
ClojureSphere has been updated with a new domain, refreshed index, and some
new features:
http://www.clojuresphere.com/
ClojureSphere lets you browse the dependency graph of the open source
Clojure ecosystem.
The dependency information is provides now is slightly more accurate and
useful.
Michael,
I actually think it's a project.clj parsing issue. Midje's is a little
non-standard looking. I've opened an issue for it.
Thanks for the feedback and report,
Justin
On Monday, September 3, 2012 2:15:28 AM UTC-4, Michael Klishin wrote:
2012/9/3 Justin Kramer jkkr...@gmail.com
Looks great. What mime type should be used? application/edn?
Justin
On Thursday, September 6, 2012 9:01:15 PM UTC-4, Rich Hickey wrote:
I've started to document a subset of Clojure's data format in an effort to
get it more widely used as a data exchange format, e.g. as an alternative
to
Hi Dave,
The conflicting reader issue is fixed in the Clojure 1.5 master branch.
Using data readers in a lib is perfectly acceptable as long as you
namespace qualify your tags, as the docs mandate: Reader tags without
namespace qualifiers are reserved for Clojure. See (doc *data-readers*).
On Tuesday, October 16, 2012 9:07:49 AM UTC-4, Stuart Sierra wrote:
- is it appropriate to include data_readers.clj in a library - given that
file is in the root?
No. data_readers.clj is intended for application developers. Libraries may
define data reader functions and suggest tags for
Current best practice in my view:
For Clojure 1.4+, do not use :use at all. Use :require :refer
(judiciously). :refer :all is almost never a good idea.
For Clojure 1.3 and below, :use :only is strongly encouraged. Bare :use is
almost never good.
Justin
On Thursday, November 8, 2012 11:57:21
Sorry, yes, to clarify -- :require :as is always good and generally
preferred over :refer or :use :only.
Justin
On Thursday, November 8, 2012 1:42:26 PM UTC-5, Luc wrote:
I am pragmatic and quite lazy, I use require with an alias and use mostly
with stuff like
clojure.tools.trace,
Yours is not actually the same as the one from Monger. Hint: you're missing
an important character that prevents def from being called.
Justin
On Thursday, November 8, 2012 10:22:39 PM UTC-5, Satoru Logic wrote:
Hi, all.
When I try to run the following `macro` in `lein repl` (with
Formative is a library for dealing with web forms. Features:
- Describe forms using simple data
- Render forms via pluggable renderers (comes with Bootstrap and other
renderers built-in)
- Parse submitted form data from Ring params
- Validate parsed data using Verily
Hi Bob,
Thanks for sharing your use case. One possible approach to fieldsets (among
others) is to have the renderer split fields on e.g. :heading and put each
group into a fieldset. Another would be to create a :fieldset field type
that itself contains other fields. I've created a GitHub issue
So I went ahead and implemented the first solution I mentioned: the default
renderer now groups fields into fieldsets, split by :heading and :submit
fields. Each fieldset has a class that you can target with css/js. You can
see the result in the demo - http://formative-demo.herokuapp.com/.
, 2013 1:32:21 PM UTC-5, hutch wrote:
On 2013-01-16, at 11:31 AM, Justin Kramer jkkr...@gmail.com javascript:
wrote:
So I went ahead and implemented the first solution I mentioned: the
default renderer now groups fields into fieldsets, split by :heading and
:submit fields. Each fieldset has
Another option: create a helper function to do the work and have the macro
call that:
(defn foo* [bar body-thunk]
{:pre [(string? bar)]}
(body-thunk)) ;or whatever
(defmacro foo [bar body]
`(foo* ~bar (fn [] ~@body))
Justin
On Tuesday, March 20, 2012 9:07:45 AM UTC-4, Chas Emerick
Hi Jeremy,
There's a RocLisp group that meets once in a while (next meeting TBD).
We've been focussing on Clojure so far.
http://roclisp.org/
https://github.com/roclisp
Twitter: @roclisp
I myself am pretty nuts about Clojure. Looking forward to meeting and
hacking with you,
Justin
@jkkramer
Nice, Mike. I stole your work and put it into the Wiki I created to
see how it fit:
http://clojure-examples.appspot.com/clojure.core/reduce
(Note: reduce seems to be missing a doc string in 1.2 master; for
other functions doc strings show up.)
As cool as walton is, it's kind of a firehose. A
-
architecting is moot.
Justin
On Jul 2, 5:09 am, kredaxx kred...@gmail.com wrote:
On 2 Lip, 09:46, Justin Kramer jkkra...@gmail.com wrote:
Partly in response to this issue and partly to get my feet wet with
Ring and friends, I spent the last few nights writing a proof-of-
concept Wiki to collect
:
On Fri, 2 Jul 2010 14:50:18 -0700 (PDT)
Justin Kramer jkkra...@gmail.com wrote:
Nice, Mike. I stole your work and put it into the Wiki I created to
see how it fit:
http://clojure-examples.appspot.com/clojure.core/reduce
Well, I like it, but I might be a bit biased.
I think the important
As part of the Clojure Examples Wiki experiment, I created a page
adapted from the Cheatsheet, with links to relevant docs and examples
(not many, yet):
http://clojure-examples.appspot.com/clojure.core
It's been reorganized and revised a bit from the Cheatsheet. The
design is a little plain but
One use case I was thinking of for the Wiki is that IDEs could make
API requests for individual functions on-the-fly, or do a mass export
periodically. A basic version of the former exists now:
http://clojure-examples.appspot.com/clojure.core/conj?format=json
The result could be displayed plain
enough, as I could imagine
many functions having a *lot* of examples, and just popping up a chunk
of scrolling text may or may not be what a typical IDE user would find
useful.
- Chas
On Jul 8, 2010, at 1:05 PM, Justin Kramer wrote:
One use case I was thinking of for the Wiki
Oh: it probably would have helped if I had said the API returns JSON,
not straight text/HTML.
Justin
On Jul 8, 1:44 pm, Justin Kramer jkkra...@gmail.com wrote:
They are separated: in the HTML version (html-content JSON
property), code is wrapped in pre class=code, results in pre
class=output
, 2010 at 7:48 PM, Justin Kramer jkkra...@gmail.com wrote:
Oh: it probably would have helped if I had said the API returns JSON,
not straight text/HTML.
Justin
On Jul 8, 1:44 pm, Justin Kramer jkkra...@gmail.com wrote:
They are separated: in the HTML version (html-content JSON
property
I've told Zack that he is free to pull any examples from the wiki for
use on his site.
I don't know about collaboration beyond that. The wiki is open source
and written in Clojure; anyone is free to contribute/fork. At least
one person has expressed interest in making code contributions.
Zack,
An examples function for the REPL that pulls from the wiki:
http://gist.github.com/470031
I'm sure something like it could be made for ClojureDocs.org once the
API is in place.
General comments on ClojureDocs.org: I think an important aspect of a
collaborative tool like this is quality control.
I think you want:
(defn- do-traversal [tree idx [tree-traversal]]
...)
Note the extra brackets for destructuring.
Another alternative is using multiple arg lists:
(defn- do-traversal
([tree idx]
(do-traversal tree idx []))
([tree idx traversal]
...))
Lastly, FYI, the form (if
With the precondition that the first collection is a vector:
(use '[clojure.contrib.seq-utils :only [positions]])
(defn nil-coalesce [v subs]
(apply assoc v (interleave (positions nil? v) subs)))
Justin
--
You received this message because you are subscribed to the Google
Groups Clojure
Another one that works with all collections. Short, but not
necessarily the most efficient:
(use '[clojure.contrib.seq-utils :only [positions]])
(defn nil-coalesce [coll subs]
(map-indexed (zipmap (positions nil? coll) subs) coll))
Justin
On Aug 17, 4:10 pm, Justin Kramer jkkra...@gmail.com
On Aug 17, 4:42 pm, Alan a...@malloys.org wrote:
Devious! The OP wanted to handle underflow of the subs collection
though, so you need a tweak:
(apply assoc v (interleave (positions nil? v)
(concat subs (repeat nil
interleave stops once either collection is
On Aug 18, 2:42 am, Michael Wood esiot...@gmail.com wrote:
nils replace nils when there are fewer substitutions than nil
positions was one of the requirements.
From the first post:
If nil is encountered in the first sequence and the second sequence is
exhaused, nil will be returned:
Meikel's suggestions are all good and I would follow them.
There are a number of built-in functions you can take advantage of if
you're using 1.2 (they're also available in contrib for 1.1):
clojure.string/lower-case
clojure.java.io/reader -- obviates java.io.BufferedReader and friends:
(reader
Woohoo, congrats! Can't wait to see all the new goodies that are in
store for the next version.
Justin
On Aug 19, 11:25 am, Rich Hickey richhic...@gmail.com wrote:
I'm pleased to announce today the release of Clojure 1.2.
http://clojure.org/downloads
For maven/leiningen users, your settings
Another tip: per the doc for 'empty?', (seq s) is preferred over (not
(empty? s)). Oh, and 'str' isn't necessary since 'println' adds spaces
between arguments:
(defn printall [s]
(when (seq s)
(println Item: (first s))
(recur (rest s
Justin
On Aug 31, 10:57 am, Nicolas Oury
A couple other things:
1) (apply identity ...) is the same as (first ...)
2) Consider using the - macro to clean up the let
Here's a quick rewrite:
(defn make-target
([file channel sweepidx]
(make-target file channel sweepidx 0))
([file channel sweepidx startidx]
(make-target file
Thanks and congratulations to the Clojure/core team for making this
happen. Can't wait!
Justin
On Sep 3, 3:15 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
We're happy to announce that the official (first clojure-conj) conference
site is now live athttp://clojure-conj.org, and that
reduce returns a single value; there's no collection to make lazy.
There is reductions, which returns the intermediate results of reduce
as a lazy sequence.
Justin
On Sep 6, 12:49 pm, Robert McIntyre r...@mit.edu wrote:
I thought that since into uses reduce, it would be lazy, but I was wrong.
Is using 'is' and 'every?' an option?
(deftest test-good-labels
(is (every? valid-label? good-labels)))
Justin
On Sep 21, 11:53 am, Sean Devlin francoisdev...@gmail.com wrote:
I'm trying to pass a vector to are, because I need to reuse some
source data. Is there a better way to do this? I
Here's the magic incantation I've been using:
[org.clojure.contrib/complete 1.3.1-SNAPSHOT :classifier bin]
I don't know how official or future-proof that is.
Justin
On Sep 22, 2:02 am, Sean Corfield seancorfi...@gmail.com wrote:
On Fri, Aug 20, 2010 at 7:22 AM, Stuart Sierra
On Oct 6, 8:39 am, B Smith-Mannschott bsmith.o...@gmail.com wrote:
On Wed, Oct 6, 2010 at 08:49, Abraham vincent@gmail.com wrote:
; prints all files
(import 'java.io.File)
(defn walk [dirpath]
(doseq [file (- dirpath File. file-seq)]
(println (.getPath file) )))
This doesn't
I should mention that Ben's solution is still nice and is basically
how tree-seq is implemented under the hood. It is more idiomatic than
using loop/recur (for most use cases).
Justin
On Oct 6, 10:59 am, Justin Kramer jkkra...@gmail.com wrote:
On Oct 6, 8:39 am, B Smith-Mannschott bsmith.o
The 'palindrome?' function can be made much faster. Your version --
which is idiomatic and fine when perf isn't a factor -- turns the test
string into a sequence, reverses it, turns it back into a string, then
checks for full equality with the original. There are faster (if
uglier) ways to check
Check out assoc-in, get-in, and update-in. They make working with
nested maps a breeze. Here's a rewrite of your code:
(ns user
(:require [clojure.string :as str]
[clojure.java.io :as io]))
(def postcode-trie
(with-open [r (io/reader /path/to/data.csv)]
(reduce
(fn [trie
Implementing this in straight Java might help pinpoint whether this is
a JVM issue or a Clojure issue.
Also, FYI, there is clj-glob (https://github.com/jkk/clj-glob) for
finding files based on patterns like */*/*.dat
Justin
On Nov 4, 4:28 pm, Pepijn de Vos pepijnde...@gmail.com wrote:
Hi all,
print-table was actually just added to the master branch:
https://github.com/clojure/clojure/commit/826ff8486fb3e742cea80ebc43d93afbd85b52d9
Justin
On Nov 13, 1:02 pm, Shantanu Kumar kumar.shant...@gmail.com wrote:
Does anybody know if a standard 'print-table' kind of function exists
in some
As Rob mentioned, I won't be doing further development Loom anytime in the
near future. However, if critical mass forms around a fork or alterate
project, I'd be happy to add a prominent link in the readme.
Justin
On Tuesday, June 18, 2013 3:10:23 AM UTC-4, Stephen Kockentiedt wrote:
My bad.
Besides post-processing results, you can also instruct java.jdbc to return
Joda dates in the first place.
Using clojure.java.jdbc 0.3.0-alpha4:
(ns example
(:require [clojure.java.jdbc :as j]
[clj-time.local :as cl]))
...
(extend-protocol j/IResultSetReadColumn
java.sql.Date
clojure.java.jdbc is transitioning to an API that uses explicit passing of
db context - see e.g. the db-find-connection and query functions. The
functions that look for a dynamically-scoped db are deprecated -
e.g., find-connection, with-query-results.
Justin
On Friday, September 6, 2013
Congratulations on the release, and thank you for your hard work! CCW is a
great tool that makes my life easier.
Justin
On Thursday, October 10, 2013 9:36:01 AM UTC-4, Laurent PETIT wrote:
Hi, a new version of Counterclockwise, the Clojure plugin for the
Eclipse IDE, has just been released.
77 matches
Mail list logo