Re: seeking a lazy way to interleave a constant

2012-04-10 Thread Alan Malloy
On Apr 10, 12:36 am, David Powell wrote: > > As an aside.. I just looked at the source for this, what does the :static > > tag in the metadata do? > > From what I can make out... nothing.  I think it is left over from an > experiment to improve var lookup times prior to dynamic binding being > dis

Re: Advice on style & implementation

2012-04-04 Thread Alan Malloy
On Apr 4, 6:50 am, David Jagoe wrote: > Particularly I very often find myself doing > > (apply hash-map (flatten (for [[k v] some-map] ...))) :( :( :( flatten is vile, never use it[1]. What if the value in the map is a list, or the key is a vector? Now you've broken it. Instead use into: (into {

Re: What's the efficient functional way to computing the average of a sequence of numbers?

2012-03-29 Thread Alan Malloy
On Mar 29, 10:18 am, David Cabana wrote: > On Thu, Mar 29, 2012 at 12:18 AM, simon.T wrote: > > The obvious way is like the following, which traverse the sequence 2 times. > > ... > > The obvious way does not necessarily traverse the sequence twice.  If > a sequence S satisfies the 'counted?' pre

Re: motivation behind laziness of apply in ClojureScript

2012-03-28 Thread Alan Malloy
On Mar 27, 11:51 pm, Nathan Sorenson wrote: > When trawling the ClojureScript source, I was a little puzzled when I first > noticed that cljs.core/apply respects the laziness of the seq its provided. > Fogus mentioned this feature in his Clojure/west talk and it reminded me of > my earlier puzzlem

Re: into applied to transient vectors undocumented?

2012-03-20 Thread Alan Malloy
(def into! #(reduce conj! %1 %2))? On Mar 20, 10:32 am, László Török wrote: > Hi, > > While implementing qsort with clojure for fun, I thought about using > transient vectors to speed up sorting vs the "naive" functional > implementation. > > I need an *into!* version of *into *when joining two s

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Alan Malloy
And this is exactly as it should be. The sorted set has no way to compare items other than by your comparator. If it just arbitrarily decided to use = instead of checking that (zero? (compare x y)) it would not be using your comparator. Note also that the behavior of contains? is consistent with c

Re: using Clojail dynamically

2012-03-09 Thread Alan Malloy
Indeed. Don't pass it the function +, pass it the symbol '+. On Mar 9, 1:20 am, "Meikel Brandmeyer (kotarak)" wrote: > Hi, > > without being too deep in clojail and the like... > > Try quoting the func and input values to your function-sandbox function. > > Sincerely > Meikel -- You received th

Re: Can Clojure be as readable as Python or Ruby ?

2012-03-07 Thread Alan Malloy
On Mar 7, 9:39 am, Leon Talbot wrote: > If so, how ? > > Thanks ! [Closed as: Not a real question] -- 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 mod

Re: Why don't extends? and satisfies? require implementation of all protocol methods?

2012-03-07 Thread Alan Malloy
On Mar 7, 1:09 am, Tassilo Horn wrote: > David Powell writes: > > Hi David, > > > When you create a protocol, as an implementation detail, it also > > creates a Java interface. > > Is a protocal neccessarily an implementation detail?  I mean, it might > be, but it can also be a public specificati

Re: Serializing ClojureScript data structures

2012-03-02 Thread Alan Malloy
Related: str is a terrible way to serialize things in JVM-clojure as well - pr-str is what you want. For example, {:x "a"} and {:x 'a} both print the same with str. pr-str also handles lazy sequences, which str doesn't. On Mar 2, 8:19 am, David Nolen wrote: > pr-str will do what you want. That sa

Re: for behavior difference between clojure and clojurescript?

2012-02-29 Thread Alan Malloy
On Feb 29, 2:36 pm, Benjamin Peter wrote: > Hello, > > when I was trying to port a little clojure app to clojurescript I > think I noticed a difference in behavior of the "for" macro. > > I am quite new to clojure and maybe you can tell me where my problem > is or if my assumptions that there migh

Re: How to be lazy…

2012-02-24 Thread Alan Malloy
Why would you (remove nil? (map f coll))? That's what keep is for: (keep f coll). On Feb 24, 11:20 am, Cedric Greevey wrote: > On Fri, Feb 24, 2012 at 2:17 PM, JuanManuel Gimeno Illa > > wrote: > > What I don't understand of your solution is the (map seq (step pieces)) > > because for me it is c

Re: Why does (= [] (range)) not terminate?

2012-02-17 Thread Alan Malloy
On Feb 17, 1:34 pm, David Powell wrote: > > Lazy sequences implement java.util.List, which has a .size method. > > clojure.lang.APersistentVector/doEquiv (and doEquals) attempts to > > optimize when it sees it is being compared to something with a .size > > or .count method, by comparing sizes bef

Re: Why does (= [] (range)) not terminate?

2012-02-17 Thread Alan Malloy
On Feb 17, 10:54 am, Michael Gardner wrote: > On Feb 17, 2012, at 12:32 PM, Bill Smith wrote: > > > It might help to know that (= (range) (range)) does not terminate either. > > Of course, since a pairwise sequential comparison (what I assume is going on > under the hood) will never find a non-ma

Re: Looking for parser generator library

2012-02-16 Thread Alan Malloy
https://www.google.com/search?q=attoparsec+in+centimeters is where I got a citation to back the 3.1 centimeter number (though, curiously, I asked for km instead of cm the first time). On Feb 15, 5:51 pm, DAemon wrote: > Not massively - I get about 3.1 metres. 10^-18x10^15x10^3x3.1m... > > > > > >

Re: Looking for parser generator library

2012-02-15 Thread Alan Malloy
Roman Gonzalez: > this library is a port of Haskell's attoparsec Despite: > > Haskell has a parser library named for a distance of approximately > > three centimetres? :) > > Not that it's pertinent, but a parsec is 31 trillion kilometers.  Did > you massively misplace a decimal?  :) 1 attoParsec

Re: Avoiding reflection in vector-of

2012-02-13 Thread Alan Malloy
vector-of is just implemented poorly - with more than four arguments it calls .cons on the vector it's building up. If the type were known and type-hinted this would be a slightly faster version of conj, but lacking the type-hint it's just a much, much slower version of conj. Adding ^Vec to line 49

Re: A Bug of map function?

2012-02-13 Thread Alan Malloy
If this is a bug, it's in eval, not in map. eval apparently just doesn't like to be handed lazy sequences, or something: repl-1=> (eval `(quote ~(lazy-seq nil))) CompilerException java.lang.UnsupportedOperationException: Unknown Collection type, compiling:(NO_SOURCE_PATH:14) ;; just to demonstrat

Re: Hierarchical logs

2012-02-12 Thread Alan Malloy
I toyed with some simple ways of doing this, but I don't think any of them will actually work out. I think the advice you got in #clojure to use zippers is probably correct. Here's a sketch I bashed out that seems to do roughly what you want: https://gist.github.com/1807340 (I took the liberty of w

Re: novice question, performance surprise

2012-02-11 Thread Alan Malloy
(def separate (juxt filter remove)). It's in old-contrib, I think in clojure.contrib.seq-utils or something. Obviously not recommended for use in new programs. On Feb 11, 3:49 pm, Cedric Greevey wrote: > On Sat, Feb 11, 2012 at 4:44 PM, Jules wrote: > > There is a standard library function for

Re: Symbols, vars, and namespaces

2012-02-11 Thread Alan Malloy
In this case the var is simply acting as a mutable pointer, so that when the implementation is changed the route reflects the new value. Here's a simple example of that behavior in action, divorced from webservers and the like: ;; caller accepts a function and returns a new one that forwards to it

Re: Marshal 1.0.0

2012-02-05 Thread Alan Malloy
o handle variable sized > arrays/strings (size of array or string specified in packet). > > On Sun, Feb 5, 2012 at 6:10 PM, Alan Malloy wrote: > > Zack Tellman's library Gloss is excellent for this, if a bit confusing > > to understand at first. > > > On Feb 5, 2:

Re: Marshal 1.0.0

2012-02-05 Thread Alan Malloy
Zack Tellman's library Gloss is excellent for this, if a bit confusing to understand at first. On Feb 5, 2:50 pm, russellc wrote: > I needed a library  to handle marshaling application defined (C > struct) binary TCP/IP protocol packets in a Clojure client app > replacing a legacy C++ client and

Re: How to loop over several sequences in parallel for side-effects?

2012-01-23 Thread Alan Malloy
(dorun (map f xs ys zs)) creates and discards a cons for each iteration, no argument there. But its first element is very cheap: just the result of f, which you had to compute anyway. (doseq [[x y z] (map vector xs ys zs)] (f x y z)) similarly creates a cons for each iteration. But its value, rath

Re: How to loop over several sequences in parallel for side-effects?

2012-01-20 Thread Alan Malloy
But I don't see any reason why this would be faster than (dorun (map side-effect-fn s1 s2 s3)). You're creating and then dismantling a three-element vector at every iteration to no purpose. On Jan 20, 12:40 pm, Meikel Brandmeyer wrote: > Hi, > > to add to Lars answer: > > (doseq [[a b c] (map vec

Re: Best IDE

2012-01-19 Thread Alan Malloy
On Jan 19, 5:26 pm, Mark Nutter wrote: > If you put the cursor on the opening paren and then hit C-k, it cuts > out exactly that sexp (and its contents) but no more, keeping the > parens perfectly balanced. You want C-M-k, not C-k. C-k is a little more aggressive, since it always kills at least t

Re: clojure.contrib.prxml broken in Clojure 1.3.0

2012-01-18 Thread Alan Malloy
rote: > It might not make a lot of practical difference, but my understanding > is that CDATA isn't parsed as XML, so if you have a lot of non-xml > data, it's probably better to use CDATA so that it is not parsed when > it's read back in. > > On Jan 17, 11:12 p

Re: clojure.contrib.prxml broken in Clojure 1.3.0

2012-01-17 Thread Alan Malloy
It doesn't need CDATA - data.xml just automatically escapes XML special-characters if it sees them. On Jan 17, 4:12 pm, jweiss wrote: > By the way, the reason I stuck with prxml is its handling of CDATA, > which as far as I know, the newer lib doesn't do yet. > > On Jan 17, 8:10 am, cassiel wrot

Re: I don't understand how to instantiate a closure library object

2012-01-10 Thread Alan Malloy
On Jan 10, 3:07 pm, Praki Prakash wrote: > On Tue, Jan 10, 2012 at 2:22 PM, billh2233 wrote: > > I'm trying to instantiate a new goog.fx/Animate object, but the > > constructor doesn't return anything: > > >  (:require [goog.fx :as fx]) > >  (let [anim (fx/Animation (array 22 33) (array 44 55) 10

Re: Struggling in making a sub-process work in an interactive way

2012-01-10 Thread Alan Malloy
On Jan 9, 9:24 pm, Phil Hagelberg wrote: > jaime writes: > > Later on I tried to add code that can make this possible but I found > > there's no way to detect if a command requires user's input and thus I > > have to find another way to make it work - but I didn't success and > > have been strugg

Re: Java interop: inner class

2012-01-09 Thread Alan Malloy
The syntax for this is atrocious in Java and the mechanism is in general rarely useful; I wouldn't be surprised if there's no non-hacky way to do this in Clojure. fooInstance.new Bar() is the construct you're talking about, right? My best guess would be that you just use the inner class's "real" (J

Re: On using atoms together with side effect functions

2012-01-06 Thread Alan Malloy
On Jan 6, 7:32 pm, Cedric Greevey wrote: > On Fri, Jan 6, 2012 at 10:22 PM, Alan Malloy wrote: > > On Jan 6, 6:16 pm, Cedric Greevey wrote: > >> On Fri, Jan 6, 2012 at 4:34 PM, Alan Malloy wrote: > >> > On Jan 6, 12:56 pm, Jozef Wagner wrote: > >> >

Re: On using atoms together with side effect functions

2012-01-06 Thread Alan Malloy
On Jan 6, 6:16 pm, Cedric Greevey wrote: > On Fri, Jan 6, 2012 at 4:34 PM, Alan Malloy wrote: > > On Jan 6, 12:56 pm, Jozef Wagner wrote: > >> Thank you, > > >> But the things are more complicated. In my case, I need to update the atom > >> with

Re: On using atoms together with side effect functions

2012-01-06 Thread Alan Malloy
On Jan 6, 12:56 pm, Jozef Wagner wrote: > Thank you, > > But the things are more complicated. In my case, I need to update the atom > with the result of a (native) function which unfortunately also performs > some side effects and cannot be split in two. > > Updated example: > > (def state {:resul

Re: macro question

2012-01-03 Thread Alan Malloy
On Jan 3, 7:22 pm, Trevor wrote: > hmmm macro question: > > ; here's a macro that assembles many puts. It serves no purpose to me > (and doesn't even make sense in its current form). It's just something > I hit playing around and learning macros. > > (defmacro doto-putter [x y xs] >   `(doto (

Re: Potential bug w/ inlined functions

2012-01-02 Thread Alan Malloy
I agree it looks like a type-hinting issue, but since ^bytes x is reader-expanded to ^{:tag 'bytes} x, I don't see that change making any difference. I'd be more inclined to try ^"[B" instead, to avoid the possibility of var resolution. I don't get the last point. He wants it to be type-hinted so

Re: Bug in extend-protocol macro? (Clojure 1.3.0)

2011-12-30 Thread Alan Malloy
On Dec 30, 11:34 am, "Marshall T. Vandegrift" wrote: > Peter Taoussanis writes: > > Thanks- that explains it: dropping to extend works as expected. > > Another option I've been making use of for exactly this situation is to > use the #= reader macro to evaluate the Class/forName at read-time. > S

Re: Clojure list syntax sugar: f(x) notation

2011-12-28 Thread Alan Malloy
% would work even worse because it doesn't nest. I still think the whole idea ia a dreadful one, but < would cause problems less often than other suggestions. On Dec 28, 10:06 pm, Ambrose Bonnaire-Sergeant wrote: > On further thought, it will be a breaking change > > (def f 1) > > (let [x 1] >  

Re: Bug in extend-protocol macro? (Clojure 1.3.0)

2011-12-26 Thread Alan Malloy
On Dec 26, 10:21 pm, Peter Taoussanis wrote: > Hi there, > > I'm using Clojure 1.3.0 and am running into what seems like an edge- > case problem with extend-protocol (?)... > > Given (defprotocol MyProtocol (action [x])), > > (extend-protocol MyProtocol >   (Class/forName "[B") (action [x] "ByteAr

Re: proxy with dynamic

2011-12-25 Thread Alan Malloy
On Dec 25, 12:45 am, Razvan Rotaru wrote: > Hi, > > Is it possible to give the class as value at runtime to proxy? > > (defn create-proxy [clazz] >     (proxy [clazz] )) > > I know this can be done with a macro, but my question is whether it > can be done as function. Presumably you just trie

Re: multiple return values

2011-12-22 Thread Alan Malloy
On Dec 22, 5:48 pm, Brian Goslinga wrote: > On Dec 22, 8:52 am, Razvan Rotaru wrote:> What do > you mean by site? > > For example, how is it when I'm creating my proxy inside a macro? (and > > assuming this macro is called many times) > > > (defmacro [a-class] > >     (proxy (a-class) )) > >

Re: Why are body-macros more fashionable than thunks?

2011-12-22 Thread Alan Malloy
with-open and with-local-vars couldn't be thunks - the whole point is creating some lexical variables in the caller's scope. Instead of (with-open [f (file)] (stuff f)) you could require (open-callback (fn [f] (stuff f)) (file)): either could expand into something like ((fn [f] (stuff f)) (file)),

Re: Question about accessing java methods?

2011-12-21 Thread Alan Malloy
On Dec 21, 12:03 pm, Jonas wrote: > You can also do (.. boxWidget GetProp3D (SetUserTransform t)) or (-> > boxWidget .GetProp3D (.SetUserTransform t)) Well, neither of these are strictly equivalent to his original code, which returns the boxWidget; yours return the result of SetUserTransform. H

Re: Could be my favourite improvement in 1.4

2011-12-20 Thread Alan Malloy
Well, that would be sufficient if we had HEREDOCs like Alex asked for, but surrounding some JSON with ""s will usually break. On Dec 20, 5:28 am, jweiss wrote: > Even if they did, it's pretty easy to surround the paste with (read- > json "... "). > > On Dec 20, 10:36 am, Alex Baranosky > wrote:

Re: Could be my favourite improvement in 1.4

2011-12-19 Thread Alan Malloy
On Dec 19, 9:25 pm, Phil Hagelberg wrote: > JSON as readable Clojure was discussed and shot down a while back, albeit > with a weirder > implementation:http://groups.google.com/group/clojure-dev/browse_thread/thread/5b066... > idea of colons having special treatment in the context of maps is > ra

Re: defrecord based on runtime metadata?

2011-12-18 Thread Alan Malloy
Why do you want to do this? It's possible that it would improve performance if you generated loads of these records, but you would have to effectively compile your whole program at runtime in order to have the static type information needed to get the improved performance. Most of the time someone

Re: How to: convert output stream into an input stream

2011-12-16 Thread Alan Malloy
-in (PipedOutputStream.) (PrintWriter.))] (binding [*out* out] (do-whatever pipe-in) On Dec 16, 1:49 am, Alan Malloy wrote: > You can't really do this in a single thread without risking blocking. > But with another thread, it's fairly simple. For example, I d

Re: How to: convert output stream into an input stream

2011-12-16 Thread Alan Malloy
You can't really do this in a single thread without risking blocking. But with another thread, it's fairly simple. For example, I do this in my gzip-middleware, copying an InputStream through a pipe with GZIP wrapping: https://github.com/amalloy/ring-gzip-middleware/blob/master/src/ring/middleware

Re: want to make a 'debug' function, how to get current source and line number?

2011-12-15 Thread Alan Malloy
On Dec 15, 1:09 pm, Cedric Greevey wrote: > On Thu, Dec 15, 2011 at 1:54 PM, Alan Malloy wrote: > > This will print all the debug information at compile time, which is > > usually not what you want. I have a little macro I use called ?, which > > looks like: > > >

Re: my first attempt at a macro returns form wrapped in clojure.core/fn

2011-12-15 Thread Alan Malloy
FWIW, much safer is (defmacro dc [sql-cmd] `(sql/with-connection db ~sql-cmd)) If you use the version with (list) and plain-quoting of the first two items, then the namespace resolution is very fragile: it will only work if the caller has referred to the sql library with the prefix sql/,

Re: want to make a 'debug' function, how to get current source and line number?

2011-12-15 Thread Alan Malloy
This will print all the debug information at compile time, which is usually not what you want. I have a little macro I use called ?, which looks like: (defmacro ? [x] `(let [x# ~x] (prn '~x '~'is x#) x#)) You could add file and line information to this fairly simply: (defmacro ? [x]

Re: multiple return values

2011-12-14 Thread Alan Malloy
Correct, just like closures and reifies. On Dec 14, 7:33 am, Tom Faulhaber wrote: > Razvan, > > I believe that proxy actually only creates a new class per call site, > not per instance. However, I can't completely swear to this. > > Anyone with more detailed knowledge than I have want to comment?

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 14, 2:22 am, Alan Malloy wrote: > On Dec 14, 1:18 am, Cedric Greevey wrote: > > > > > > > > > > > On Wed, Dec 14, 2011 at 3:12 AM, Alan Malloy wrote: > > > On Dec 13, 8:37 pm, Cedric Greevey wrote: > > >> On Tue, Dec 13, 2011 at

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 14, 1:18 am, Cedric Greevey wrote: > On Wed, Dec 14, 2011 at 3:12 AM, Alan Malloy wrote: > > On Dec 13, 8:37 pm, Cedric Greevey wrote: > >> On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy wrote: > >> > On Dec 13, 7:56 pm, Stephen Compall wrote: > >&g

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 13, 8:37 pm, Cedric Greevey wrote: > On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy wrote: > > On Dec 13, 7:56 pm, Stephen Compall wrote: > >> On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: > >> > As you can see, only as many elements are realized a

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Alan Malloy
On Dec 13, 7:56 pm, Stephen Compall wrote: > On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: > > As you can see, only as many elements are realized as are needed to > > satisfy the user's request. > > Yes, in the expression (conr (conr (conr '( 1 2 3) 4) 6)

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Alan Malloy
On Dec 13, 3:05 pm, Stephen Compall wrote: > On Mon, 2011-12-12 at 10:53 -0800, Michael Jaaka wrote: > > (defn conr[ col item ] > >    (lazy-seq > >            (if (seq col) > >                    (cons (first col) (conr (rest col) item)) > >                    (list item > > > And now stick w

Re: bug in clojure.walk in 1.3

2011-12-13 Thread Alan Malloy
On Dec 13, 11:36 am, Stuart Sierra wrote: > It's not clojure.walk, it's bean: > > user=> (empty (bean "hi")) > AbstractMethodError > clojure.lang.APersistentMap.empty()Lclojure/lang/IPersistentCollection; > clojure.core.proxy$clojure.lang.APersistentMap$0.empty (:-1) > > The generated class doesn'

Re: bug in clojure.walk in 1.3

2011-12-13 Thread Alan Malloy
Issue is in bean, not walk. walk calls (empty foo) on its collection, in order to make sure you get back a collection of the same type. bean maps are, I guess, some special type rather than an ordinary c.l.PersistentHashMap; and that type doesn't implement the full IPersistentCollection contract (i

Re: definterface vs. defprotocol type hints

2011-12-11 Thread Alan Malloy
On Dec 11, 8:15 am, blais wrote: > Hi, > > Why is it that defprotocol ignores type hints, while definterface > deals with them? Both macros expand to a call to > gen-interface--defprotocol just adds a bit more to that. I don't see > why it wouldn't be possible. > > Is it just a historical artifact

Re: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
On Dec 7, 9:23 pm, Andy Fingerhut wrote: > On Wed, Dec 7, 2011 at 8:29 PM, Alan Malloy wrote: > > On Dec 7, 8:12 pm, Andy Fingerhut wrote: > > > Ugh.  And if I were slightly lazier at pressing the send button, I would > > > have realized that the laziness of map and

Re: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
On Dec 7, 8:12 pm, Andy Fingerhut wrote: > Ugh.  And if I were slightly lazier at pressing the send button, I would > have realized that the laziness of map and remove gives this short-circuit > evaluation. > > I generalized your example to allow the notation [- keyfn] as an argument > to specify

Re: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
This should be a function, not a macro. In fact it is just: (defn multicmp [& xs] (first (remove zero? xs))) But what you really wanted to begin with is a comparator function, so more like: (defn multicmp [& keys] (fn [a b] (or (first (remove zero? (map #(compare (% a) (% b))

Re: Type hints for ^map migrating from 1.2 to 1.3

2011-12-06 Thread Alan Malloy
On Dec 6, 10:31 am, Meikel Brandmeyer wrote: > Hi, > > Am 06.12.2011 um 18:31 schrieb Eric in San Diego: > > > I'm migrating some code from 1.2 to 1.3, and one of the things I've > > encountered is that it no longer accepts ^map as a type hint.  It's > > happy if I use ^clojure.lang.PersistentArra

Re: another noob recursion question

2011-12-01 Thread Alan Malloy
On Dec 1, 2:14 pm, Stuart Sierra wrote: > Tree-building functions are not usually tail-recursive.  I'm not even sure > that Scheme will do tail-call elimination in that case.  The Java stack can > hold 8000 frames or so, so log base 2 is probably small enough to avoid a > stack overflow when build

Re: Get multiple vals from a map

2011-12-01 Thread Alan Malloy
I usually use juxt, but a more correct/robust solution is to use map, with the lookup-map as the function: (map {:foo 1 :bar 2 :baz 0} [:foo :bar]) On Dec 1, 12:26 pm, Ulises wrote: > How about using juxt: > > sandbox> ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0}) > [1 2] > sandbox> > > This only wo

Re: A few enhancements

2011-12-01 Thread Alan Malloy
1) I agree this seems silly but I don't think it's ever bitten me 2) I think this has caused me problems once or twice 3) It would be nice to have Named and Namespaced, but I don't think it's feasible to make the change now - there's too much code assuming you can get the namespace of a Named thi

Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Alan Malloy
(btw I threw this together just before bed, so it's not perfect. One thing that's wrong is it assumes (name x) can be called on any x; but it can't be called on lots of things, like numbers. So you'd need to filter those out, and also fix a couple other bugs. On Dec 1, 2:12 am

Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Alan Malloy
LoL lets you write: (with-cxrs (blah (foo (bar (cadddar x) ie, it looks in your source, sees what you need defined, and makes a letfn. This looked fun, so I banged out an implementation: (defn cxr-impl [name] (when-let [op (second (re-matches #"c([ad]+)r" name))] `(comp ~@(map {\a `

Re: noob question about error with tail recursion

2011-11-30 Thread Alan Malloy
(seq? ()) is true. You want (seq all), not (seq? all). There may be other problems, but that one jumps out at me. On Nov 30, 1:53 pm, coco wrote: > yep..that is an error but (recur (rest rst) I think wouln't work...maybe > something like > > (defn packing [lista] >   (loop [[fst snd :as all] list

Re: Clojure 1.3 head holding bug

2011-11-28 Thread Alan Malloy
On Nov 28, 1:55 pm, Juha Arpiainen wrote: > On Nov 27, 3:59 am, Gerrard McNulty wrote: > > Hi, > > > I've a head holding problem that I believe is a bug in clojure 1.3.  I > > wrote the following function to split a a lazy seq of strings across > > files of x size: > > > (defn split-file > >   ([

Re: Clojure 1.3 head holding bug

2011-11-28 Thread Alan Malloy
Interesting. It seems to me like locals-clearing should take care of this for you, by preparing a call to trampoline, then setting the locals to nil, then calling trampoline. But you can solve this easily enough yourself, in this particular case, by splitting the strings up into chunks before you o

Re: Can we make implements? public

2011-11-28 Thread Alan Malloy
On Nov 28, 11:14 am, Meikel Brandmeyer wrote: > Hi, > > Am 28.11.2011 um 20:10 schrieb Brent Millare: > > > I need to verify if an object implements a protocol. Looking at the source > > code, I noticed that protocol objects act as a map, and has the key :impls. > > From this is a map I can look

Re: keyword arguments

2011-11-27 Thread Alan Malloy
On Nov 27, 8:43 am, Mark Rathwell wrote: > Also, another way to take keyword arguments is: > > (defn foo [& opts] >   (let [opts (apply hash-map opts)] >     (println opts))) This is what already happens internally with the & {:keys ...} notation. You can actually be rather more concise if you wr

Re: Lookup on a symbol?

2011-11-23 Thread Alan Malloy
Other way round. It behaves like a keyword, looking itself up in a map: ('x '{x 1 y 2}) yields 2. You see the same behavior with (reduce :and [5 10]), yielding 10. On Nov 23, 9:32 pm, Sean Corfield wrote: > @lloyda2 posted on Twitter: (reduce 'and '(false true)) => true ...Huh? > > I must admit,

Re: Use of eval

2011-11-22 Thread Alan Malloy
If you try to do it without eval and you don't have the apache stuff on your classpath, then you get an exception while compiling, before class/forname is ever called. On Nov 22, 11:33 am, vitalyper wrote: > Gary, > > You were right with your initial reply. Sorry I did not get it. Thanks > for yo

Re: Proposal: libraries should have type hints

2011-11-21 Thread Alan Malloy
On Nov 21, 12:24 pm, Sean Corfield wrote: > On Mon, Nov 21, 2011 at 8:12 AM, Tassilo Horn wrote: > > But is that really an issue?  I mean, since you cannot use such duck > > typing in Java itself (except in terms of reflection), any method > > defined for more than one class with shared, consiste

Re: ClojureScript deftype and extend-type differ

2011-11-20 Thread Alan Malloy
The correct way to write this extend-type is (extend-type MyType MyProtocol (something ([this] 1) ([this x] x))) The version you posted doesn't work in JVM-Clojure either; I don't have CLJS handy, but I suspect that this version will work fine there. On Nov 20, 11:36 am, David Nolen

Re: adding metadata to java objects

2011-11-16 Thread Alan Malloy
On Nov 16, 11:53 am, Ben Smith-Mannschott wrote: > On Wed, Nov 16, 2011 at 17:28, Ben Mabey wrote: > > Hi, > > I would like to be able to add metadata to arbitrary java objects that have > > already been instantiated.  I know that you can use proxy to add metadata to > > objects that you create b

Re: where is defvar?

2011-11-14 Thread Alan Malloy
On Nov 14, 7:44 pm, Phil Hagelberg wrote: > On Mon, Nov 14, 2011 at 4:26 PM, Alan Malloy wrote: > > (def name doc init) > > Actually defvar is more like defonce. Huh? I don't see any defonce semantics at https://github.com/clojure/clojure-contrib/blob/master/modules/def/src/

Re: where is defvar?

2011-11-14 Thread Alan Malloy
(def name doc init) On Nov 14, 4:03 pm, Brad wrote: > I'm working on moving to Clojure 1.3 > > Some code is using defvar which use to be in clojure.contrib.def > > http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go > mentions that contrib.def partially migrated to clojure.core.inc

Re: form-zip

2011-11-08 Thread Alan Malloy
(fz-node-seq x) is just (tree-seq coll? seq x) then, yeah? I could see form-zip being useful for people who like zippers (personally I don't have enough experience to be comfortable with them), but fz-node-seq doesn't seem useful. On Nov 1, 8:56 pm, George Jahad wrote: > surely this one's been wr

Re: form-zip

2011-11-08 Thread Alan Malloy
They have a different make-node function, so that when you edit a vector-zip you get vectors instead of something else. It's also easy to imagine your "data units" are simple vectors, grouped together in some kind of list structure. Then you would want the zipper to tell you "hey, this node is a le

Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-08 Thread Alan Malloy
On Nov 8, 6:46 pm, Alan Malloy wrote: > On Nov 8, 4:44 pm, Stuart Halloway wrote: > > > This is under clojure 1.2.0, 1.2.1, 1.3.0, though the error messages > > > differ. > > > > Consider a trivial project that `uses` midje: > > > >    (n

Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-08 Thread Alan Malloy
On Nov 8, 4:44 pm, Stuart Halloway wrote: > > This is under clojure 1.2.0, 1.2.1, 1.3.0, though the error messages differ. > > > Consider a trivial project that `uses` midje: > > >    (ns midje-aot.core > >      (:use midje.sweet)) > > > If it's aot-compiled, everything appears to go well: > > >  

Re: Newbie question on OO/records

2011-11-07 Thread Alan Malloy
Yes On Nov 7, 10:35 am, stevelewis wrote: > So, you can have records in one .clj file and implementations of the > protocols in another .clj file? > > On Nov 6, 1:43 am, Baishampayan Ghose wrote: > > > > > > > > > > Okay, I'm trying to understand records. I read this article: > > >http://freegee

Re: Newbie question on OO/records

2011-11-06 Thread Alan Malloy
On Nov 5, 10:43 pm, Baishampayan Ghose wrote: > > Okay, I'm trying to understand records. I read this article: > >http://freegeek.in/blog/2010/05/clojure-protocols-datatypes-a-sneak-p... > > (Clojure Protocols & Datatypes - A sneak peek by Baishampayan Ghose. I > > found it helpful, but the usage

Re: see if any branch of a cond succeeded

2011-11-05 Thread Alan Malloy
ond (= dir :left) ((move-left)(:ok)) (= dir :up) > >> ((move-up)(:ok)) :else :nok) > > or whatever the exact syntax is > > Am 05.11.2011 08:22, schrieb Alan Malloy: > > > > > > > > > > > On Nov 4, 11:49 pm, Baishampayan Ghose wrote: > >>

Re: see if any branch of a cond succeeded

2011-11-05 Thread Alan Malloy
On Nov 4, 11:49 pm, Baishampayan Ghose wrote: > On Sat, Nov 5, 2011 at 11:55 AM, Martin DeMello > wrote: > > What's the cleanest way to run a piece of code if any branch of a cond > > statement succeeded, without relying on the return value of the > > individual clauses not to be nil? > > > For

Re: -> vs ->> and names vs anonymous function

2011-11-03 Thread Alan Malloy
As a nice result of this, you can easily see what the problem is simply by quoting the form: this resolves reader macros but leaves the form otherwise unevaluated, so you can determine what forms the -> macro is working with: user> '(-> x #(inc %)) (-> x (fn* [p1__4781#] (inc p1__4781#))) user> (m

Re: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Alan Malloy
On Nov 3, 4:18 am, Ben Smith-Mannschott wrote: > On Thu, Nov 3, 2011 at 03:14, Alex Baranosky > > wrote: > > What a coincidence. My instinct would be to make (interleave) return an > > empty seq, instead of nil. I wonder the trade-offs between the two? > > There is no such thing as an empty seq.

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alan Malloy
That's what I get for copy/pasting a link from Google Groups. The real URL for the JIRA ticket is http://dev.clojure.org/jira/browse/CLJ-863 if you'd rather avoid the pointless redirect. On Nov 2, 7:02 pm, Alan Malloy wrote: > http://groups.google.com/group/clojure-dev/browse_thread

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alan Malloy
http://groups.google.com/group/clojure-dev/browse_thread/thread/b81c6c8621629960/b73ed6ba28b60781 http://www.google.com/url?sa=D&q=http://dev.clojure.org/jira/browse/CLJ-863&usg=AFQjCNGcl4S8hvppsmfP8mtjo1W2y5wgfA On Nov 2, 6:28 pm, Alex Baranosky wrote: > Something interesting I've noticed: > >

Re: Datestreams

2011-11-02 Thread Alan Malloy
The call to (set day-nums) should really be pulled out of the inner function to avoid rebuilding the set over and over: (defn day-of-week-stream [& day-nums] (let [day-set (set day-nums)] (filter #(day-set (.. % dayOfWeek get)) (today+all-future- dates On Nov 1, 10:57 pm, Baishampayan G

Re: Confusing interplay between macros and metadata

2011-10-26 Thread Alan Malloy
On Oct 25, 2:27 am, "Marshall T. Vandegrift" wrote: > Alan Malloy writes: > > It seems to me that it would be nice to have macros automatically > > include, on their result forms, the metadata from their input > > &form. Of course, macros may wish to add me

Re: creating a finite sequence of uncertain length

2011-10-25 Thread Alan Malloy
(take-while (complement nil?) (repeatedly myfunc)) On Oct 25, 4:07 pm, rugby_road wrote: > I have a function without arguments which returns a big,complex object > repeatedly until it returns nil.  That is to say that the function > will produce a sequence of objects, but I don't know how many.  

Re: Is there a String protocol?

2011-10-25 Thread Alan Malloy
java.lang.Object.toString On Oct 25, 5:45 am, Sean Devlin wrote: > I was wondering if there was a common protocol to get a string > representation of an object yet.  Also, are there common protocols for > ints, doubles, chars, etc?  Having just spent a lot of time writing > Python, having an int

Re: Get key from map

2011-10-24 Thread Alan Malloy
http://stackoverflow.com/q/7034803/625403 On Oct 24, 2:58 pm, pistacchio wrote: > Hi! Since both (:a {:a 1 :b 2}) and ({:a 1 :b 2} :a) return the > correct value, is there any difference between the two? What is the > preferred form? > > Thanks. -- You received this message because you are subs

Re: Confusing interplay between macros and metadata

2011-10-24 Thread Alan Malloy
 pm, Kevin Downey wrote: > syntax quote effectively does that it, it rewrites your forms as a > series of calls to various sequence functions like concat and in the > shuffling it loses metadata. > > > > > > > > > > On Mon, Oct 24, 2011 at 12:43 PM, Alan Mal

Re: Confusing interplay between macros and metadata

2011-10-24 Thread Alan Malloy
syntax quote issue > > > > > > > > > > On Mon, Oct 24, 2011 at 11:54 AM, Alan Malloy wrote: > > I'm struggling with a basic feature of how macros behave. I understand > > how the > > problem arises, and I can cobble together my own fix in the specific >

<    1   2   3   4   >