Re: best way to make use of association lists

2009-09-07 Thread John Harrop
On Mon, Sep 7, 2009 at 5:19 PM, Conrad wrote: > Alternatively, I suppose it would be possible to create a new type of > map that performs better than an alist but can return items in the > order they were added to the list, if desired Or use an existing type: the java.util.LinkedHashMap. The do

Re: minor grievance with arithmetic on characters

2009-09-09 Thread John Harrop
On Tue, Sep 8, 2009 at 8:18 PM, Timothy Pratley wrote: > > Hi Steve, > > I find the -1, 0, 1 result more useful, but am also wary it hides some > useful information. My preference would be to have the doc-string > changed to what you proposed and keep the neg/pos behaviour > of .compareTo in place

Re: Ensure and STM: find the bug...

2009-09-17 Thread John Harrop
On Thu, Sep 17, 2009 at 11:04 AM, Mark Volkmann wrote: > On Thu, Sep 17, 2009 at 9:57 AM, Chouser wrote: > > > > On Thu, Sep 17, 2009 at 12:28 AM, Krukow wrote: > >> > >> Final question. The docs say that 'ensure' permits more concurrency > >> than promoting the ref to a write. Is there a quick/

Re: Ensure and STM: find the bug...

2009-09-17 Thread John Harrop
Don't commutes commute with one another, but not with other writes? --~--~-~--~~~---~--~~ 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 ne

Re: Redefining Special Forms

2009-09-17 Thread John Harrop
On Thu, Sep 17, 2009 at 2:49 PM, Stuart Sierra wrote: > > On Sep 17, 12:40 pm, Gorsal wrote: > > Oh. And just as a quick other question, do global bindings affect > > threads which are started in the same ns? > > I think threads inherit the bindings in effect when they are created. http://cloju

Re: Anyone care to defend/comment some points in this presentation

2009-09-17 Thread John Harrop
On Thu, Sep 17, 2009 at 3:06 PM, Mark Volkmann wrote: > > On Thu, Sep 17, 2009 at 1:43 PM, z5h wrote: > > > > Specifically some problems encountered in Clojure's STM and bytecode > > generation. > > > > > http://www.azulsystems.com/events/javaone_2009/session/2009_J1_JVMLang.pdf > > (Slide's 8 an

Re: Redefining Special Forms

2009-09-17 Thread John Harrop
On Thu, Sep 17, 2009 at 6:15 PM, Gorsal wrote: > Or maybe i could simply push to the global var and in addition to the > value use a unique gensymed id. Then once the local binding was done > it would pop until it sees its gensymed id. That would work in the > situation that a local binding faile

Re: Anyone care to defend/comment some points in this presentation

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 8:34 AM, Mark Volkmann wrote: > On Thu, Sep 17, 2009 at 5:22 PM, John Harrop wrote: > > On Thu, Sep 17, 2009 at 3:06 PM, Mark Volkmann < > r.mark.volkm...@gmail.com> > > wrote: > >> > >> On Thu, Sep 17, 2009 at 1:43 PM, z5h wrote

Re: problem with threading and sql lib

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 1:32 PM, rogergl wrote: > The problem is that the above code only works if I establish a > connection outside the handle-client function. Otherwise the first > reply to my client gets lost. > > Has anyone an explanation for this ? Are you opening something, using it to r

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 4:39 PM, Tassilo Horn wrote: > Although that doesn't really help, the normal `reduce' doesn't do > better. > > (reduce + (take 100 (iterate inc 1))) ; works > (reduce + (take 1000 (iterate inc 1))) ; OutOfMemoryError Are you sure? I'd expect that with (def integ

Re: Silly Convention Question

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 4:45 PM, CuppoJava wrote: > Hi, > After I shot myself in the foot again this morning by naming one of my > variables "cond" and then wondering why Clojure was complaining about > a simple cond form, I thought why don't we have capitalization > conventions that differ betwee

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread John Harrop
On Fri, Sep 18, 2009 at 3:52 PM, Patrik Fredriksson wrote: > > Hi! > > Could someone please help me understand why the following causes a > java.lang.OutOfMemoryError: Java heap space for large n:s (10 > works fine, 100 does not). > > (def integers (iterate inc 1)) > > (defn limited-reduce

Re: problem with threading and sql lib

2009-09-19 Thread John Harrop
On Sat, Sep 19, 2009 at 1:07 AM, Roger Gilliar wrote: > > Hi, > > > re you opening something, using it to return a lazy sequence, and > > then closing it before consuming the sequence? > > > No. I started with just opening the database connection in the handler > function. You mention threading

Re: problem with threading and sql lib

2009-09-19 Thread John Harrop
Nothing leaps out at me as a likely cause of a dropped message. OTOH, the loop/recur at the end is probably better changed to a doseq. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this gr

Re: Q: why doesn't this script terminate

2009-09-21 Thread John Harrop
On Mon, Sep 21, 2009 at 2:22 PM, Richard Newman wrote: > > > But this script doesn't terminate. I have to press ctr-c to end this > > script. It seems that there a still some threads active. why ? > > http://www.mail-archive.com/clojure@googlegroups.com/msg13865.html Your response was longer th

Re: Namespace/class visibility in eval

2009-09-22 Thread John Harrop
On Tue, Sep 22, 2009 at 6:46 PM, Eric Tschetter wrote: > If I do just > > curl 'http://localhost:43034/1.0/cloj' -H 'content-type: > application/clojure' -d '(json-str {:howdy ["hi" 1 2 3]})' > > I get this exception > > java.lang.Exception: Unable to resolve symbol: json-str in this > context (N

Re: Namespace/class visibility in eval

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 8:50 AM, Philipp Meier wrote: > On 23 Sep., 03:26, John Harrop wrote: > > But, this looks like a gaping security hole. You're taking an HTTP POST > > request body and eval'ing it. Someone will, sooner or later, try typing > > "(delete

Re: trouble running clojure.test

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 12:29 PM, MarkSwanson wrote: > Environment: vimclojure-2.1.2. clojure from git as of a few days ago. > > Running the tests in a plain REPL from the command line worked > perfectly! > -=* THANKS GUYS !!! *=- > > I wasn't expecting this at all. I thought the REPL in vimclojur

Re: Getting REPL transcript

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 12:40 PM, Michael Wood wrote: > 2009/9/23 Phil Hagelberg : > > > > Emeka writes: > > > >> I would like to have a transcript of Repl. Could someone help me out > here? > > > > Sure; run it in GNU Screen with logging turned on. > > > > $ screen -l > > $ rlwrap java -cp cl

Re: Getting REPL transcript

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 1:05 PM, Fogus wrote: > If you're running it with JLine, then the transcript is usually stored > in ~/.jline-clojure.lang.Repl.history Actually, that suggests a more general point: that we can have programmatic access to the REPL's backlog if we modify the REPL process's

Re: question regarding agents

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 4:18 PM, Roger Gilliar wrote: > I have the following code: > > (defn handle-client [in out] >(binding [ >*in* (reader in) >] >(with-connection db >(let [outstream (agent (writer out))] >

Re: Catching from Eval

2009-09-23 Thread John Harrop
On Wed, Sep 23, 2009 at 6:42 PM, Phil Hagelberg wrote: > What's going on here? The exception is being transformed. Eval and just about anything using closures -- just about any delayed evaluation, in other words -- wraps exceptions in RuntimeException for some reason. Even if they already were

Re: Macros, namespaces, and lexical scope

2009-09-25 Thread John Harrop
On Fri, Sep 25, 2009 at 4:49 PM, Constantine Vetoshev wrote: > (let [f1 #(inc %)] > (defmacro m1 [x] >`(~f1 ~x))) > > (m1 12) > => No message. > [Thrown class java.lang.ExceptionInInitializerError] > > The equivalent works in Common Lisp (Allegro CL and SBCL): > > (let ((f1 (lambda (y) (1+ y

Re: Macros, namespaces, and lexical scope

2009-09-25 Thread John Harrop
On Fri, Sep 25, 2009 at 8:48 PM, Constantine Vetoshev wrote: > > On Sep 25, 6:02 pm, John Harrop wrote: > > I don't think you can use things like defmacro in a let. > > This works: > > (let [y 10] > (defmacro m1 [] >`(list ~y))) > > (m1) => &g

Re: Mocking?

2009-09-27 Thread John Harrop
On Sun, Sep 27, 2009 at 8:06 PM, Stuart Sierra wrote: > On Sep 27, 12:55 am, Mark Derricutt wrote: > > How are people handling mocking/stubbing in clojure? Google finds me > some > > old posts about a called? function/macro as part of test-is which looks > like > > it'd do what I need but I can'

Re: how to understand macro in clojure?

2009-09-29 Thread John Harrop
On Mon, Sep 28, 2009 at 5:23 AM, Jarkko Oranen wrote: > What happens is, when you call (mfloat + 1 2) the macro evaluates ('+ > (float 1) (float 2)), ie. it calls the *symbol* + with parameters 1.0 > and 2.0. Symbols, when used as functions, look themselves up in > whatever associative thing you

Re: Mocking?

2009-09-29 Thread John Harrop
On Mon, Sep 28, 2009 at 9:20 AM, Laurent PETIT wrote: > 2009/9/28 C. Florian Ebeling >> >> > In Java I'd just have an interface >> > with two implementations, and bootstrap the tests with a different >> > implementation, in clojure I guess I'd do something like: >> > (in-ns `some.thing) >> > (def

Re: ClojureCLR installation?

2009-09-30 Thread John Harrop
On Tue, Sep 29, 2009 at 7:21 PM, David Miller wrote: > Mono: > - One BigDecimal implementation away from getting serious about > this. Why doesn't Mono have a BigDecimal analogue? It shouldn't, in principle, be difficult to create an open-source-friendly implementation backed by GMP. --~--~-

Re: Problem using shell-out in Windows command prompt

2009-10-01 Thread John Harrop
On Thu, Oct 1, 2009 at 1:39 PM, Nick Day wrote: > > Hey, > > I've just been trying to run a couple of simple commands using shell- > out (e.g. (sh "dir")) in a repl in Windows command prompt, but am > running up against errors of the type > > java.io.IOException: Cannot run program "dir": CreateP

Re: Citing clojure

2009-10-01 Thread John Harrop
On Thu, Oct 1, 2009 at 3:42 PM, Dragan Djuric wrote: > > I usualy cite Rich's conference paper and Stuart's book. > > @conference{hickey2008clojure, > title={{The Clojure programming language}}, > author={Hickey, R.}, > booktitle={Proceedings of the 2008 symposium on Dynamic languages}, > yea

Re: server-socket on exit event

2009-10-01 Thread John Harrop
On Thu, Oct 1, 2009 at 4:02 PM, Roger Gilliar wrote: > Am 01.10.2009 um 21:28 schrieb ngocdaothanh: > > Roger, your code is not event based. > What do you mean by not event based ? He means he wants automatic notification if a connection is dropped. I'm not sure TCP/IP has a native facility fo

Re: apply for macros?

2009-10-03 Thread John Harrop
In the specific cases of "and" and "or", I made utility functions that do non-short-circuiting "and" and "or" for use with "apply" and a stream of boolean data. (Not sure which implementation is more efficient though: a version that returns its argument with one argument, punts to the appropriate m

Re: apply for macros?

2009-10-04 Thread John Harrop
On Sat, Oct 3, 2009 at 6:50 PM, b2m wrote: > > What macros do y'all have that you want to "apply" things to? > (defn init-funs [name & levels] > (do >(apply-macro create-department-struct name levels) >(apply-macro create-process-department name levels) >nil)) > > A call like > (ini

Re: On

2009-10-05 Thread John Harrop
On Sun, Oct 4, 2009 at 4:41 PM, samppi wrote: > > I want to do this: > > (defn a ...) > (cache a) ; or (cache #'a) or (cache 'a); it doesn't matter to me > > ...instead of this: > > (def a (memoize (fn ...))) > > That way, it separates the concern of what a does from the > optimization I'm doi

Re: apply for macros?

2009-10-05 Thread John Harrop
On Mon, Oct 5, 2009 at 2:38 PM, Meikel Brandmeyer wrote: > Hi, > > Am 05.10.2009 um 19:29 schrieb cody koeninger: > > Here we have the smell! You cannot define functions with a function. >>> You have to use a macro! >>> >> >> I am not clear on what you mean by this. From a user's point of view,

Re: Agent send-off: ~20k/s

2009-10-05 Thread John Harrop
On Mon, Oct 5, 2009 at 11:51 AM, MarkSwanson wrote: > On Oct 5, 2:45 am, ngocdaothanh wrote: > > I think it is not "spawn about 20K agents / second", it is 20K message > > passings / second. The number is about that of Erlang. > > As Clojure uses a thread pool for agents I agree 'spawn' was the w

Re: immutable defs?

2009-10-07 Thread John Harrop
On Tue, Oct 6, 2009 at 9:14 PM, Stephen C. Gilardi wrote: > `(do (set-validator! (defvar ~name ~init) #{~init}) (var ~name))) > Cute hack. Won't work if init is false or nil, though, unless the validator does not trigger on the initial assignment of the value. --~--~-~--~~--

Re: Another defmult VS defn query

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 10:25 AM, Robert Stehwien wrote: > (defn mv2 [from to] > (let [f (if (= (class from) File) from (File. from)) > t (if (= (class to) File) from (File. to))] > (println "transformed to File"))) > ITYM t (if (= (class to) File) to (File. to))] for that

Re: What does this error mean?

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 9:38 AM, kunjaan wrote: > > java.lang.ClassFormatError: Unknown constant tag 52 in class file > queries__init (Trial.clj:0) It seems to be an infrequently-encountered bug in load-file. If you copy and paste the source code into the REPL and hit enter, it will evaluate the

Re: What does this error mean?

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 11:09 AM, Mark Tomko wrote: > Can you give some more context? The pesky thing about that particular error is that there IS no more context; it fingers no specific line of code, function definition, or whatever as culprit. --~--~-~--~~~---~--~-

Re: Agents for managing threads

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 1:06 PM, Laurent PETIT wrote: > So I don't think you need this message-queue at all (or maybe I haven't > understood what it is or I'm mislead by its name), send directly your order > to the agent as what you want to change in its state. You might be able to do better than

Re: Agents for managing threads

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 7:49 PM, John Harrop wrote: > You might be able to do better than that, and dispense entirely with the > separate polling thread. > Confirmed: (def x (agent {:polling false :message "foo"})) (defn poll [m] (when (:polling m) (prn (:message m)

Re: Agents for managing threads

2009-10-10 Thread John Harrop
Here is a quickie "library" for abstracting this: (defn make-actor [f period-in-ms & initial-state] (agent (into [f period-in-ms false] initial-state))) (defmacro actor "Creates and returns a new, initially-sleeping actor with the specified period, initial parameter values, and code to execute

Re: Agents for managing threads

2009-10-10 Thread John Harrop
On Sat, Oct 10, 2009 at 5:52 PM, Raoul Duke wrote: > > > The actor itself is > > an agent wrapping a vector with the function, period, awake flag, and > > current parameters. > > will actors actually do the queued function w/in a reasonable > timeframe? i don't think there are any guarantees of i

Clojure persistent immutable priority queue and jobs.

2009-10-11 Thread John Harrop
I've implemented a Clojure persistent, immutable priority queue data structure (built on a heap, in turn built on a Clojure vector). The namespace below exports the heap operations as well as the priority queue operations in case that's useful. These operations return a new data structure instead o

Re: Odd ns metadata compile error

2009-10-11 Thread John Harrop
It's attempting to attach the metadata to the next following expression. In this case all it finds is a close paren. => (list #^{:foo 'bar} 'sym) (sym) => (list #^{:foo 'bar}) # I'm not sure how to attach metadata to a namespace, but I'd try putting the metadata before the (ns ...) form instead of

Re: Agents for managing threads

2009-10-11 Thread John Harrop
On Sun, Oct 11, 2009 at 5:28 PM, Raoul Duke wrote: > >> will actors actually do the queued function w/in a reasonable > >> timeframe? i don't think there are any guarantees of it so if one is > >> hoping to get really nicely periodic behaviour... just curious because > >> i'd thought of using age

Re: Proposal: New Reader Macro #s{ ... }

2009-10-11 Thread John Harrop
How about borrowing a page from LaTeX? That has a \verb+text+ which can use any desired delimiter character. My thought is to have something like $+.+ turning whatever was between the character following $ (here, +) until the next occurrence of that character into a literal string. A way to esc

Re: Duplicated keys in maps

2009-10-11 Thread John Harrop
On Sun, Oct 11, 2009 at 8:55 PM, Angel Java Lopez wrote: > Hi people! > > I just discovered that maps support duplicated keys: > > user=> {:a 1 :b 2 :a 3} > {:a 1, :b 2, :a 3} > > It was not clear to me, from documentation. I presumed that maps are like > dictionaries. > > What is the rationale be

Re: Is there a standard function transforming a map's vals

2009-10-11 Thread John Harrop
On Sun, Oct 11, 2009 at 3:17 PM, Daniel Werner < daniel.d.wer...@googlemail.com> wrote: > On Oct 11, 6:02 am, samppi wrote: > > Oops, you're right; I was thinking about something else. And I have > > another mistake in my function too—I meant: > > > > (defn transform-map [f a-map] > > (into

Re: Agents for managing threads

2009-10-12 Thread John Harrop
Thanks. --~--~-~--~~~---~--~~ 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 moderated - please be patient with your first

Re: Proposal: New Reader Macro #s{ ... }

2009-10-12 Thread John Harrop
On Mon, Oct 12, 2009 at 4:21 PM, Greg wrote: > My only concern, and perhaps John could elaborate on this because he > touched on it, would be how are Java nested classes protected from > this? Wouldn't it interfere with them? Or will the delimiters be > restricted to non-alphanumeric characters?

Re: Dynamically building and evaluating s-expressions from Java

2009-10-12 Thread John Harrop
On Mon, Oct 12, 2009 at 5:10 PM, Garth Sheldon-Coulson < garth.sheldoncoul...@gmail.com> wrote: > Rich wrote somewhere that he wanted to make it possible for Java > applications to build Clojure s-expressions dynamically and pass them to an > embedded Clojure compiler/evaluator. > > I'm not talkin

Re: Dynamically building and evaluating s-expressions from Java

2009-10-12 Thread John Harrop
On Mon, Oct 12, 2009 at 6:55 PM, Garth Sheldon-Coulson wrote: > Yes, but for present purposes I'm stuck in Java proper. > > I'll try using Clojure's compile to build a Java class with a method that > builds an s-expression based on its arguments and evals it. If this works it > will be simpler th

Re: Agents for managing threads

2009-10-13 Thread John Harrop
On Tue, Oct 13, 2009 at 7:24 AM, Robert Stehwien wrote: > John, > > Excellent "library" I'm pulling this into my utilities functions ... with > proper attribution of course and as long as you don't mind. It is just too > useful to me to not keep around. Thanks. Consider any code I post here to

Re: Duplicated keys in maps

2009-10-13 Thread John Harrop
On Tue, Oct 13, 2009 at 12:35 PM, Stuart Sierra wrote: > On Oct 11, 11:17 pm, John Harrop wrote: > > > I just discovered that maps support duplicated keys: > > I suspect it's a bug. > > It's been discussed on IRC and declared not a bug. It's officially &g

Re: Finding elements in 2 sequences that match (indexwise)

2009-10-14 Thread John Harrop
On Wed, Oct 14, 2009 at 2:06 AM, Mark Tomko wrote: > > This is basically a problem of parallel iteration. I've devised 2 > solutions, one is recursive (alas, not tail-recursive) and the other > appears to be a more idiomatic Clojure solution. Can someone suggest > a more efficient or cleaner so

Re: Flags, binding, and laziness, oh my!

2009-10-14 Thread John Harrop
Are the options changed between generating the lazy sequences and realizing them? If not, you can just ignore this issue. Otherwise, Meikel has some suggestions. Another is to give up laziness if you don't really need it: wrap the sequences in doall when returning them out of your API. --~--~-

Re: Finding elements in 2 sequences that match (indexwise)

2009-10-14 Thread John Harrop
On Wed, Oct 14, 2009 at 10:42 AM, Mark Tomko wrote: > > Thanks, this was very helpful. You're welcome. Just to follow up on a few things - by SICP, do you mean the book > "Structure and Interpretation of Computer Programs"? That's the most > likely match I could find. I'm not familiar with th

Re: Compilation with Java class files

2009-10-14 Thread John Harrop
On Wed, Oct 14, 2009 at 3:31 PM, Laurent PETIT wrote: > Oh, and that's one of the main reasons why I think it's best to have our > ccw compiler in a separate jvm : not unexpectedly crashing the host Eclipse > if some code like this arises in user code or libraries imported by user > code :-) >> >>

Re: Clojure's 2nd Birthday!

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 1:35 AM, Mark Engelberg wrote: > > Uh oh, time for the "terrible twos". Who wants to throw the first tantrum? > :) Didn't Wrexsoul already do that a few months ago? --~--~-~--~~~---~--~~ You received this message because you are subscribe

Re: let-while

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 7:58 PM, mbrodersen wrote: > > Hi, > > I am new to Clojure and I am wondering if there is anything similar to > the following macro already built in: > > (defmacro let-while >"Makes it easy to continue processing an expression as long as it is > true" >[[nam

Re: let-while

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 8:12 PM, John Harrop wrote: > (defmacro let-while > "Makes it easy to continue processing an expression as long as it > is true" > [[name expr] & forms] > (let [n# ~name] > `(loop [] >(let [~n# ~expr] >

Re: -> vs comp

2009-10-16 Thread John Harrop
On Fri, Oct 16, 2009 at 11:55 PM, samppi wrote: > Don't forget about the third piece of the puzzle, #() (and fn). > Whenever I need to create a function using ->, I just do #(-> % ...). > It's about as much typing as (comp ...). > > Personally, I can go either way—I just kind of wish that there w

Re: clojure.test hang testing agent

2009-10-16 Thread John Harrop
On Sat, Oct 17, 2009 at 12:51 AM, Robert Stehwien wrote: > I'm using the clojure-maven-plugin v1.1 (latest shapshots of clojure and > clojure-contrib) to run a test for an agent > ... > All the tests run, complete, and report back their status but then the > build freezes until I hit ctrl-c J

Re: let-while

2009-10-17 Thread John Harrop
On Sat, Oct 17, 2009 at 3:32 AM, Timothy Pratley wrote: > > > But name is multiply evaluated. This might be preferable: > > Hi John, > > Could you explain this a bit more for me? I can understand if the > condition is duplicated that is unnecessary calculation but don't > appreciate the issue with

Re: let-while

2009-10-17 Thread John Harrop
On Sat, Oct 17, 2009 at 2:27 PM, Christophe Grand wrote: > (defmacro while-let > "Makes it easy to continue processing an expression as long as it is true" > [binding & forms] > `(loop [] > (when-let ~binding >~...@forms >(recur > This does look like the best implemen

Re: Dedicated thread for agent or creating thread pool for agent?

2009-10-17 Thread John Harrop
Does SWT have no equivalent of SwingUtilities.invokeLater? --~--~-~--~~~---~--~~ 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

Re: Printing to *out* in another thread

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 2:04 AM, Gorsal wrote: > > I just tried this on the eclipse clojure repl, it works. So i guess it > is an enclojure thing! (.println System/out "HI") also doesn't work on > the netbeans repl, but does on the enclojure. I'll ask on the > enclojure mailing group. Thanks for t

Re: Using 'future' ?

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 5:59 PM, Gorsal wrote: > > I'm attempting to use the function future to start something in > another thread. However, in the netbeans enclojure plugin, when i type > it into the repl, it becomes non-responsive. Is this just a bug in the > enclojure plugin or would this be

Re: Using 'future' ?

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 10:22 PM, Gorsal wrote: > > Hey, is there any way to separate the out view from the repl view so i > don't have to switch back and forth? > In Enclojure? Unfortunately, apparently not. It's possible to undock the REPL and make it a free-floating window, but all three of th

Re: Using 'future' ?

2009-10-18 Thread John Harrop
On Mon, Oct 19, 2009 at 12:39 AM, Gorsal wrote: > > So now that the future is working, I'm attempting to print from an > actual java thread. Like this > > (defmacro with-thread [nm & body] > `(let [thread# (Thread. #(fn [] (do ~...@body)))] > ~@(if nm `((.setName thread# ~nm))) > (.start

Re: Beginner: performance of vector creation/"modification"

2009-10-19 Thread John Harrop
On Mon, Oct 19, 2009 at 4:05 PM, Danny Woods wrote: > The only thing that I can see that would speed up set-flags would be to not > take the length of the vector on every iteration: I suspect that may involve > a traversal of the vector every time it's called. > With an abstract list/seq that wo

Re: Redirecting Output

2009-10-20 Thread John Harrop
On Tue, Oct 20, 2009 at 12:07 AM, Alex Osborne wrote: > Gorsal wrote: > > However, this raises the CPU to about 50 percent. This is due to the > > infinite recursion, I'm assuming? > > Yes, it's because you're tight looping, checking to see if data is > available as fast as possible. A quick and

Re: Best way to run multiple filters on the same [lazy] collection?

2009-10-20 Thread John Harrop
On Tue, Oct 20, 2009 at 7:40 PM, Dmitry Kakurin wrote: > P.S. Why does it take almost 2 DAYS for my messages to appear in this > group? I've sent two last messages on Sunday afternoon. It's to keep out spam. Posts from new users are held for manual approval, until they've made a few posts none o

Re: Best way to run multiple filters on the same [lazy] collection?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 1:20 AM, Meikel Brandmeyer wrote: > >>>(repeat (count filters) []) > > Should I wrap it in (vec ...) or is there a better way? > > repeat, map, filter, cycle, take, iterate, etc. are all sequence > functions. They will turn their argument into sequence (via seq) and >

Re: Neophyte question

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 10:51 AM, Lauri Pesonen wrote: > One way to fix this would be to produce a string out of c: > > (defn hexchar? [c] (re-find #"[0-9A-Fa-f]" (str c))) > > but you should really change hexchar? into something more elegant. Like this? (def hexchar? #{\0 \1 \2 \3 \4 \5 \6 \7

Re: Once-only macro

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 7:35 PM, Gorsal wrote: > > I was just idly wondering: even after searching google, i haven't seen > the once-only macro+clojure pop up any results. Its easy to > implement, but I was wondering if there was some reason people weren't > using this to avoid multiple evaluatio

Re: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 7:49 PM, samppi wrote: > Is there a standard function that takes one argument and calls it? > That is, the function equivalent to #(%). Or is that the best idiom > there is? #(%) is only four characters. Calling apply with only one argument also does this, and "apply" is

Re: Large lazy seq = StackOverflow?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 9:28 PM, Dmitry Kakurin wrote: > > I have an innocent-looking function that only uses map and reduce, but > when I run it on a big collection (10K elements) I get a StackOverflow > exception. Here is the function: > > (defn multi-filter [filters coll] > (reduce >(fn [r

Re: Large lazy seq = StackOverflow?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 9:58 PM, Dmitry Kakurin wrote: > On Oct 21, 6:45 pm, John Harrop wrote: > > the reduction is wrapping the initial seq of empty vectors in ten > > thousand layers of map ... fn ... invoke ... map ... etc. > > Reducing a lazy sequence generator

Re: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 11:50 PM, samppi wrote: > Oh, no. I was just wondering if there was a standard variable devoted > to it. A symbol would be aesthetically less clutter than #(%), even if > it'd take more typing. But if there isn't any other than the slow > apply function, I'm happy with #(%

Re: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Thu, Oct 22, 2009 at 12:19 AM, John Harrop wrote: > On Wed, Oct 21, 2009 at 11:50 PM, samppi wrote: > >> Oh, no. I was just wondering if there was a standard variable devoted >> to it. A symbol would be aesthetically less clutter than #(%), even if >> it'd t

Re: Private multimethods possible?

2009-10-22 Thread John Harrop
On Thu, Oct 22, 2009 at 11:11 PM, Alex Osborne wrote: > > > So you could do the same when defining a multimethod, just give the > > name (symbol) of the method the metadata ":private" with the value > > "true": > > > > (defmulti #{:private true} my-multi my-dispatch) > > I'm having a bad day for

Re: Macro newbie: Trying to create a map template

2009-10-23 Thread John Harrop
On Sat, Oct 24, 2009 at 12:19 AM, samppi wrote: > user=> (defmacro b [form] > (let [processed-form (a form rec#)] >`(fn [rec#] processed-form))) > java.lang.Exception: Unable to resolve symbol: rec# in this context > (NO_SOURCE_FILE:39) Try (defmacro b [form] (let [r (gensym) pr

Re: Macro newbie: Trying to create a map template

2009-10-24 Thread John Harrop
On Sat, Oct 24, 2009 at 2:43 PM, samppi wrote: > Thanks a lot! I didn't know about the existence of gensym. This will > help a lot. You're welcome. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. T

Re: SICP in Clojure

2009-10-24 Thread John Harrop
On Sat, Oct 24, 2009 at 10:19 PM, Robert Stehwien wrote: > Hadn't seen it posted here yet: > http://sicpinclojure.com/ > Are they looking for help writing Clojure versions of the Scheme code snippets? --~--~-~--~~~---~--~~ You received this message because you are

Re: clojure / ruby yield comparison

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 2:50 PM, Radford Smith wrote: > > Ruby blocks are anonymous functions with syntax sugar. You could write > James' with_open method like this: > > def with_open(stream, &f) > f.call(stream) > end > > The equivalent in Clojure is effectively the same: > > (defn with-open [s

Measuring code complexity

2009-10-25 Thread John Harrop
Reading http://www.paulgraham.com/power.html and specifically the section titled "Metrics" near the top, I realized that it would be very easy to calculate such metrics for Lisp code, and it took me literally only seconds to hack something in Clojure: user=> (defn count-nodes [data] (if (clojure.c

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 10:08 PM, John Harrop wrote: > > 4 public class NodeCounter { > 8 public static int countNodes (Object data) { > 10 if (!(data instanceof Iterable)) return 1; > 5 int result = 1; > 8 for (Object e : (Iterable)data) { >

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 11:56 PM, MarkSwanson wrote: > I'm curious (general Clojure question) about your use of the quoted > form. The Clojure docs state that this results in an unevaluated form, > but I had trouble finding more details on this. F.E. I'd like to run > count-nodes against a compile

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 12:45 AM, Timothy Pratley wrote: > > This sounds like a neat idea to me. Maybe the way to get the > 'complexity' is to calculate it at definition, this macro doesn't work > for obvious reasons: > (defmacro defnc > [n & body] > `(let [f# (defn ~n ~...@body)] > (alter-m

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 1:09 AM, Chouser wrote: >(count-nodes "abcde") >; 6 Yikes. Maybe special-casing strings would be best: change (seqable? x) into (and (seqable? x) (not (string? x))). I don't know if Seqable is synonymous with that; might there be other seqable?s that aren't Seq

Re: Equivalents from java

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 1:17 AM, Gorsal wrote: > So i've been trying to find two equivalents to keywords in java. The > first one is synchronized. is there any syncrhonized keyword in > clojure? > (locking obj (do-something-with obj foo bar)) is equivalent to Java synchronized (obj) { obj.

clojure@googlegroups.com

2009-10-26 Thread John Harrop
On Mon, Oct 26, 2009 at 4:18 AM, Cristian wrote: > I just started learning clojure and I tried to extend JButton, but I > keep getting a ClassFormatError when I try to instantiate the class. > > The problem started happening when I declared my own constructors. Can > I not declare a constructor wi

Re: Equivalents from java

2009-10-26 Thread John Harrop
On Mon, Oct 26, 2009 at 8:01 AM, Gorsal wrote: > Thanks. Now i know to also use doc :) You're welcome. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@g

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-26 Thread John Harrop
On Mon, Oct 26, 2009 at 1:55 PM, Jason Wolfe wrote: > Hi Mark, > > Thanks for the patch! Have you seen this page? > > http://clojure.org/contributing > > You should follow the instructions there to get your patch included. > In particular, that page tells you where to post it, and has other > de

Re: KeyTest$_init_307.class vs KeyTest_init?

2009-10-27 Thread John Harrop
On Mon, Oct 26, 2009 at 11:18 PM, Gorsal wrote: > Again, there is compiled something like ns_name__154__auto__ > $init__162.class. I really wonder what these dollar signs signify! Nested classes are indicated that way at the JVM level. --~--~-~--~~~---~--~~ You

Re: Measuring code complexity

2009-10-27 Thread John Harrop
On Mon, Oct 26, 2009 at 6:09 PM, kyle smith wrote: > Rather than the number of nodes in a tree, I think a better metric > would be the number of edges in a graph. Variables that are > referenced on many different lines should get double counted. I think > this would explain why imperative spagh

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-27 Thread John Harrop
On Tue, Oct 27, 2009 at 1:39 PM, Emeka wrote: > On Sun, Oct 25, 2009 at 4:57 PM, MarkSwanson wrote: > >> >> Hello, >> >> Someone recently posed the question: (why doesn't this work) >> (into {} (map #([% (* % %)]) [1 2 3 4])) >> >> > Is this actually a Vector problem or the limitation of the anon

<    1   2   3   4   >