Re: Self-referencing map literals

2009-08-31 Thread Achim Passen
Hi! Am 31.08.2009 um 11:27 schrieb Timo Mihaljov: > I have some code that looks like this: > >(let [radius 20 > diameter (* 2 radius) > circumference (* pi diameter)] > {:radius radius > :diameter diameter > :circumference circumference}) > > I would like t

Re: Symbol to keyword

2009-08-24 Thread Achim Passen
Hi! Am 24.08.2009 um 18:31 schrieb Dragan Djuric: > I needed (and created) a macro to generate keywords from symbols. I > couldn't find anything ready, and I am still not completely > comfortable with the solution I came up with. Any suggestions for > improvement? If I understand you correctly,

Re: Arity count

2009-08-19 Thread Achim Passen
Hi! Am 19.08.2009 um 10:24 schrieb lancecarlson: > Is there a way to introspect a function to get its arity? I know some > functions have an arbitrary amount of arguments, but knowing the count > on finite argument lists and whether or not a function accepts an > infinite list would be very usef

Re: Newbie code review

2009-08-09 Thread Achim Passen
Hi! If you'd like to use relational structures, take a look at clojure.set. There's a couple of functions which let you do relational algebra (project, select, rename, plus some other things like index). Clojure represents relations as sets of maps: (def data #{{:id 0 :name "Fred":age 3

Re: Hash Consing

2009-06-29 Thread Achim Passen
Hi! I think it’s basically a generalized version of this: user> (def hcons (memoize cons)) #'user/hcons user> (identical? (cons 1 nil) (cons 1 nil)) false user> (identical? (hcons 1 nil) (hcons 1 nil)) true In the case of cons, every two equal (value-wise) data structes have the same "construc

Re: Confused about vars, symbols, names,...

2009-03-06 Thread Achim Passen
Hi! > I tried this: (var (symbol name)) > but that caused the exception: clojure.lang.PersistentList cannot be > cast to clojure.lang.Symbol var is a special form. If var was a function, (symbol name) would have been evaluated and the result would have been passed to var as an argument. Spec

Re: Compiling problem.

2009-03-03 Thread Achim Passen
Hi! Are you using the release version from clojure.org? I remember this one having a strange *compile-path* default when started as clojure.main (something like "/Users/rich/..."), but defaulting to "classes" when started as clojure.lang.Repl ... Kind regards, achim Am 03.03.2009 um 22:2

Re: time complexity for immutable priority queue?

2009-03-01 Thread Achim Passen
Hi, that's a nice example of using closures to store data! (f)first and rest look like constant time to me. count is linear time, but could easily be made constant time by storing the counts instead of recursing. Insertion is linear time though, plus it recurses, resulting in stack sizes

Re: Mathy operations on non-numerics

2009-02-27 Thread Achim Passen
Hi! Am 27.02.2009 um 18:03 schrieb Phil Hagelberg: > Agreed. Am curious as to what the idiomatic way to check to see if one > string is alphabetically greater than another is though. "compare" seems to do the right thing in most cases. You could define shorthands if that's too much typing: us

Re: CLOJURE_HOME (was Re: Waterfront - The Clojure-based editor for Clojure)

2009-02-25 Thread Achim Passen
Hi! Am 25.02.2009 um 23:14 schrieb Stephen C. Gilardi: > (If this flies, at some point it would be good to add "contrib" to > the svn-ignore list for Clojure's top level directory so it wouldn't > even show up as an untracked node.) Another way to do this is to add contrib as an svn external

Re: rules for writing macros

2009-02-03 Thread Achim Passen
Hi! Am 03.02.2009 um 17:26 schrieb Mark Volkmann: > On Tue, Feb 3, 2009 at 8:24 AM, Konrad Hinsen > wrote: >> >> On Feb 3, 2009, at 14:49, Mark Volkmann wrote: >> >>> I see from the feedback so far that my statements are wrong. >>> However, >>> I think it's true that there are *some* things y

Re: Alternatives to contains?

2009-01-29 Thread Achim Passen
Hi! Am 29.01.2009 um 23:52 schrieb Mark Volkmann: > I'd like for that to be moved to core so I don't have to load it ... > which is also verbose for something that is commonly needed. "includes?" being commonly needed might indicate that people really should be using sets instead of lists or v

Re: why does this work?

2009-01-23 Thread Achim Passen
Hi Kurt, Am 23.01.2009 um 05:23 schrieb zoglma...@gmail.com: > (defn create-a [firstName lastName] > (defn getFirstName [] firstName) > (defn getLastName [] lastName) > (fn [operator & operands] >(apply operator operands))) It's important to note that, regardless of the lexical context,

Re: How can I find all files ending with .clj, for example

2009-01-08 Thread Achim Passen
On 9 Jan., 03:03, Achim Passen wrote: > (filter #(re-find #".clj$" %) … ) correction: (filter #(re-find #"\.clj$" %) … ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure&q

Re: How can I find all files ending with .clj, for example

2009-01-08 Thread Achim Passen
Hi! (filter #(re-find #".clj$" %) … ) see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html (Boundary matchers) Kind regards, achim On 9 Jan., 02:39, wubbie wrote: > thanks, > > Is there anyway to specify regular expression, instead of startsWith/ > endsWith? > -sun > > On

Bug? overflow check in Numbers.minus

2009-01-08 Thread Achim Passen
Hi all! I encountered some corner cases where overflow checking for "-" doesn't work as I would expect: user=> (- Integer/MAX_VALUE Integer/MIN_VALUE) -1 user=> (- Long/MAX_VALUE Long/MIN_VALUE) -1 The problem seems to be that negating MIN_VALUE yields MIN_VALUE again, so it slips through t

Re: Modulo

2008-12-29 Thread Achim Passen
Hi! I uploaded my attempt at this to the files section of this group: http://clojure.googlegroups.com/web/mod-sgn.diff It adds the modulus operator plus, as a by-product, the signum operator (sgn). Comments most welcome! Kind regards, achim On 29 Dez., 07:01, Rich Hickey wrote: > On Dec

Re: classpath problem on MacOSX

2008-10-28 Thread Achim Passen
Ah, Java's classpath handling - a constant source of delight. Using $CLASSPATH is not a reliable way of adjusting your classpath, because its contents will only be considered if you don't specifiy anything else on the java command line, i.e. if you start clojure like this $ java -cp

Re: destructuring/multimethods vs. pattern matching

2008-10-20 Thread Achim Passen
Hi Stuart, Am 20.10.2008 um 20:00 schrieb Stuart Halloway: > Nice--I like this one, except for needing to apply. What I really want > is arity overloading *within* the first argument, which is what led me > down the path to multimethods. Yes, sadly arity matching is only available at the top le

Re: destructuring/multimethods vs. pattern matching

2008-10-20 Thread Achim Passen
Hi! Here's a variadic version: (defn qsort ([] []) ([x & xs] (concat (apply qsort (filter #(< % x) xs)) (cons x (apply qsort (filter #(>= % x) xs)) user> (qsort 1234 56 789 0) (0 56 789 1234) Kind regards, achim Am 2

Bug? Strange set equality (r1075)

2008-10-19 Thread Achim Passen
Hi, user> (= #{1 4} #{2 3}) true it's not, is it? Kind regards, achim -- http://rauschabstand.twoday.net --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group

Re: Lazy step ...

2008-10-19 Thread Achim Passen
Hi Steve, thanks for your answer! Am 19.10.2008 um 17:13 schrieb Stephen C. Gilardi: > That looks strictly better than the other examples to me. If you're > willing and if you send a Contributer Agreement to Rich, I'd like to > adopt it in clojure.contrib.lazy-seqs. In the meantime, the wik

Lazy step ...

2008-10-19 Thread Achim Passen
... is not some new form of dance music from the UK, but what appears to be a recurring - dare i say - pattern in the definition of lazy sequences: the combination of lazy-consing and a step function. There are plenty of these in boot.clj and in contrib's lazy-seq.clj. Here's an example (po

Re: Casting java arguments...

2008-10-16 Thread Achim Passen
Hi, Am 17.10.2008 um 03:12 schrieb Luc Prefontaine: > This means that (clojure.lang.RT/classForName > "com.mysql.jdbc.Driver") has no effect on the static code in the > class. You're right, RT/classForName doesn't do initialization. Does this work for you?: (Class/forName "com.mysql.jdbc

Re: remainder function

2008-10-15 Thread Achim Passen
Hi, Am 15.10.2008 um 23:35 schrieb Islon: > Is there a remainder (rest of the division) function in closure? (as > java '%' operator). > I browse the docs but couldn't find one. clojure/rem ([num div]) rem[ainder] of dividing numerator by denominator. I ran into the same problem some time

patch: "no matching ctor" exceptions tell class name

2008-10-12 Thread Achim Passen
Hi! Here's a tiny bit of error message cosmetics i just added while debugging some code. Maybe it's a useful addition. Kind regards, achim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Bug in r1057? Var reader macros in syntax quotes

2008-10-10 Thread Achim Passen
Hi! There seems to be a problem with the new LispReader$VarReader: ; r1057 user=> `#'clojure/doc java.lang.UnsupportedOperationException: Vars are not values (NO_SOURCE_FILE:0) ; r1056 user=> `#'clojure/doc (var clojure/doc) This only happens for bound Vars, which are no longer wrapped when re

Re: Patch: java.util.Map support

2008-09-30 Thread Achim Passen
Am 30.09.2008 um 17:20 schrieb Paul Barry: > On Sep 30, 11:17 am, Rich Hickey <[EMAIL PROTECTED]> wrote: >> I've been thinking about this Map vs Collection issue for a while now >> and am considering making the move to: Clojure maps implement Java >> Map. > > Yes, please do! +1! Yes, that’s muc

Re: Patch: java.util.Map support

2008-09-30 Thread Achim Passen
On Sep 30, 5:20 am, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > After some more thought, I'm not sure whether this should be a concern   > or not. Since jmap's purpose is to wrap Clojure maps for passing to   > Java APIs, I'm not sure when it will be necessary to compare jmaps to   > Clojur

Re: Patch: java.util.Map support

2008-09-30 Thread Achim Passen
e have now implement this. I think it's very   > important that jmap fit in with that definition of "=". > > What prevents jmap from participating in this same check? If there are   > more changes to existing Clojure code that are necessary to support   > this, I think

Patch: java.util.Map support

2008-09-29 Thread Achim Passen
Hi! Here's a patch to add java.util.Map support to clojure maps, along with some example code. This my first java code in quite some time, so if you notice i'm doing anything odd or incorrect, please don't hesitate to comment. http://groups.google.com/group/clojure/web/jmap.diff http://groups.go

Re: Get the time of next Friday noon

2008-09-06 Thread Achim Passen
Hi Mathias, Perhaps this saves you some typing with field accessing: (defn fields-map "Returns a hash map with all field values of o" [o] (apply hash-map (mapcat #(list (keyword (.getName %)) (.get % o)) (.getFields (class o) Use like this to co

Re: Local recursive lazy sequences

2008-09-01 Thread Achim Passen
Hi Mike, thank you for your reply! On Sep 1, 3:15 pm, "Michael Reid" <[EMAIL PROTECTED]> wrote: > (defn fib [n] >   (let [fibs2 (fn fibs2 [] (lazy-cat '(0 1) (map + (fibs2) (drop 1 > (fibs2)] >     (nth (fibs2) n))) Dodgy. ;-) I wasn't aware of named anonymous fns – nice. But i suspect di

Local recursive lazy sequences

2008-09-01 Thread Achim Passen
Hi! Is there a way to have locally bound recursive lazy sequences in Clojure? I'd like to define a function that uses a lazy seq as an interim result, so i wouldn't want to use a top-level def. I'll try to give a short example. You can define the sequence of fibonacci numbers lazily-recurs