drop-while for noobs

2010-08-09 Thread Alan
Hi all, I'm new to the group; I have some experience with both CL and Java, though it's been a while for each. Anyway I really like Clojure as a way of combining the best parts of the two languages, but I'm still getting the hang of it and there are often things that confuse me. For example, I wan

Re: drop-while for noobs

2010-08-09 Thread Alan
Also sorry the indentation is so awful. How do I get Google to let me compose/edit in a fixed-width font? On Aug 9, 12:09 pm, Alan wrote: > Hi all, I'm new to the group; I have some experience with both CL and > Java, though it's been a while for each. Anyway I really like Cloju

Re: drop-while for noobs

2010-08-09 Thread Alan
=> (drop-while neg? [-3 -2 -1 0 1 2 3 ]) > (0 1 2 3) > user=> (class (neg? -5)) > java.lang.Boolean > > On Aug 9, 12:09 pm, Alan wrote: > > > Hi all, I'm new to the group; I have some experience with both CL and > > Java, though it's been a while for eac

Can't get my nesting right

2010-08-10 Thread Alan
I have the following function as part of a card-game system I'm developing: (defn make-suit [suit owner ranks] {suit (map (partial struct-map card :suit suit :owner owner :rank) ranks)}) (make-suit :spad

Re: How to construct Set

2010-08-10 Thread Alan
Depends on what you mean by that. If you mean, create a hashset for use in clojure that will only accept MyType objects, I'll defer to someone here who knows more clojure than I do, though it looks like metadata preconditions are the way to go. If you mean, create a hashset you can pass to Java ob

Re: Eclipse Clojure REPL dies (newbie)

2010-08-10 Thread Alan
Similar experience here. For what it's worth, I found that emacs/swank made my wildest dreams come true - if you're willing to put in the effort to learn emacs, you'll love emacs for clojure as much as you love eclipse for java. On Aug 10, 11:38 am, gammelgedden wrote: > Now we are at  eclipse /

Re: Game development in Clojure

2010-08-13 Thread Alan
Funny you should mention this - I was about to post a question about my own game when I saw your article. My issue is, I assume someone has written minimax and/or alpha-beta pruning in Clojure (or a java library that's easy to interop with). My case is slightly different in that the turn order is n

A useful function?

2010-08-16 Thread Alan
(defn apply-keys [f ks] (zipmap ks (map f ks))) Trivial to write, but it can be quite useful. For example: (defn whatever [arg] (let [some-list (make-list-from arg) mapped (map myfunc some-list)] (zipmap some-list mapped))) compared to (defn whatever [arg] (apply-keys myfunc (m

Trouble upgrading to clojure 1.2

2010-08-16 Thread Alan
t works if I launch it independently of leiningen, with the clj script provided in clojure.contrib. Thanks a bunch, ~Alan -- 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 Not

Re: Trouble upgrading to clojure 1.2

2010-08-16 Thread Alan
Ah, that's all it was. I thought it was available after I saw someone suggest using clojure 1.2. After changing to use RC3, swank (especially swank.core/break) works beautifully. Thanks! On Aug 16, 11:23 am, Saul Hazledine wrote: > Aug 16, 8:03 pm, Alan wrote: > > > >

Re: A useful function?

2010-08-17 Thread Alan
> > > Note that if f is not referentially transparent, you can get different > > results depending on the order in which the collection is traversed, > > for unordered collections. See the API function group-by. It makes > > this behavior explicit by mapping each i

Re: A useful function?

2010-08-17 Thread Alan
utput arguments, in the same order as their corresponding inputs were > > traversed. > > > - Will Morgan > > > On Aug 16, 3:31 am, Alan wrote: > > > > (defn apply-keys [f ks] > > >   (zipmap ks (map f ks))) > > > > Trivial to write, but it can be

Re: Nil Coalesce

2010-08-17 Thread Alan
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 On Aug 17, 1:10 pm, Justin Kramer wrote: > With the precondition that the first collection is a vect

Re: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-18 Thread Alan
The indentation is enough of a hint to get it right. For example, in myfn-a, because you've indented it correctly I can easily tell that (dec b) is the second argument to recur, without looking at the parentheses at all. Isolating close-parens would probably help a little with this task, but the lo

Re: REPL

2010-08-19 Thread Alan
I use Ctrl-D on linux, but Ctrl-C works too, and is what I would try first on Windows. (System/exit 0) won't work if you're using leiningen to get your repl, because it passes I/O through JLine and System.exit terminates the clojure process without notifying the JLine process: $ lein repl user=>

Re: multiplying lists

2010-08-19 Thread Alan
Or if you want to avoid the #(...%...) syntax: user=> (def a (list 1 2 3)) #'user/a user=> (def b (list '(4 5 6) '(7 8 9))) #'user/b user=> (map (partial map * a) b) ((4 10 18) (7 16 27)) On Aug 19, 4:56 pm, Glen Rubin wrote: > I want to multiply a list of n items by h lists of n items, so that

Re: Game development in Clojure

2010-08-20 Thread Alan
or the card game bridge. On Aug 16, 3:08 am, Mike Anderson wrote: > On Aug 13, 5:33 pm, Alan wrote: > > > Funny you should mention this - I was about to post a question about > > my own game when I saw your article. My issue is, I assume someone has > > written minimax

Re: Unsigned-right-shift patch

2010-08-23 Thread Alan
Without commenting on the usefulness of this (it doesn't really interest me), there are a couple style things I would change. First, :added ought to be 1.3 (maybe 1.2?), not 1.0. Second, the newsgroup seems to think that if you're changing clojure.core you might as well update from (. staticMember

Re: trouble using nested map fn

2010-08-23 Thread Alan
Really? I would be interested to hear why; is it maybe because partial has to take any number of arguments and then (apply even? args)? I've taken to using partial when I can, precisely because of the difficulty of nesting anonymous functions, and while performance isn't a big deal for me I'm curi

Re: Clojure 1.3: Integrating clj-stacktrace?

2010-08-25 Thread Alan
I have the same problem, but you can usually figure that out by looking at the function to which the backtrace refers, as well as the filename: 4: clojure.lang.RT.nth(RT.java:722) 5: ddsolve.core$play_deal_strategically.invoke(core.clj:177) 6: ddsolve.core$eval2129.invoke(NO_SOURCE_FILE:1)

Re: Help speed up an inner loop?

2010-08-30 Thread Alan
I think this misses the point. Of course java, c, and clojure will all have roughly the same wall-clock time for this program, since it is dominated by the I/O. You can even see that in the output from $ time java Iterate: less than 0.5s was spent in user space, the rest was spent in system code -

Re: Is "nil" a compile-time literal?

2010-08-30 Thread Alan
That was my first thought too, but (hash nil) is zero. So it doesn't seem like it "should" be caused by that problem. I'm not familiar enough with the internals of clojure.core to follow all of the stuff going on in (source case), but it seems to be using (hash x) rather than (. x hashCode). And (m

Re: reflection warnings with defprotocol/deftype with type hints

2010-08-31 Thread Alan
I haven't quite figured out type hinting either, but here's one thing I realized I was doing wrong that you might want to try. (.length msg) is a reader macro that expands to (. msg length). The docs for the . special form state that if no arguments are provided for an instance member, it is assum

Re: Lisp/Scheme Style Guide

2010-09-01 Thread Alan
I'm afraid if I write my code while this thread is going on, I'll just have to reformat all of it once the discussion has settled this decades-old argument. On Sep 1, 9:45 am, ataggart wrote: > This is so terribly boring.  Don't you guys have any code to write? -- You received this message beca

Re: Why so?

2010-09-03 Thread Alan
A very handy web page to have around; thanks for mentioning it. It looks nice too, but the accessibility is a bit poor - when I look at it with an increased text size, the CSS quickly falls apart and renders it confusing and/or unreadable. So if the maintainer for that site is on this newsgroup som

Re: external clojure lib >

2010-09-07 Thread Alan
You've seen a lot of recommendations for Leiningen. I suggest you try it out: everyone seems to think it will solve your problem (Hint: it will). But even if you have no idea what it is, the fact that everyone is suggesting it means you should try it out before you simply repeat the question you've

Re: A difficult Metaphor for Macros (especially for Java people)

2010-09-08 Thread Alan
This was actually the article that finally got me to overcome the inertia and start exploring lisp, as a long-time native Java speaker. I gave up again in a few weeks, but the possibilities excited me, and when I found Clojure I was delighted with the number of things that were better than lisp, as

Re: Strange bug with mutable fields and try

2010-09-08 Thread Alan
Are you using the release version of 1.2.0? I get the behavior you describe when I use a snapshot of 1.2.0 from when I built from source, but when I use lein repl in a project with a dependency on 1.2.0, all three forms fail with the same exception. On Sep 8, 9:44 am, Nicolas Oury wrote: > Dear a

Simple question about destructuring

2010-09-08 Thread Alan
I happened to be looking at the source for clojure.core/juxt, and I was a little surprised by the way it handles 4+ arguments -- 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

Re: Simple question about destructuring

2010-09-08 Thread Alan
Sorry, Google posted this before I was done. Anyway, it looks like: (defn juxt ([f g h & fs] (let [fs (list* f g h fs)] ...))) Is there a reason to do that instead of the following? (defn juxt ([& fs] ...)) On Sep 8, 11:02 am, Alan wrote: > I happened to be loo

Re: REPL

2010-09-08 Thread Alan
This. And to clarify, in case it's unclear: every function in Clojure must return a value - there are no "void" functions as in Java. print and println, therefore, in addition to printing their data, must return something (they choose nil), and the REPL always prints out the return value of whateve

Re: Improved stack traces

2010-09-09 Thread Alan
I assume I'm just clueless here, but the last commit I see at http://github.com/richhickey/clojure is one from Stuart Halloway in June. Where do I find this so I can try it out? Or, what version do I have to tell leiningen I depend on - 1.2.0-snapshot, 1.3.0-snapshot, or something like that? On Se

Re: drop-while and (pred item) returns nil?

2010-09-09 Thread Alan
I'm not 100% sure what you're asking, but I think I understand you, and in that case you can refer to http://groups.google.com/group/clojure/browse_thread/thread/9c7f726709e24c12/b2e2696b70d924f2?show_docid=b2e2696b70d924f2, in which I ask this very question and get the answers I am looking for. O

Re: Using a keyword as object get method

2010-09-09 Thread Alan
user> (bean (java.io.File. "tmp.txt")) {:path "tmp.txt", :parent nil, :hidden false, :parentFile nil, :canonicalFile #, :freeSpace 0, :absoluteFile #, :class java.io.File, :name "tmp.txt", :absolutePath "/home/akm/src/clojure/ddsolve/tmp.txt", :directory false, :usableSpace 0, :canonicalPath "/home

Re: A Clojure "Scholarship": Let's send Raynes to the Conj!

2010-09-10 Thread Alan
Did we really get this done in an hour? I haven't been part of the community for long, but Rayne has been helpful to me already on #clojure so I was going to donate a bit. Did I already miss my chance? On Sep 10, 10:39 am, Chas Emerick wrote: > With a huge helping hand from Relevance, the host of

Re: Generating functions programmatically

2010-09-10 Thread Alan
I actually did this just the other day, to create a simple C-style enum macro (I assume someone has a better version; this was a learning exercise). You can see my project at www.github.com/amalloy/enum. It sounds like your problem might be constructing the symbol to define; the solution will look

Re: Generating functions programmatically

2010-09-10 Thread Alan
e/= n__1041__auto__ :a))) (.meta (var synthetic-a On Sep 10, 1:02 pm, Alan wrote: > I actually did this just the other day, to create a simple C-style > enum macro (I assume someone has a better version; this was a learning > exercise). You can see my project atwww.github.com/amalloy/e

Re: A Clojure "Scholarship": Let's send Raynes to the Conj!

2010-09-10 Thread Alan
coming in after we hit   > > > our goal, please read the above post anyway. :-) > > > > Thanks again to all! > > > > - Chas > > > > On Sep 10, 2010, at 2:55 PM, Alan wrote: > > > > > Did we really get this done in an hour? I haven't

Re: Generating functions programmatically

2010-09-10 Thread Alan
= kw %)) #'user/make-kw-fn user=> (def kws [:a :b]) #'user/kws user=> (eval (cons 'do (map #(list 'def (symbol (str "test-" (name %))) (make- kw-fn %)) kws))) #'user/test-b user=> (test-b :a) false user=> (test-b :b) true On Sep 10, 1:37 pm, icemaze

Re: Generating functions programmatically

2010-09-10 Thread Alan
PS this is super-ugly and I'm always embarrassed when I find myself using eval in a lisp. While this works, I'd love it if someone could tell me how to do it with macros. On Sep 10, 3:07 pm, Alan wrote: > I see. It's hard to imagine how this could work, since macros don&

Re: Generating functions programmatically

2010-09-10 Thread Alan
underbolt.play> (def a 5) > #'thunderbolt.play/a > thunderbolt.play> (def b 5) > #'thunderbolt.play/b > thunderbolt.play> (ultra-synth "hi" [:a :b]) > #'thunderbolt.play/hib > thunderbolt.play>  (hia 5) > true > > --Robert McIntyre > > On Fri,

Re: drop-while and (pred item) returns nil?

2010-09-12 Thread Alan
eturns nil." + item for which (pred item) returns logical false." {:added "1.0" :static true} [pred coll] On Sep 9, 11:46 pm, Jacek Laskowski wrote: > On Fri, Sep 10, 2010 at 1:08 AM, Alan wrote: > > I'm not 100% sure what you're asking, but I think I u

Re: java interop problem

2010-09-13 Thread Alan
Ranjit, try the following to see it in action even at the REPL: (def xt (make-array Float/TYPE 3 3)) (def myloop (for [x (range 3) y (range 3)] (aset xt x y 1))) (aget xt 1 1) ;; xt hasn't been changed myloop ;; force REPL to de-lazify (aget xt 1 1) ;; changed now On Sep 13, 9:28 am, Mark Nut

Re: java interop problem

2010-09-14 Thread Alan
earing that up for me everyone. So the REPL itself acts > like a consumer of lazy sequences? Is there some logic behind that? I > guess I would have expected that the REPL would just return a > reference to a lazy expression rather than evaluate it. > > Thanks, > > -

Re: java interop problem

2010-09-14 Thread Alan
0 items in the seq ;; evaluating just myvar causes the REPL to realize the whole seq On Sep 14, 9:33 am, Alan wrote: > That would be very awkward: > > user=> (-> (range) (filter even?) (drop 10) (take 5)) > LazySeq > user=> (-> (range) (filter even?) (drop 10) (take 5) fir

Re: var args

2010-09-14 Thread Alan
First, you could use destructuring to make your map function cleaner. The following is exactly identical to your definition. It declares that it will be passed one argument; because that argument is [...], it will be a seq; it asks that the seq be split into y, the first element, and z, a seq of th

Re: ClassCastException: class to interface

2010-09-14 Thread Alan
This is working fine from Clojure. I don't see how you can get help without providing some information about the code you have that isn't working. user> (definterface Printable (print [])) user.Printable user> (definterface User (use [^user.Printable p])) user.User user> (def p (reify Printable (p

Re: simplest graphics?

2010-09-14 Thread Alan
I think you could just keep a vector of (color,shape) pairs as an atom, and reify a subclass of JPanel whose paint() method closes around that atom, calling (.draw shape color). Then as long as you call repaint every time you modify the atom, you should be done. Seems like it's hard to see a librar

Re: var args

2010-09-14 Thread Alan
Great. Looks shiny and idiomatic to me. On Sep 14, 12:06 pm, Michael Ossareh wrote: > Alan and Patrick, thank you so much! I've come across apply in JS and > it really should have clicked for me! > > So I have the following, and it works very well: > > (defn make-tables

Re: simplest graphics?

2010-09-15 Thread Alan
use (list shape-name...), try [shape-name...] -- (defn render-shape [shape-name [x y w h] color]) -- (render-shape 'rect (take 4 (repeatedly #(rand-int 400))) blue) The last two combine to let you avoid writing rand-int so many times. On Sep 15, 5:32 am, Lee Spector wrote: > On Sep 14,

Re: Feature idea: meta-macros

2010-09-15 Thread Alan
My guess is no. It would remove a huge benefit of Clojure, which is that you can tell, without having to look over the whole codebase, exactly what a given form does. (my-thing 20 [x y]) invokes my-thing, a function or macro, with 20 as its first argument, and then a vector of locals. No need to hu

Re: Feature idea: meta-macros

2010-09-15 Thread Alan
Binding uses dynamic scope, not lexical scope, right? So any functions called before the binding expires will be affected by the new bindings, not just the code explicitly within its lexical scope. On Sep 15, 11:35 am, Luke VanderHart wrote: > Unless I misunderstand something, (binding...) wouldn

Re: simplest graphics?

2010-09-16 Thread Alan
pm, Lee Spector wrote: > On Sep 15, 2010, at 1:57 PM, Alan wrote: > > > This looks a lot like what I would do - I'm afraid I don't have any > > brilliant insights for you. I do have a couple ways you could make > > this smaller, though: > > > - Instead

Re: concurrency example about java x clojure

2010-09-20 Thread Alan
A few days ago I was thinking about how different it would be to write flip-map* in Java vs Clojure. A very simple, small program, but easy to see how Clojure can be more expressive. public static Map flipMap(Map map) { Map result = new HashMap(map.size()); for (K key : map.keys()) {

Re: concurrency example about java x clojure

2010-09-20 Thread Alan
ot to add to it. On Sep 20, 9:08 am, Alan wrote: > A few days ago I was thinking about how different it would be to write > flip-map* in Java vs Clojure. A very simple, small program, but easy > to see how Clojure can be more expressive. > > public static Map flipMap(Map map)

Re: concurrency example about java x clojure

2010-09-20 Thread Alan
key) with reverse - not sure if that's more readable, but there's certainly a case for it. On Sep 20, 9:52 am, John Cromartie wrote: > On Sep 20, 12:08 pm, Alan wrote: > > > > > A few days ago I was thinking about how different it would be to write > > flip-map* in J

Re: exception thrown when passing in nil parameter

2010-09-27 Thread Alan
(defn f ([a b c] ...) ([a b c d] (if d ... (f a b c Not the prettiest solution, I'll grant you; I'm sure someone will come along with something better. But this will work. On Sep 27, 11:13 am, Glen Rubin wrote: > I have a function that will accept 3 or 4 parameters.  

Re: Fighting with Emacs ;-)

2010-09-27 Thread Alan
C-c C-k in the .clj buffer is easier and equivalent (or at least very similar) On Sep 27, 12:27 pm, Linus Ericsson wrote: > I recognize that one. The repl haven't loaded the file your editing. > > My (temporary) solution is to do a (load-file "") > after each edit that I want to debug, but that's

Re: Screencast of the Emacs front end to the Clojure Debugging Toolkit:

2010-10-01 Thread Alan
I don't have time to watch the whole thing until I get home from work, but just hearing the first 30 seconds has me drooling all over myself... On Oct 1, 1:32 pm, George Jahad wrote: > For your delectation:http://www.vimeo.com/15462015 -- You received this message because you are subscribed to

Cross-referencing objects?

2010-10-03 Thread Alan
I've got a collection of unique objects, and I need to partition them into sets. That part's easy enough, but I need to have both of the following be efficient, and preferably easy: - Given an object, determine what set it's in - List all the objects in a given set In an imperative language this w

Re: Fighting with Emacs ;-)

2010-10-05 Thread Alan
Hm. How are you connecting to swank? I use M-x slime-connect (then hit yes/ a few times); as soon as that's done, a new buffer with the clojure REPL appears. Then I can switch to it just as with any buffer; C-x C-o or similar. The buffer it creates is called *slime-repl clojure*. That should be all

Re: re-formulating sql statements

2010-10-05 Thread Alan
(use 'clojure.java.io) (require 'clojure.string) (refer 'clojure.string :only [split]) (let [pattern #"case when (\\S+) in \\(([^)]+)\\) then (\\S+) as (\\S +)"] (with-open [sql-in (reader "/path/to/file")] (doseq [line (line-seq reader)] (let [[_ in-str then-str as-str]

Re: re-formulating sql statements

2010-10-05 Thread Alan
) Also it occurred to me that my (split) doesn't handle the commas you have, so the regex should probably be something more like #"[ ,]+" On Oct 5, 2:49 pm, Avram wrote: > Alan, thanks for your response, I'm still new at this.  Running it, > the part with refer had an iss

Re: Newbie - Map to String

2010-10-08 Thread Alan
user=> (use 'clojure.string) WARNING: replace already refers to: #'clojure.core/replace in namespace: user, being replaced by: #'clojure.string/replace WARNING: reverse already refers to: #'clojure.core/reverse in namespace: user, being replaced by: #'clojure.string/reverse nil user=> (join "&" (m

Re: strange bug in range or lazy-seq?

2010-10-11 Thread Alan
I confess I'm a bit baffled by this too, but I have a couple suggestions that don't address your problem :) (drop 2 (range)) is the same as (iterate inc 2), and the same as your convoluted lazy-seq, except that the iterate works here, while for some reason the range doesn't. You might consider ze

Re: Polymorphic functions in Clojure (or how to stop thinking in objects)...

2011-03-15 Thread Alan
On Mar 14, 8:15 pm, Daniel Solano Gomez wrote: > I believe there are two approaches to doing this in Clojure: > > 1. Multimethods:http://clojure.org/multimethods > 2. Protocols:http://clojure.org/Protocols > > Of the two, as of Clojure 1.2, protocols are the preferred way of doing > things.   Wha

Re: Polymorphic functions in Clojure (or how to stop thinking in objects)...

2011-03-15 Thread Alan
draw) color)) > > (defn rotare [shape degrees] >   ((shape :rotate) degrees)) > > And is used like this: > > (def circle (make-circle 5 5 10)) > (draw circle) > > On Mar 15, 9:26 am, Alan wrote: > > > > > > > > > On Mar 14, 7:54 pm, stu wro

Re: Polymorphic functions in Clojure (or how to stop thinking in objects)...

2011-03-15 Thread Alan
On Mar 14, 7:54 pm, stu wrote: > Hi, > > I'd like to create a simple library of drawable shapes: lines, circles > and rectangles.  I've placed each type of shape in its own namespace > with functions that operate on that shape kind: > > (ns myshapes.line) > > (defn line ... creates new line ...) >

Re: Polymorphic functions in Clojure (or how to stop thinking in objects)...

2011-03-15 Thread Alan
On Mar 15, 10:30 am, Daniel Solano Gomez wrote: > In the end, the it all depends on what fits best with what you are > doing.  One approach is to simply avoid using multimethods or > polymorphism as you start developing.  Instead, you can use a custom > dispatch using if or cond in your polymorphi

Re: Polymorphic functions in Clojure (or how to stop thinking in objects)...

2011-03-15 Thread Alan
On Mar 15, 10:50 am, Mark Engelberg wrote: > On Tue, Mar 15, 2011 at 10:40 AM, Alan wrote: > > Seconded. I often know ahead of time I'll want to extend to > > multimethods eventually, but sometimes I don't. Because multimethods, > > protocols, and plain-old-functi

Re: (.contains (transient #{}) 17) ==> true!?!

2011-03-15 Thread Alan
On Mar 14, 2:10 pm, Ken Wesson wrote: > On Mon, Mar 14, 2011 at 4:41 PM, Alan wrote: > > Thanks Ken, I found this too when I saw Tassilo's problem on irc > > (didn't notice it was on ML as well). I was going submit a patch for > > this, but if you've alr

Re: Software Engineering Practices for Marking Algorithms?

2011-03-16 Thread Alan
You are asking on the wrong list. Nobody in the Clojure list will ever tell you that monkey-patching and mutating your data structure is the right approach in order to traverse it. And that's totally fine: ask away, if you're willing to accept other solutions. But you've rejected all ideas aside fr

Re: xml parsing

2011-03-16 Thread Alan
It's one variety of depth-first. Pre-order, post-order, and in-order are all viable ways of doing depth-first searches (though in-order makes less sense for non-binary trees). Assume for the rest of this post the following tree: 1 --2 --3 4 --5 6 --7 - Breadth-first traversal: 1237465

Re: strint and macro expansion

2011-03-17 Thread Alan
On Mar 17, 8:34 am, "Bhinderwala, Shoeb" wrote: ...use the strint *MACRO*... ...works when I specify my string [as a literal]... ...but doesn't work when I pass the string through a variable. Macros are not functions. << is receiving as arguments a list with the two elements 'str and 'q. It must

Re: strint and macro expansion

2011-03-17 Thread Alan
On Mar 17, 11:00 am, Meikel Brandmeyer wrote: > Hi, > > Am 17.03.2011 um 18:11 schrieb Alan: > > > From my uninformed position, strint looks like it should have been > > written as a function, not a macro, but probably there are reasons it > > was not. > > It c

Re: Beginning Clojure

2011-03-22 Thread Alan
http://www.try-clojure.org/ I hear it's not always working, but it seems to be up now. On Mar 22, 4:55 pm, Kyle Cordes wrote: > On Tuesday, March 22, 2011 at 7:16 AM, André Branco wrote: > > Hi! > > > A good collection of resources: > >http://learn-clojure.com/ > > Thanks for the mention (that's

Re: complication using re-gsub having special chars in replacement string

2011-03-22 Thread Alan
$ is a special character in replacements as well, for indicating capturing-subgroups. user> (require '[clojure.string :as s]) nil user> (s/replace "stuff$@stuff" #"\$@" "\\$@sub") "stuff$@substuff" On Mar 22, 8:05 pm, Tim Robinson wrote: > I'm not well versed in regex functions., so I'm probably

Re: Should destructure emit not nthnext, but nthrest?

2011-03-23 Thread Alan
If you don't plan to use the &rest arguments, and in fact don't care about them at all, why are you binding them to something? More importantly, it would make the following idiom a lot more clumsy: (defn sum [list] (let [[x & xs] list] (+ x (if xs (sum xs) 0 Using

Re: Java Interop - Generics - Hmmm...

2011-03-24 Thread Alan
This is only half-true. The data exists somewhere, as Jules says, so that javac can enforce proper use of generics when calling compiled library code. Eg, rt.jar contains only classes, yet j.u.List still manages to have generics, which are treated correctly by the compiler. The *use* of generic cod

Re: Java Interop - Generics - Hmmm...

2011-03-24 Thread Alan
On Mar 24, 9:47 am, Alessio Stalla wrote: > Reflection is aware of generic type > variables:http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Generi... > > What is lost at runtime is information about *instantiation* of those > variables: e.g. you can't distinguish a method returning

Re: Implicit unpacking of a map

2011-03-24 Thread Alan
A macro should work fine if you use ~@ instead of just ~. (defmacro save-article [path form-params timestamp] `(ds/save! (Article. ~path ~@(vals form-params) ~timestamp))) On Mar 24, 1:28 pm, Thorsten Wilms wrote: > On 03/24/2011 05:40 PM, Meikel Brandmeyer wrote: > > > The problem is the

Re: Implicit unpacking of a map

2011-03-24 Thread Alan
I find it easier to write web apps if my users provide me with their inputs at compile time anyway. On Mar 24, 1:45 pm, Meikel Brandmeyer wrote: > Hi, > > Am 24.03.2011 um 21:38 schrieb Alan: > > > A macro should work fine if you use ~@ instead of just ~. > > > (defmac

Re: I understand metadata now!

2011-03-25 Thread Alan
It's already possible, but metadata is the wrong tool. Wrap all return values that "might" have multiple values in a vector, and return/bind as many elements as you want. Add macros to make it less ugly, stir awhile, and you have multiple values. Using metadata for this purpose would have real pro

Re: Random "IllegalArgumentException: No distinct mapping found" after replacing defmultis with protocols

2011-03-25 Thread Alan
That error message is coming from some use of (case), usually in your code but conceivably from somewhere in Clojure. It tries to do some clever bit-fiddling to generate a constant-time-dispatch on the hashcodes of its clauses, and if that fails it throws a compiler error (arguably it could degrade

Re: Generating cross recursive lazy sequences in clojure

2011-03-27 Thread Alan
(1) lazy-cat is old. There's no reason to use it anymore; lazy-seq is better for generating custom lazy seqs, and concat is already lazy. (2) declare is overkill for this; just use letfn and avoid creating a bunch of global functions that nobody else will ever use. On Mar 27, 9:43 am, Christian Sc

Re: Creating an empty string array

2011-03-28 Thread Alan
(into-array String []) (make-array String 0) On Mar 28, 12:58 pm, Konrad Hinsen wrote: > For interfacing with some Java code I need to create an empty string   > array in Clojure. Is that possible somehow? The only way I know to   > create a string array is > >         (into-array ["a" "b"]) > >

Re: Macro compile vs run time, appengine-magic defentity

2011-03-28 Thread Alan
If you need it quoted in the "def" context: (defmacro def-entity-and-attrs [entity-name key attrs-name attrs] `(do (def ~attrs-name '~attrs) (ds/defentity ~entity-name ~(vec (concat ['^:key key] attrs) Note the ' before attrs. PS why is there a ' before ^:key? It doesn't seem to m

Re: fixing web docs

2011-03-29 Thread Alan
My understanding is that it's mostly a hosting problem. I'll ask Raynes about it - the code is mostly his, as I understand it. On Mar 29, 5:08 pm, Sean Corfield wrote: > On Tue, Mar 29, 2011 at 5:00 PM, Ken Wesson wrote: > >> Pointing out try-clojure.org would probably be a good thing there > >>

Re: updating a map value

2011-03-30 Thread Alan
(update-in foo [:a] inc). It also works for nested maps, the same way assoc-in and get-in do. On Mar 30, 10:21 am, Jeff Rose wrote: > Hola, >   I'm looking for a function that updates a map value by calling a > function on it. > > (def foo {:a 1}) > > So instead of this: >   (assoc foo :a (inc (:

Re: from string to keyword?

2011-03-30 Thread Alan
(keyword "abcdef") => :abcdef (defn metric-diff [metric & json-objs] (apply - (map (comp :value (keyword metric)) json-objs))) Probably does what you want. On Mar 30, 12:04 pm, Avram wrote: > hi, > > I have 2 report files in JSON format like below: > > # file 1: a.json > { "abcdef" : { "value

Re: updating a map value

2011-03-31 Thread Alan
On Mar 30, 11:29 pm, Jozef Wagner wrote: > On Wednesday, March 30, 2011 7:29:42 PM UTC+2, Mike Meyer wrote: > > > On Wed, 30 Mar 2011 10:21:41 -0700 (PDT) > > Jeff Rose wrote: > > > > Hola, > > >   I'm looking for a function that updates a map value by calling a > > > function on it. > > > > (def

Re: Basic compilation question

2011-03-31 Thread Alan
You don't actually need to quote class names: (import com.test.Test) works. Of course if you're using the list syntax you do, to avoid calling the package as a function; but you can get around that as well by using a vector if you'd rather not quote: (import [com.test Test OtherTest]) On Mar 31, 5

Re: REPL bug: premature submission hitting enter with unmatched [

2011-04-02 Thread Alan
Works fine for me in slime, came repl, and java -jar clojure.jar. The indentation isn't so hot for the raw repl, but what can you expect? The repl is fine; perhaps you should tell us how you're launching your repl, since that seems to be the source of the problem. ;; TABs added by me - the repl pu

Re: java interop: behaviour of the new function with indirect references to classes

2011-04-02 Thread Alan
(let [c String] (.newInstance c)) If you need to pass arguments to the constructor there's more work to do - check out clojure.lang.Reflector. On Apr 2, 5:53 pm, JonathanBelolo wrote: > Ok, so here's the thing: > > I'd like to keep a reference to a class somewhere, and later retrieve > it to i

Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-03 Thread Alan
Isn't all this just a special case of partition-by? (defn drop-by [f coll] (apply concat (rest (partition-by f coll (defn take-by [f coll] (first (partition-by f coll))) user> (drop-by (partial + 2) [2 2 2 3 3 4]) (3 3 4) user> (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42]) (1 4 1 7

Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-03 Thread Alan
I like your version, Roman. It seems as efficient as anything, and is easy to read. For what it's worth, I'd make a small rewrite: (defn take-by [f coll] (lazy-seq (when-let [[x & xs] (seq coll)] (let [val (f x)] (cons x (take-while (comp #{val} f) xs)) On Apr 3, 5:45 am, Rom

Re: April Showers Bring May Flowers - raindrop advice please

2011-04-03 Thread Alan
I'd write it as (repeatedly num-raindrops #(agent nil)). On Apr 3, 5:27 pm, Sean Corfield wrote: > On Sun, Apr 3, 2011 at 4:31 PM, carinmeier wrote: > >  (let [rainagents (vec (repeat num-raindrops (agent nil)))] > > Wouldn't that create a vector with N copies of the same agent? > > Try: > > (le

Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-04 Thread Alan
Yes. Generally push lazy-seq as high in the chain as you can (but no higher!), for that reason.. On Apr 3, 11:09 pm, Roman Sykora <4rt.f...@gmail.com> wrote: > Thank you for your time and kind answers. I really enjoy reading this > group and the whole clojure community. Enough flattery ;) > > A qu

Re: Protocols and name collisions

2011-04-04 Thread Alan
You can't turn clojure.core/first into a protocol - it's already a bare function. When you define a protocol with a first method, you define a new function in your namespace called first, which delegates to protocol implementations. The compiler is complaining that you're shadowing clojure.core/fir

Re: How to access specific java.awt.Color constructor?

2011-04-09 Thread Alan
You probably weren't putting it into a java float array, but instead a Float array (boxed type). Here's a repl session doing what you want. I don't know anything about colorspaces so it's probably nonsense, but it creates a Color with that constructor. user=> (import '(java.awt.color ICC_Profile C

  1   2   3   4   5   6   7   8   9   10   >