Re: Am I holding on to the head here ?

2009-02-08 Thread Kevin Downey

I am not sure exactly how preduce differs from normal reduce, but
reduce is not a lazy operation, so it will result in the realization
of a lazy seq passed to it.

On Sun, Feb 8, 2009 at 2:13 PM, Jeffrey Straszheim
straszheimjeff...@gmail.com wrote:
 I have this piece of code:

 (defn- run-work-elements-in-parallel
   Runs a group of work elements in parallel. Returns an extended database.
   [elements database]
   (assert (set elements))
   (let [[rec simp] (separate :recursive elements)
 results-simp (pmap #(run-simple-work-element % database) simp)
 results-rec (map #(run-recursive-work-element % database) rec)
 results (concat results-simp results-rec)]
 (preduce union (cons database results

 The exact details aren't important.

 The let bindings results-simp, results-rec, and results are each a lazy
 stream.  They can get quite large.  Assuming preduce can iterate over them,
 is binding them in the let statement stopping them from getting garbage
 collected?

 If so, is the best solution to wrap them in a (fn [] ...) and then use them
 like (results)?

 Thanks

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: anonymous functions

2009-02-10 Thread Kevin Downey

fn has an implicit (do ...)
#(do ...) behaves the same way.

#(a b c) expands to
(fn [] (a b c))
if you put in multiple forms you get
#((a b)(c d))
expands to
(fn [] ((a b) (c d)))
note the (a b) in the operator position.

On Tue, Feb 10, 2009 at 8:09 PM, Mark Volkmann
r.mark.volkm...@gmail.com wrote:

 Just checking my understanding of the rules for writing anonymous functions 
 ...
 (fn [args] ...) allows any number of expressions in its body.
 #(...) only allows a single expression in its body, correct?
 Why the difference?

 --
 R. Mark Volkmann
 Object Computing, Inc.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: alternate syntax

2009-02-23 Thread Kevin Downey

You might be interested in my pet macro: pl
http://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj#L94

it does transformations on code using zippers.
for example:

(pl inc $ inc $ 0) expands to (inc (inc 2))

pl is just a toy but it might be worth looking at.

On Mon, Feb 23, 2009 at 7:42 AM, Mark Volkmann
r.mark.volkm...@gmail.com wrote:

 I have an idea I'd like to float to see if there are reasons why it's
 a bad idea.

 What if Clojure had an alternate surface syntax that was translated
 into standard Clojure syntax by a kind of preprocessor?

 Many people that don't like Lisp dialects don't like them because of
 the parentheses. I'm trying to address that.

 Here's a simple example of valid Clojure code.

 (defn pig-latin [word]
  (let [first-letter (first word)]
(if (.contains aeiou (str first-letter))
  (str word ay)
  (str (subs word 1) first-letter ay

 (println (pig-latin red))
 (println (pig-latin orange))

 Here's what that same code would look like in my alternate syntax.

 defn pig-latin [word]
  let [first-letter (first word)]
if .contains aeiou (str first-letter)
  str word ay
  str (subs word 1) first-letter ay

 println (pig-latin red)
 println (pig-latin orange)

 The rules for turning this into standard Clojure syntax are pretty simple.

 1) If a line is indented farther than the previous one, it is part of
 the previous line.
 2) If a line doesn't start with a (, then add one.
 3) If the next line is indented less than this one, add the
 appropriate number of )'s at the end.
 4) If the first token on a line is if and the first non-whitespace
 character after it is not (
then assume the rest of the line is the condition and wrap it in ( ).

 A translation from standard Clojure syntax to this alternate form
 should also be possible.

 Is this a bad idea?

 --
 R. Mark Volkmann
 Object Computing, Inc.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Flatten a list

2009-02-24 Thread Kevin Downey

filter, http://clojure.org/api#filter

On Tue, Feb 24, 2009 at 7:38 PM, Sean francoisdev...@gmail.com wrote:

 I've got the following list

 (:a nil nil :b :a)

 I want to call a nil-killer function, and get the following list

 (:a :b :a)

 How do I go about this?  Could someone post a quick example?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Extensive use of let?

2009-02-25 Thread Kevin Downey

You should look at -
it lest you take (op3 (op2 (op1 input))) and write it as (- input op1 op2 op3)
there is also comp which composes functions, and partial for partial
application.

some example comp usage:
http://github.com/hiredman/clojurebot/blob/297e266b0badf0f301a556e95771b940a80016e7/hiredman/clojurebot/tweet.clj#L11

On Wed, Feb 25, 2009 at 12:57 PM, levand luke.vanderh...@gmail.com wrote:

 Recently, in my code, I have been struggling with which of the two
 equivalent forms is, in a general sense, better.

 (defn my-fn1 [input]
  (let [value1 (op1 input)
        value2 (op2 input)
        value3 (op4 value1 value2)]
    (op5 value3)))

 (defn my-fn2 [input]
  (op5 (op4 (op1 input) (op2 input

 Now, the second is definitely cleaner and more elegant, besides being
 smaller, which is a non-trivial benefit when I have a fair amount of
 code to page through.

 However, if I've been away from the code awhile, it's much easier to
 come back determine what the code is doing when its written the first
 way, especially when it uses descriptive names. An operation that is
 impenetrable when written in nested form can become quite simple when
 each step is broken down and labeled.

 Clojure is my first Lisp - should I just stick with the second form
 until I learn to see through the nested s-expressions?

 It's not that I'm trying to make my code more imperative - Although I
 come from a Java background, I love functional programming, and it is
 a delight to see how much I can do without side-effects. But I do miss
 the self-documentation that well-named variables can provide.

 Any thoughts? Also, is there any performance degradation from the
 first way, or can the compiler optimize it away?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: transposing a small java class in clojure

2009-03-10 Thread Kevin Downey

I don't know how many arguments the method you are overriding with
onLogin takes, but the function you define should take one more
argument then the method you are overiding, the first argument being
an explicit reference to an instance

On Tue, Mar 10, 2009 at 12:16 PM, rb raphi...@gmail.com wrote:

 HI Chris,

 thanks for your response, and I'll update the code as you suggest.
 However, I actually have problems even when the -onLogin function is
 empty, returns nil, or returns FtpletResult/DEFAULT. It seems it
 causes trouble once it's defined.

 I'll post an update tomorrow

 Raphaël

 On Mar 10, 6:50 pm, chris cnuern...@gmail.com wrote:
 I can see one possible difference, depending on how you are loading
 the code into the ftp server.

 In your clojure example you are accessing the logger through a top-
 level define.  I believe this will run *during the file loading
 process* as static code.

 In your working java example, you aren't accessing the logger until
 the actual onLogin function is called.

 If the logger is in an odd state (like null) or god forbid the runtime
 sets up the logger just before it calls into your function then you
 may get different results.  I would recommend calling the getlogger
 call in the function perhaps; change the 'def logger' to 'defn logger
 []' and work out the resulting details.  This would make the clojure
 example a little closer to your java example and at least eliminate
 one possible problem.

 Chris

 On Mar 10, 7:35 am, rb raphi...@gmail.com wrote:

  Hi,

  I'm experimenting withhttp://mina.apache.org/ftpserver
  I have written a small java class that gets used by the ftp server,
  and am trying to transpose it to clojure, but unsuccessfully until
  now

  The class generated with clojure is detected and used by the server,
  but the code of the method implemented is not run, and even worse, the
  ftp server isn't functional anymore (though I don't see any exception
  raised).

  Does anyone have an idea about what I'm doing wrong?

  Thanks

  Raphaël

  Here's the java code:

  package com.raphinou;

  import java.io.IOException;
  import org.apache.ftpserver.*;
  import org.apache.ftpserver.ftplet.*;

  public class Ftplet extends DefaultFtplet {
      public FtpletResult onLogin(FtpSession session, FtpRequest
  request)
              throws FtpException, IOException {
          java.util.logging.Logger logger=
  java.util.logging.Logger.getLogger(com.raphinou);
          logger.addHandler( new java.util.logging.FileHandler(/tmp/
  ftp.log));
          logger.severe(Logging in!!);
          return FtpletResult.DEFAULT;
      }

  }

  and here's the clojure code:

   (ns com.raphinou.ftplet
    (:gen-class :name com.raphinou.Ftplet
     :extends org.apache.ftpserver.ftplet.DefaultFtplet)
    (:import [org.apache.ftpserver.ftplet DefaultFtpReply
  FtpletResult]))

  (def logger (java.util.logging.Logger/getLogger com.raphinou))
  (.addHandler logger (java.util.logging.FileHandler. /tmp/ftp.log))

  (defn -onLogin [session request]
    (.severe logger Logging in, clj)
    FtpletResult/DEFAULT)
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Request: Can clojure.contrib.walk provide a reduce type operation?

2009-03-11 Thread Kevin Downey

if your walk pushes the items into a Queue, you can just reduce across the Queue

On Wed, Mar 11, 2009 at 9:24 AM, Jeffrey Straszheim
straszheimjeff...@gmail.com wrote:
 Currently the clojure.contrib.walk code provides a nice way to perform a
 depth first map operation on trees.  However, I need to fold across a tree.
 It would be nice if walk provided this.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Slash mystery

2009-03-18 Thread Kevin Downey

this came up on irc starting:
http://clojure-log.n01se.net/date/2009-02-18.html#23:49
and the solution:
http://clojure-log.n01se.net/date/2009-02-19.html#0:30


On Wed, Mar 18, 2009 at 11:03 AM, Konrad Hinsen
konrad.hin...@laposte.net wrote:

 Consider the following session:

 user= /
 #core$_SLASH___3331 clojure.core$_slash___3...@7a916b
 user= clojure.core//
 #core$_SLASH___3331 clojure.core$_slash___3...@7a916b
 user= (ns-unmap *ns* '/)
 nil
 user= /
 java.lang.Exception: Unable to resolve symbol: / in this context
 (NO_SOURCE_FILE:0)
 user= (defn / [a b] (clojure.core// a b))
 #'user//
 user= /
 #user$_SLASH___1401 user$_slash___1...@37a91a
 user= user//
 java.lang.Exception: Invalid token: user//


 Why is user// an invalid token, whereas clojure.core// works
 perfectly well?

 Konrad.


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Slash mystery

2009-03-18 Thread Kevin Downey

Symbols starting and ending with . are reserved.
see http://clojure.org/reader the section on Symbols

On Wed, Mar 18, 2009 at 12:58 PM, Michael Wood esiot...@gmail.com wrote:

 On Wed, Mar 18, 2009 at 8:22 PM, Kevin Downey redc...@gmail.com wrote:

 this came up on irc starting:
 http://clojure-log.n01se.net/date/2009-02-18.html#23:49
 and the solution:
 http://clojure-log.n01se.net/date/2009-02-19.html#0:30

 Interesting.

 I noticed something similar the other day:

 user= (defn ... [] (print 'something))
 #'user/...
 user= (...)
 java.lang.IllegalArgumentException: Malformed member expression,
 expecting (.member target ...) (NO_SOURCE_FILE:4)
 user=

 But I suppose that's a reader macro thing?

 --
 Michael Wood esiot...@gmail.com

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Help with the dot operator special form

2009-03-21 Thread Kevin Downey

you want defmacro not definline. the result of a macro is a data
structure. that data structure is then evaluated in place of the call
to the macro. definline (I think?) behaves similar to a function, so
if it returns a data structure, you just get that data structure (the
data structure is not then evaluated)

On Sat, Mar 21, 2009 at 6:04 PM, David Nolen dnolen.li...@gmail.com wrote:
 I'm wondering if it's possible to create a Clojure function that does what
 the dot operator does. It seems like this would be possible with definline
 but I'm unable to get this to work or figure it out.  For example I want to
 be able write something like the following:
 (dot Hello world (list 'substring 1 2))
 Trying to use definline like this:
 (definline dot
   [obj member-exp]
   `(. ~obj (~...@member-expr)))
 Simply throws an error.
 I don't need variable arity, I will always pass an instance or class
 following by a list representing the member expression.
 Is this impossible?
 It seems like this would be generally useful to allow variable method
 calling on Java objects. As to why I want it to implement this, it would be
 far simpler to support Java interop from clj-cont if the dot operator could
 be expressed as a Clojure function.
 Thanks!
 David
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Mapping a function over a map's values

2009-03-22 Thread Kevin Downey

(defn mapmap [fn m]
(into {} (map #(vector (first %) (fn (second %))) m)))

On Sun, Mar 22, 2009 at 1:10 PM, Jon Nadal jon.na...@gmail.com wrote:

 I often need to map a function over the values of a map while
 preserving keys--something like:

 [code]
 (defn mapmap [fn m]
  (let [k (keys m)
        v (map fn (vals m))]
    (zipmap k v)))

 (mapmap inc {:a 0, :b 1})
 [/code]

 Is there a more concise way to do this in Clojure?  If not, is this
 something that might be worth putting in the contrib?

 -Jon

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: introspect namespace ?

2009-04-05 Thread Kevin Downey

(.toString *ns*)

On Sun, Apr 5, 2009 at 12:39 PM, Stephen C. Gilardi squee...@mac.com wrote:

 On Apr 5, 2009, at 3:23 PM, dysinger wrote:

 I need coffee - too many typos.  I meant to say I am trying to avoid
 _typing_ 'x.y.z' twice

 (str (the-ns 'user)) is is even more human-error prone than just
 typing user.

 I was look for a way to introspect ns (DRY up the Logger/getLogger
 call).  In java you could just Logger.getLogger(this.getClass().getName
 ()) or something so you are not prone to typos and it's refactor-
 friendly.

 If you want the name of the current namespace as a string, here's one way:

        (- *ns* ns-name name)

 --Steve





-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Question about metadata on map keys

2009-04-10 Thread Kevin Downey

I think you misunderstand, I don't think he is expecting to being able
to use :foo as a key twice with different metadata.

I think he wants something like:

(def x {[:a] 1 [:b] 2})

then

(meta (first (keys (assoc x (with-meta [:a] {:x 1}) 2
;(- (assoc x (with-meta [:a] {:x 1})) keys first meta)

would be {:x 1}, instead of nil

On Fri, Apr 10, 2009 at 7:09 AM, Stuart Sierra
the.stuart.sie...@gmail.com wrote:

 On Apr 10, 12:14 am, Jason Wolfe jawo...@berkeley.edu wrote:
 ...
 Namely, if a map already contains a given key, when you attempt to
 assoc in a version of the key with new metadata this is not recorded.
 It seems that the map always retains the original key:
...
 Is this desired behavior?  If so, is there a better way to change the
 metadata on a key than first dissoc-ing it out and then assoc-ing it
 back in again with new metadata?

 Probably this is expected, since metadata is defined not to affect
 equality, and maps rely on equality semantics.  I would recommend
 against storing metadata on map keys.  In general, if the metadata
 matters for the value of an object, then it shouldn't be metadata.

 Some alternatives: 1) put the information directly in the map values;
 2) store metadata on the map values; 3) use maps as keys.

 -Stuart Sierra
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java.lang.String cannot be cast to [Ljava.lang.CharSequence;

2009-04-16 Thread Kevin Downey

I would be interested in seeing a full stack trace and some pastbined
code. there are no clojure strings, just java strings, and java
strings are charsequences.

On Thu, Apr 16, 2009 at 11:25 AM, prhlava prhl...@googlemail.com wrote:


 Hello,

 I am trying to use a java library ( http://code.google.com/p/webdriver/
 ), the method I need to call has signature:

 sendKeys(java.lang.CharSequence... keysToSend)

 If I give it a clojure string, the cannot be cast message appears in
 the stack trace.

 I have tried explicit (cast java.lang.CharSequence my-string) but
 the cast does only compare AFAIK.

 Is there a way to give the library what it wants from Clojure?

 Kind regards,

 Vlad
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: IFn?

2009-04-18 Thread Kevin Downey

ifn? returns true for things that implement clojure.lang.IFn, IFn is
the interface for things that can be put in the operator position in a
s-expr:
functions
vectors
maps
sets
keywords
symbols
...?

fn? returns true for just functions

On Sat, Apr 18, 2009 at 9:37 PM, tmountain tinymount...@gmail.com wrote:

 Sorry for the newbie question, but can someone tell me what IFn means
 exactly? I keep running into it in the docs particularly in the
 keyword documentation, and Google has yet to expain.

 Thanks,
 Travis
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: areduce flaw

2009-04-27 Thread Kevin Downey

no, the syntax is not the same.

user= (macroexpand-1 '(.foo bar))
(. bar foo)



On Mon, Apr 27, 2009 at 2:51 PM, Boris Mizhen bo...@boriska.com wrote:

 Hi Meikel, thanks for the answer.

 I wonder if someone could explain or point me to the explanation about
 *why* a Java static fn can't be passed just like a closure fn?

 After all the syntax to call them is the same :)

 Thanks,
 Boris


 On Apr 27, 5:34 pm, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 27.04.2009 um 23:17 schrieb Boris Mizhen:

  ((comp #(Math/abs %) +) -3 -4) = 7

  How can I pass a static java function to another function?

 Here you already gave the answer to your question. Wrap it in
 a Clojure fn/#().

  A member function must be trickier because this must be supplied, but
  perhaps a macro can be created that results in a function that would
  capture this and call the member function appropriately ...

 #(.someMethod an-object %)

 Or passing in the object:

 #(.someMethod %1 %2)

 For apply and friends one needs a more elaborate way.
 Search for rhickey jcall site:paste.lisp.org.

 Sincerely
 Meikel

  smime.p7s
 5KViewDownload
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: constructing maps

2009-05-05 Thread Kevin Downey

(into {} (apply map vector
'((cars bmw chevrolet ford peugeot)
  (genres adventure horror mystery

{ford mystery, chevrolet horror, bmw adventure, cars genres}


On Mon, May 4, 2009 at 4:03 PM, Michel S. michel.syl...@gmail.com wrote:



 On May 4, 5:07 pm, Christophe Grand christo...@cgrand.net wrote:
 Michel S. a écrit :

  (apply conj {} (map split-kv (split-pairs test-str)))

  The last can be simplified by using into:
  (into {} (map split-kv (split-pairs test-str)))

 It should be noted that into (and conj) is somewhat tricky with maps:
 user= (into {} '({1 2} {3 4}))
 {3 4, 1 2}
 user= (into {} '([1 2] [3 4]))
 {3 4, 1 2}
 user= (into {} '((1 2) (3 4)))
 java.lang.ClassCastException: java.lang.Integer cannot be cast to
 java.util.Map$Entry (NO_SOURCE_FILE:0)

 It bit me before.

 Yes, me too. The design is a bit unfortunate, as I cannot convert a
 Scheme-style association list to a map easily:

 user= (into {} '((cars bmw chevrolet ford peugeot)
 (genres adventure horror mystery)))

 java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to
 java.util.Map$Entry (NO_SOURCE_FILE:0)

 --
 Michel
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can for be enhanced to not have to take a binding?

2009-05-07 Thread Kevin Downey

user= (doc take-while)
-
clojure.core/take-while
([pred coll])
  Returns a lazy sequence of successive items from coll while
  (pred item) returns true. pred must be free of side-effects.
nil
user=


On Thu, May 7, 2009 at 2:11 PM, CuppoJava patrickli_2...@hotmail.com wrote:

 I'm trying to accomplish the following:
 Create a lazy sequence of calls to f() while pred() is true.
 And an elegant way to do this seems to be:

 (for [:while (pred)] (f))

 which doesn't work because (for) requires a binding.
 This can be worked around with:

 (for [i (constantly 0) :while (pred)] (f))

 which is not as elegant.

 Does anyone else think this is a worthwhile to for? Thanks for your
 opinions.
  -Patrick
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Help with Type Hint

2009-05-14 Thread Kevin Downey

so I took a look at with this code:

http://gist.github.com/111935

output:

:original
Elapsed time: 369.683 msecs
:redux-1
Elapsed time: 11672.329 msecs
:redux-2
Elapsed time: 74.233 msecs

as to why there is such a huge difference between your code and
redux-2 I am not sure.

I would definitely take a look at
http://clojure.org/java_interop#toc46 if you haven't yet.


On Thu, May 14, 2009 at 1:19 PM, Dimiter malkia Stanev
mal...@gmail.com wrote:

 This is the best I was able to come up with in Clojure:

 (defn byte-array-contains? [coll key]
  scans a byte array for a given value
  (let [c (int (count coll))
        k (byte key)]
    (loop [i (int 0)]
      (if ( i c)
        (if (= k (aget coll i))
          true
          (recur (unchecked-inc i)))


 On May 14, 8:22 am, tmountain tinymount...@gmail.com wrote:
 I'm trying to optimize some code I've written, and I have set warn on
 reflection as advised. I'm having a hard time getting a simple
 statement to avoid reflection.

 user= (== (byte 0x1) (byte 0x1))
 Reflection warning, line: 33 - call to equiv can't be resolved.

 Can you use type hints on primitive types? I've tried obvious stuff
 like:

 user= (== #^byte (byte 0x1) #^byte (byte 0x1))
 Reflection warning, line: 4 - call to equiv can't be resolved.

 and other variations without success.

 Thanks,
 Travis
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: The thread ring problem

2009-05-29 Thread Kevin Downey

http://gist.github.com/120289 using queues and Threads instead of agents

On Fri, May 29, 2009 at 4:11 PM, Laurent PETIT laurent.pe...@gmail.com wrote:

 Hi,

 here is a second attempt, partly inspired by clojure's agents page,
 that looks better (true direct ring of agents, not just indirect ring
 via vector), and that performs similarly to my first attempt.

 Still room for progress, though.

 (ns shootout.ring2
  (:gen-class))

 (def n-threads 503)
 (def nb-pass   5000)

 (defn agent-fn [state token-val stop-val print-result-fn start-time]
        (if (= token-val stop-val)
          (print-result-fn (:name state) start-time)
          (send (:next state) agent-fn (inc token-val) stop-val
 print-result-fn start-time))
        state)

 (defn main
  main function calling the benchmark test.
  [n-threads N print-result-fn]
  (let [agent-n  (agent {:name n-threads :next nil})
       agent-1  (reduce (fn [a n] (agent {:name n :next a})) agent-n
 (range (dec n-threads) 0 -1))]
   (send agent-n assoc :next agent-1)
   (send agent-1 agent-fn 0 N print-result-fn (System/nanoTime))
   nil))

 (defn repl-print-result-fn [thread-id start-time]
  (println \n
          thread number:  thread-id \n
          time   (secs):  (/ (- (System/nanoTime) start-time) 10.0)))

 (defn benchmark-print-result-fn [thread-id _]
  (println thread-id))

 (defn -main []
  (main n-threads nb-pass benchmark-print-result-fn))

 (defn repl-test [nb-pass]
  (main n-threads nb-pass repl-print-result-fn))

 2009/5/29 Sean Devlin francoisdev...@gmail.com:

 Would type hints help at all?

 On May 29, 11:40 am, Laurent PETIT laurent.pe...@gmail.com wrote:
 Hi,

 Here is my attempt, for the real benchmark test, it has an honorable
 result of 62 sec. (if there is no flaw in my algorithm, of course).

 ;; file shootout/ring.clj
 (ns shootout.ring
   (:gen-class))

 (def n-threads 503)
 (def nb-pass   5000)

 (defn main
   main function calling the benchmark test.
   [n-threads N print-result-fn]
   (let [start-time (System/nanoTime)
         agents  (into [] (map #(agent {:name (inc %)}) (range n-threads)))
         send-to (fn this [i token-val]
                   (send (nth agents (mod i n-threads))
                             (fn [state t-val]
                               (if (= t-val N)
                                 (print-result-fn (:name state) start-time)
                                 (this (inc i) (inc t-val)))
                               state)
                             token-val))]
     (send-to 0 0)
     nil))

 (defn repl-print-result-fn [thread-id start-time]
   (println \n
            thread number:  thread-id \n
            time   (secs):  (/ (- (System/nanoTime) start-time) 
 10.0)))

 (defn benchmark-print-result-fn [thread-id _]
   (println thread-id))

 (defn -main []
   (main n-threads nb-pass benchmark-print-result-fn))

 (defn repl-test [nb-pass]
   (main n-threads nb-pass repl-print-result-fn))

 ;; repl session
 Clojure
 1:1 user= (use 'shootout.ring)
 nil
 1:2 user= (do (repl-test 1000) (repl-test 5000))
 nil
 1:3 user=
  thread number:  498
  time   (secs):  0.128037133

  thread number:  292
  time   (secs):  62.724999733

 on a recent machine

 (and yes, I know something similar is on the clojure agents page, but
 sometimes it's rewarding not to look at the solution too early :-)

 Cheers,

 --
 Laurent

 2009/5/29 Alvaro Vilanova Vidal alv...@gmail.com:

  Thanks, seems that I misunderstood Agents :)

  The solution of Christian works well with full load, but maybe slow for 
  the
  benchmark. In my core2duo, with full load, takes about 28mins to compute 
  the
  result.

  user= (do (println (System/nanoTime)) (start 5000))
  22651751153117
  #ag...@27a897a9: 1
  user= 292 ( 24319344452689 )
  user= (/ (- 24319344452689 22651751153117) 600.0)
  27.79322165954

  2009/5/29 Christian Vest Hansen karmazi...@gmail.com

  On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT laurent.pe...@gmail.com
  wrote:
   when I try it with the 50,000,000 number of times the token is
   exchanged (which is the number to be used for the benchmark)

  Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
  (time ...) makes no sense.

   How would one fix this?

  With a CountDownLatch? That's what I'm currently trying.

   2009/5/29 Christian Vest Hansen karmazi...@gmail.com:

   For kicks, I made an implementation* using agents:

  http://gist.github.com/119946

   I think that you may not want to use the STM so much and instead
   figure out a different approach to sending the token around the ring.

   *it may be a bit liberal in its interpretation of the rules... didn't
   read them that carefully.

   On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal
   alv...@gmail.com wrote:

   Hi everyone,
   I am a newbie in clojure world, so I have some newbie's questions :)
   To
   learn about clojure, I am trying to do the thread ring problem of 
   clgb
   in
   

Re: Using (into {} ...) on a sequence of lists vs. vectors

2009-06-01 Thread Kevin Downey

two element vectors implement MapEntry, (into {} x) x needs to be
something that seq can be called on and will return a seq of MapEntrys


On Mon, Jun 1, 2009 at 10:39 AM, samppi rbysam...@gmail.com wrote:

 Why does using a list with into and a map throw an exception, while
 using a vector is fine?

 Clojure 1.0.0-
 user= (def a (list :a 1))
 #'user/a
 user= (into {} [a])
 java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to
 java.util.Map$Entry (NO_SOURCE_FILE:0)
 user= (def b [:a 1])
 #'user/b
 user= (into {} [b])
 {:a 1}


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: New and stuck ??

2009-06-07 Thread Kevin Downey

the new entry point is clojure.main

java -cp clojure.jar clojure.main ;no slash, with the corrent jar name

java -cp clojure.jar clojure.main --help

will print a nice help message


On Sun, Jun 7, 2009 at 8:20 AM, darrelldgalli...@gmail.com wrote:

 OK, embarrassing

 Thanks, I was caught wishing to see a wow fun demo, without thought on
 my part.

 -= Darrell

 On Jun 7, 10:13 am, Kyle R. Burton kyle.bur...@gmail.com wrote:
 I think your ls showed it, the jar name is clojure-1.0.0.jar, so the
 java -cp argument should point to that instead:

   java -cp clojure-1.0.0.jar clojure.lang.Repl

 Kyle


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: The - . nested usage

2009-06-08 Thread Kevin Downey

sure it can, you just need to pass in an initial value.

(- (String.) String. String.) ; works
(- x String. String.) ;works for any x where string has a constructor
that takes something of type x

for example

(- file.txt File. FileReader. BufferedReader.)

will return a buffered reader on file.txt (assuming you import those
classes from java.io)

On Mon, Jun 8, 2009 at 12:59 PM, ronennark...@gmail.com wrote:

 I see, using - with . will not create a chain of new
 invocations, the best solution that iv found is:
 user= (String. (String.))
 
 user= (macroexpand (String. (String.)))
 
 user= (macroexpand `(String. (String.)))
 (new java.lang.String (java.lang.String.))

 Nesting is a must :)
 Thank you both for your helpful reply

 On Jun 8, 10:51 pm, Kevin Downey redc...@gmail.com wrote:
 you need to pass something in.
 example:

 = (- foo String. String.)
 foo

 = (macroexpand '(- String. String.))
 (new String String.)

 = (macroexpand '(- foo String. String.))
 (new String (clojure.core/- foo String.))
 = (macroexpand '(- foo String.))
 (new String foo)

 String. is only treated as new String ...  when it is placed in the
 function position (String. ...)
  in (- String. String.) the first String. is never put in the
 function position, so effectively you get
 (String. String.)



 On Mon, Jun 8, 2009 at 12:38 PM, ronennark...@gmail.com wrote:

  Following a blog post on building large object graphs I was suggested
  with the following solution:
   (def nested-object (- GrandFather. Father. GrandSon.))

  this indeed seems to be correct however fails in even in a simple
  example:

  user= (- String. String.)
  java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7)

  expanding the macros involved seems to reveal the issue:

  user= (macroexpand-1 `(- String. String.))
  (java.lang.String. java.lang.String.)

  the . macro isn't expanded.

  Is there a way of applying nested macros?
  (iv searched for applying nested macros with no results).

 --
 And what is good, Phaedrus,
 And what is not good—
 Need we ask anyone to tell us these things?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Thoughts on bags?

2009-06-09 Thread Kevin Downey

On Tue, Jun 9, 2009 at 7:49 PM, Richard Newmanholyg...@gmail.com wrote:

 Thanks, Konrad and Andrew, for chipping in!

 There's an outline of an implementation of multisets (I think that's
 the same as your bags) at:

        http://code.google.com/p/clojure-contrib/source/browse/trunk/src/
 clojure/contrib/types/examples.clj

 Thanks for the pointer.

 I apologize for the negativity, but these don't seem first class --
 that is, I can't treat them as I would sets:

 user= (map identity #{:a :b :c})
 (:a :c :b)
 user= (map identity (gc/conj (multiset {}) :a :b :c)))
 ([:c 1] [:b 1] [:a 1])

all that needs to happen is for multiset to provide it's own seq, like
it supplies it's own conj. seq would strip  whatever information out.
you would need to call it explicitly on the multiset before passing it
to functions which call seq internally (map, filter, etc).

 The cardinality tracking has been (necessarily, I understand) lifted
 into the explicit contents of the data structure, so applications
 which call Clojure code that performs core operations (not your
 generic versions) on those structures will not work.

 Consequently, I couldn't use these with clojure.set's relational
 operations, for example:

 user= (clojure.set/join
          #{{:name John :id 4} {:name John :id 3}}
          #{{:age 32 :id 4} {:age 19 :id 3}})
 #{{:age 19, :name John, :id 3} {:age 32, :name John, :id 4}}

 user= (clojure.set/join
          (gc/conj (multiset {}) {:name John :id 4} {:name
 John :id 3})
          (gc/conj (multiset {}) {:age 32 :id 4} {:age 19 :id 3}))
 java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot
 be cast to java.util.Map$Entry (NO_SOURCE_FILE:0)

 So far as I understand it, to get 'native' multisets would require an
 implementation of IPersistentCollection, or perhaps IPersistentSet
 itself (if the contract of the interface doesn't impose set
 semantics), and ideally some Clojure surface syntax.

 PersistentTreeSet doesn't look too scary, so perhaps I'll dive in...
 more fun than my paid work, after all :)


 Google Collections has Multisets - and they have an immutable
 implementation.

 http://code.google.com/p/google-collections/

 Hmm, interesting. Not sure how their builder-based approach would fit
 in.

 For now, as I'm storing maps in my sets -- I'm doing relational stuff,
 after all -- I just add an :id entry in each map, filled by (iterate
 inc 0). Functionally the same as a multiset, so long as I ignore
 the :id 'column'...

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: EDT interaction

2009-06-13 Thread Kevin Downey

On Sat, Jun 13, 2009 at 2:02 PM, Wrexsould2387...@bsnow.net wrote:

 Now I'm working on some Swing code and came up with these, which are
 obviously going to be useful:

 (defmacro do-on-edt [ body]
  `(SwingUtilities/invokeLater #(do ~...@body)))

 (defmacro get-on-edt [ body]
  `(let [ret# (atom nil)]
     (SwingUtilities/invokeLater #(reset! ret# [(do ~...@body)]))
     (loop []
       (let [r# @ret#]
         (if r#
           (first r#)
           (recur))

 (defmacro future-on-edt [ body]
  `(future (get-on-edt ~...@body)))

 The do-on-edt macro executes its body on the EDT and returns nil.

 The get-on-edt macro does similarly, but returns whatever the body
 returns. It blocks until the body has returned, though, which you may
 not want, though since it executes on the EDT it should execute fast.

 The future-on-edt macro avoids this blocking behavior. It behaves as
 if you scheduled its body to run as a future on the EDT instead of on
 whatever thread(s) futures usually run on. In actual fact, the future
 it returns is executing the blocking get-on-edt. :)

 Action listener code can assume it will run on the edt, but plenty of
 other things do not; notably, REPL expressions do not, as well as
 anything explicitly launched into another thread and anything executed
 as a result of load-file or via a main class.

 This code, which I offer to the public domain, also furnishes some
 simple examples of macro design, as well as of the use of an atom to
 move information between threads, plus a recurrence of the one-cell-
 vector idiom for having both nil and meta-nil, distinguishing not-
 set-yet from actually-returned-nil. This also showed up in super-lazy-
 seq where ultimately one var could end up holding either a boxed
 return value or *two* out-of-band values, nil and :skip. (Another
 trick for returning out-of-band values is to return a two-element
 vector with a value in one cell and an accompanying bit of meta-data
 in the other, for example [item found] distinguishing [nil false] from
 [nil true]. Other lisps admit of the same trick, using a cons cell
 (item . found) for instance, or using nil vs. (item . nil) or any-atom
 vs. (item . nil). Don't know if anyone else here is familiar with
 dotted-pair notation though, except clojure's author.)
 


get-on-edt uses a busy loop, which is icky. I would use a
blockingqueue. if you are not constrained by 1.0 compatibility
promise/deliver just hit the new git repo. a promise is a new kind of
reference type that provides a blocking deref.

http://github.com/richhickey/clojure/blob/1a0e23d0e78ef3d3a3a6267a68adcfc414d3fb56/src/clj/clojure/core.clj#L4152


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: EDT interaction

2009-06-13 Thread Kevin Downey

On Sat, Jun 13, 2009 at 2:55 PM, Meikel Brandmeyerm...@kotka.de wrote:
 Hi,

 Am 13.06.2009 um 23:29 schrieb Meikel Brandmeyer:

 (defmacro get-on-edt
  [ body]
  `(get-on-edt* (fn [] ~body)))

 Of course ~...@body instead of ~body...

 Sincerely
 Meikel



I know you (Meikel) already fixed it, but I guess it is a good idea to
explain that have a macro expand to a #() form is a bad idea.
the original do-on-edt macro did expand to a #() form, which means if
you passed in another #() form you would end up with nested #() forms,
which causes an exception.

-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: EDT interaction

2009-06-13 Thread Kevin Downey

it depends how often you are pushing stuff onto the EDT. I have a
similar macro called EDT so I can do stuff like (EDT (.setText foo
bar)) alternatively I would need to type (SwingUtilities/invokeLater
#(.setText foo bar)) or even (SwingUtilities/invokeLater (fn []
(.setText foo bar)))

On Sat, Jun 13, 2009 at 5:23 PM, Aaron Cohenremled...@gmail.com wrote:

 Isn't this a case of wrapping a Java API needlessly?

 What's so bad about: (SwingUtilities/invokeLater my-func) ?
 -- Aaron



 On Sat, Jun 13, 2009 at 5:59 PM, Kevin Downeyredc...@gmail.com wrote:

 On Sat, Jun 13, 2009 at 2:55 PM, Meikel Brandmeyerm...@kotka.de wrote:
 Hi,

 Am 13.06.2009 um 23:29 schrieb Meikel Brandmeyer:

 (defmacro get-on-edt
  [ body]
  `(get-on-edt* (fn [] ~body)))

 Of course ~...@body instead of ~body...

 Sincerely
 Meikel



 I know you (Meikel) already fixed it, but I guess it is a good idea to
 explain that have a macro expand to a #() form is a bad idea.
 the original do-on-edt macro did expand to a #() form, which means if
 you passed in another #() form you would end up with nested #() forms,
 which causes an exception.

 --
 And what is good, Phaedrus,
 And what is not good—
 Need we ask anyone to tell us these things?

 


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Primitive char Type

2009-06-13 Thread Kevin Downey

user= (def s (StringBuilder. aaa))
#'user/s
user= (. s setCharAt 0 \b)
nil
user= s
#StringBuilder baa
user= (. s setCharAt (int 0) (char \b))
nil
user= (. s setCharAt (int 0) (char \e))
nil
user= s
#StringBuilder eaa
user=

works for me


On Sat, Jun 13, 2009 at 7:28 PM, tmountaintinymount...@gmail.com wrote:

 I'm writing some simple code, and I believe I'm running into trouble
 getting a primitive char.

 user= (def s (new StringBuilder aaa))
 #'user/s

 ; Java method signature is setCharAt(int index, char ch)
 user= (. s setCharAt (int 0) (char \a))

 java.lang.IllegalArgumentException: No matching method found:
 setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
 user= (type (char \a))
 java.lang.Character
 ; should be char?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Kevin Downey

you can use apply to avoid in-lining:

user= (binding [+ -] (apply + '(5 3)))
2


On Tue, Jun 16, 2009 at 11:16 AM, Michel S.michel.syl...@gmail.com wrote:



 On Jun 16, 1:42 pm, Paul Stadig p...@stadig.name wrote:
 On Tue, Jun 16, 2009 at 1:38 PM, Michel Salim michel.syl...@gmail.comwrote:



  It's currently not possible to dynamically rebind functions:

  (binding [+ -] (+ 5 3)) == 8 ;; not 2

  Thanks,

  --
  Michel S.

 It is possible to rebind (even core) functions, but there are a couple of
 limitations. One of which is the fact that some functions are inlined by the
 compiler. I believe the two argument case of '+ is one of those.

 I just verified and it does indeed work -- thanks. Time to read up on
 macros to implement this tracing construct, then.

 --
 Michel
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



with-open binding form

2008-10-13 Thread Kevin Downey

I noticed with-open kind of stuck out because it doesn't use vectors
for binding like let, loop, and others. it was a quick fix using
destructuring to make the macro use square backets
example:
(with-open [f (new java.io.FileWriter test)] do-stuff)

but as I was writing an email to this list I realized that let,loop,
etc do multiple bindings. so a few hours later I had this:

(defmacro better-with-open [b  f]
  (let [q b
h (map (fn[x] `(. ~x (close))) (take-nth 2 q))]
`(let ~q (try [EMAIL PROTECTED] (finally [EMAIL PROTECTED])

sorry about all the single letter variables, I am not exaggerating
about how long this took. Still wrapping my head around macros.

usage example:

(better-with-open [f (new java.io.FileWriter foo true)
   q (new java.io.FileWriter bar)]
  (. f (write one))
  (. q (write two)))



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



is clojure known to work on any phones with javame?

2008-10-14 Thread Kevin Downey

I am in the market for a phone and it would be so cool to have clojure
on it. Has anyone tried this yet?

-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Kevin Downey

On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote:

 Yeah, I need to be able to do this to easily manage trees of maps. I
 meant, how would you idiomatically implement their algorithms?

 Fold isn't build into Clojure, but they should still somehow be
 possible...right?

 On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote:
 On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure 
 out how to do this:

(flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2)

 (defn flat-map-seq [m]
   (if (empty? m) '()
 (let [kv (first m)]
   (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) 
 ...and vice versa:

(map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b
  1, :c 2}

 (defn map-from-flat-collection [c]
   (if (empty? c) {}
 (conj (map-from-flat-collection (rrest c)) [(first c) (frest
 c)])))

  Anyone have any idiomatic ideas?

 Well, not sure how idiomatic this is; apart from conj, this is how
 you'd do it in Lisp/Scheme. I'd use fold to do the first function if
 it's built into Clojure.

 Regards,

 --
 Michel
 


(apply assoc {} [:a 1 :b 2 :c 3])
-   {:c 3, :b 2, :a 1}
-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Kevin Downey

On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote:
 On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote:

 Yeah, I need to be able to do this to easily manage trees of maps. I
 meant, how would you idiomatically implement their algorithms?

 Fold isn't build into Clojure, but they should still somehow be
 possible...right?

 On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote:
 On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to 
 figure out how to do this:

(flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2)

 (defn flat-map-seq [m]
   (if (empty? m) '()
 (let [kv (first m)]
   (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) 
 ...and vice versa:

(map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b
  1, :c 2}

 (defn map-from-flat-collection [c]
   (if (empty? c) {}
 (conj (map-from-flat-collection (rrest c)) [(first c) (frest
 c)])))

  Anyone have any idiomatic ideas?

 Well, not sure how idiomatic this is; apart from conj, this is how
 you'd do it in Lisp/Scheme. I'd use fold to do the first function if
 it's built into Clojure.

 Regards,

 --
 Michel
 


 (apply assoc {} [:a 1 :b 2 :c 3])
 -   {:c 3, :b 2, :a 1}
 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye


user= (apply concat (seq {:c 3, :b 2, :a 1}))
(:c 3 :b 2 :a 1)
user=


-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Kevin Downey

user= (reduce concat {:a 1 :b 2 :c 3})
(:c 3 :b 2 :a 1)
user=


On Sat, Nov 15, 2008 at 4:02 AM, Matthias Benkard [EMAIL PROTECTED] wrote:

 On 15 Nov., 05:17, samppi [EMAIL PROTECTED] wrote:
 Fold isn't build into Clojure

 Isn't fold just clojure/reduce?

 Matthias
 




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Kevin Downey

user= (mapcat identity {:a 1 :b 2 :c 3})
(:c 3 :b 2 :a 1)



On Sat, Nov 15, 2008 at 4:05 AM, Kevin Downey [EMAIL PROTECTED] wrote:
 user= (reduce concat {:a 1 :b 2 :c 3})
 (:c 3 :b 2 :a 1)
 user=


 On Sat, Nov 15, 2008 at 4:02 AM, Matthias Benkard [EMAIL PROTECTED] wrote:

 On 15 Nov., 05:17, samppi [EMAIL PROTECTED] wrote:
 Fold isn't build into Clojure

 Isn't fold just clojure/reduce?

 Matthias
 




 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: strings

2008-11-18 Thread Kevin Downey

(apply str (reverse I am cold))

shorter and it does the same thing. no need to take out the spaces and
put them back in

On Tue, Nov 18, 2008 at 5:21 PM, Mark Volkmann
[EMAIL PROTECTED] wrote:

 Here's another solution that came from help on the chat. Thanks Chouser!

 (apply str (interpose   (reverse (.split I am cold  

 On Tue, Nov 18, 2008 at 7:15 PM, islon [EMAIL PROTECTED] wrote:

 (defn string-reverse [s]
  (reduce #(str %1   %2) (reverse (seq (. s (split  ))

 You're probably looking for something like this =)

 On Nov 18, 9:00 pm, joejoe [EMAIL PROTECTED] wrote:
 hello all,
 so I'm not only new to this group but I am new to Clojure.  I may be
 going about this all wrong but here's what I got.  I want to simply
 take a string and reverse it, ex: I am cold would become cold am
 I (haha I just realized that's probably how yoda would say it).  So
 for now I am hard coding my string, so myString =I am cold.

 How I am thinking of doing this is as follows:

 (loop [i 0]
 (when ( i (count myString))
 //missing code
 //
 //
 (recur (inc i

 so this probably isn't a hard thing to do but like I said I am new to
 this all.  I basically need to figure out a way to print each element
 of myString one at a time, this would allow me to figure out how to
 reverse it.

 so to my simple question, is it possible it print each element of a
 string independently?

 I know about (first myString), which will give me I printed out three
 times.  So it seems there has to be a way and I just can't seem to
 figure it out.

 thanks for any input!

 -joejoe
 




 --
 R. Mark Volkmann
 Object Computing, Inc.

 




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: seq and vector

2008-11-23 Thread Kevin Downey

I don't think you understand. clojure data structures are IMMUTABLE.
every call to conj, or anyother function returns a new object. To
optimize there is sharing of structure.

On Sun, Nov 23, 2008 at 4:38 AM, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:

 On Nov 23, 1:23 am, Rich Hickey [EMAIL PROTECTED] wrote:
 I still don't understand your expectation here. If the filter does any
 filtering, it won't return everything in the vector, so the new result
 will have fewer items. Do you want a vector with fewer items? Then
 you'll have a new vector.

 Sure. But I get a seq and not a vector. Now don't get me wrong - I
 like the whole sequence library. It's just the performance cost to get
 a vector back. That's why I mean relative to seqs the data structures
 sometimes feel like second class. In my example I no longer use a
 vector to hold items even though that would be the most appropriate
 data structure. To be more specififc:

 I have agents whose state is a vector (used as a buffer) of messages.
 There are a couple of transformation functions, e.g. tagging messages,
 removing messages from the vector etc. which are implemented with map
 and filter. In addition when messages are appended to the vector, conj
 is used and messages end up at the end of the vector. Later I noticed
 that the order was screwed because some intermediate tagging (using
 map) returned a secuence as the new agent's state and later additions
 with conj prepended messages at the front. This motivated me to ask
 for the simplest and most efficient way to get a vector back because
 that's what I wanted. Now I use a list instead of a vector and use
 reverse when necessary.

 In general, it can be efficient to perform a series of transformations
 in the seq space and then realize a vector at the end if you want. The
 lazy seqs just act as a cursor over the data, and a stream of results,
 and building a new vector from scratch by appending, as vec or (into
 [] ...) would do, is more efficient than element 'replacement'.

 If you don't expect a copy when mapping across an entire vector, and
 you want to use the immutable data structures, what alternative do you
 imagine?

 I certainly don't want to move away from immutability. It's more an
 issue with the return types. In the example setting outlined above
 suppose I have a message buffer (vector) of length n. Now some
 messages need to be tagged, which means mapping over the vector and
 possibly changing some messages. Now by changing I mean of course that
 the message m which is a map is transformed into m' where m' has
 some :tag key for instance. This mapping over the vector gives me a
 seq, i.e. the type has changed from vector to a sequence and this type
 change will cause later appending to the buffer to bahve differently.
 Now, to get a vector back I was told to use vec which AFAICS is very
 costly. Your proposal to use reduce in order to build up the new
 vector was a very good suggestion. For mapping at least. But the
 general issue for me was the type change. What would I propose? Not
 sure. I guess this behavior is by design and if I would want to get
 vectors there ios no way around copying. Which lead me to my
 conclusion that I better use a list instead of a vector. However it
 didn't give me that warm and fuzzy feeling that I normally get when
 programming in Clojure. Sorry that I can't be more specific than this.


 




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

I know you are asking about refs, but you might want to think about
using reduce to walk the line-seq. the nature of reduce lets you have
access to the line-seq, two lines at a time no need for a ref.

On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle [EMAIL PROTECTED] wrote:
 I am parsing a file and to compare the current line
 with the previous line of the file.  I am using line-seq
 to go thru the file and I thought I would create a
 ref to store the previous line.   When I want to update
 the previous line value I can't seem to do it.  I've
 never used refs before so I'm sure I'm doing something
 very stupid.

 (defstruct line :lat :lon :name)

 (defn convert [file]
   (let [prev-line (ref (struct line))]
 (with-open [r (reader file)]
(doseq [l (line-seq r)]
  (let [ps (split #, l)
 c-line (struct line (ps 0) (ps 1) (ps 2))]
(if (not= c-line @pre-line)
  (do ; do stuff here then update pre-line
 (dosync ref-set pre-line (apply struct line (vals c-line)))
 (println @pre-line  ; this prints out all nils
 doesn't seem to work



 Sorry if this email is not formatted correctly.  Something is wrong with my
 browser
 currently typing in a textarea.  Thanks.



 




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

ref-set needs its one set of parens, and the last thing in the ref-set
call needs to be a function either (fn [x] ...) or a symbol for a var
that holds a function

On Mon, Nov 24, 2008 at 2:30 PM, Brian Doyle [EMAIL PROTECTED] wrote:
 Thanks Kevin, I will try using reduce instead.  I would like to know what
 I'm doing wrong with updating the ref for future reference.  Thanks.

 On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey [EMAIL PROTECTED] wrote:

 I know you are asking about refs, but you might want to think about
 using reduce to walk the line-seq. the nature of reduce lets you have
 access to the line-seq, two lines at a time no need for a ref.

 On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle [EMAIL PROTECTED]
 wrote:
  I am parsing a file and to compare the current line
  with the previous line of the file.  I am using line-seq
  to go thru the file and I thought I would create a
  ref to store the previous line.   When I want to update
  the previous line value I can't seem to do it.  I've
  never used refs before so I'm sure I'm doing something
  very stupid.
 
  (defstruct line :lat :lon :name)
 
  (defn convert [file]
(let [prev-line (ref (struct line))]
  (with-open [r (reader file)]
 (doseq [l (line-seq r)]
   (let [ps (split #, l)
  c-line (struct line (ps 0) (ps 1) (ps 2))]
 (if (not= c-line @pre-line)
   (do ; do stuff here then update pre-line
  (dosync ref-set pre-line (apply struct line (vals
  c-line)))
  (println @pre-line  ; this prints out all nils
  doesn't seem to work
 
 
 
  Sorry if this email is not formatted correctly.  Something is wrong with
  my
  browser
  currently typing in a textarea.  Thanks.
 
 
 
  
 



 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye




 




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

On Mon, Nov 24, 2008 at 2:34 PM, Kevin Downey [EMAIL PROTECTED] wrote:
 ref-set needs its one set of parens, and the last thing in the ref-set
 call needs to be a function either (fn [x] ...) or a symbol for a var
 that holds a function

I made a mistake here. I was thinking of alter, not ref-set.


 On Mon, Nov 24, 2008 at 2:30 PM, Brian Doyle [EMAIL PROTECTED] wrote:
 Thanks Kevin, I will try using reduce instead.  I would like to know what
 I'm doing wrong with updating the ref for future reference.  Thanks.

 On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey [EMAIL PROTECTED] wrote:

 I know you are asking about refs, but you might want to think about
 using reduce to walk the line-seq. the nature of reduce lets you have
 access to the line-seq, two lines at a time no need for a ref.

 On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle [EMAIL PROTECTED]
 wrote:
  I am parsing a file and to compare the current line
  with the previous line of the file.  I am using line-seq
  to go thru the file and I thought I would create a
  ref to store the previous line.   When I want to update
  the previous line value I can't seem to do it.  I've
  never used refs before so I'm sure I'm doing something
  very stupid.
 
  (defstruct line :lat :lon :name)
 
  (defn convert [file]
(let [prev-line (ref (struct line))]
  (with-open [r (reader file)]
 (doseq [l (line-seq r)]
   (let [ps (split #, l)
  c-line (struct line (ps 0) (ps 1) (ps 2))]
 (if (not= c-line @pre-line)
   (do ; do stuff here then update pre-line
  (dosync ref-set pre-line (apply struct line (vals
  c-line)))
  (println @pre-line  ; this prints out all nils
  doesn't seem to work
 
 
 
  Sorry if this email is not formatted correctly.  Something is wrong with
  my
  browser
  currently typing in a textarea.  Thanks.
 
 
 
  
 



 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye




 




 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye




-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: loop recur vs recursion

2008-11-29 Thread Kevin Downey
the jvm does not do TCO, loop/recur allows for functional looking
recursion on the jvm with constant stack size.

On Sat, Nov 29, 2008 at 1:25 AM, bOR_ [EMAIL PROTECTED] wrote:

 Hi all,

 I wondered if there is a difference between using loop-recur or merely
 writing a recursive function. The main difference I found thus far was
 that the loop-recur can suffice with less arguments, but the recursive
 functions seem to be shorter, and perhaps more elegant?

 (defn construct-atom
  translates a number n into an set of letters of size n
  [construct length]
  (if ( (count construct) length)
(construct-atom (conj construct (char (+ (rand-int amino_acids)
 65))) length)
construct))

 (defn construct-atom-loop
  translates a number n into an set of letters of size n
  [n]
  (let [base_construct #{}]
(loop [construct base_construct]
  (if ( (count construct) n)
(recur (conj construct (char (+ (rand-int amino_acids) 65
construct


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Possible minor bug in gen-class: method name character escaping?

2009-01-16 Thread Kevin Downey

On Fri, Jan 16, 2009 at 12:22 PM, Greg Harman ghar...@gmail.com wrote:

  2. If I want the Clojure functions that underlie the methods in the
  generated class used directly by my Clojure code as well (which I do),
  then I'm stuck having to either violate standard Clojure/Lisp function
  naming conventions in favor of Java-friendly naming or I have to write
  wrapper functions like:

  (defn myMethod [obj] (my-method obj))

  Other than using the prefix and keeping the method names to one
  word, is there a better way?

 Since gen-class is used to create Java classes, it's sensible that the
 naming convention within the generated class be Java's.

 I agree that the convention inside the generated class should be a
 Java convention (my original post was more of an experiment than an
 attempt to create a working class with that signature). However, I
 find myself wanting to write a clojure function that can be exposed to
 both Clojure and Java code, and I'd like to keep them in their
 respective paradigms. That is, in Clojure, I don't want to have to
 call (.myMethod foo) when I already have (my-method) defined. And in
 Java, I want to just use foo.myMethod(), not have to wrap up a call to
 RT.var().invoke().

 I know I'm being picky, but it just seems cleaner this way...

write a macro that takes all fns in the current namespace and
generates wrappers with the correct naming style.
problem solved.



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Printing Strings in Lists

2009-01-23 Thread Kevin Downey

prn

On Fri, Jan 23, 2009 at 11:00 AM, Kevin Albrecht onlya...@gmail.com wrote:

 Below are two operations that print (1 2 3 4).  How can I do something
 similar to print (1 2 3 4) to standard out?

 (println '(1 2 3 4))
 - (1 2 3 4)

 (def x 1 2 3)
 (println `(~x 4))
 - (1 2 3 4)

 --Kevin Albrecht
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Kevin Downey

instead of using binding and eval, you can generate a (fn ) form, eval
it, keep the result function stuffed away somewhere and apply it
instead of calling eval all the time

On Fri, Jan 23, 2009 at 1:10 PM, Zak Wilson zak.wil...@gmail.com wrote:

 It does seem like a legitimate use for eval, at least at first glance.
 The biggest problem is that using eval this way is really slow when
 each rule is being tested on hundreds of inputs.

 Interesting alternative, Konrad. I can probably take advantage of the
 fact that all of the functions I'm calling (unchecked math and bitwise
 operators) take exactly two arguments. I might give something like
 that a try. I'd rather not though, if I can avoid it.

 It seems like there ought to be a way to make a function out of a list
 of symbols that would be a valid function body and then call it
 repeatedly. I was playing around with that approach at first, but
 never managed to get it right. I strongly suspect creating a function
 once and calling it 400 times will be faster than calling eval 400
 times.
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Length of Sequence

2009-01-28 Thread Kevin Downey

(doc count)
-
clojure.core/count
([coll])
  Returns the number of items in the collection. (count nil) returns
  0.  Also works on strings, arrays, and Java Collections and Maps
nil


On Wed, Jan 28, 2009 at 11:15 AM, Peter Wolf opus...@gmail.com wrote:

 Here's a dumb question, but I can't find it in the docs:

 How do I get the length of a sequence?  Is there some generic way to
 find the number of elements in something that might be list, map, vector
 or lazy?

 There must be some sort of built in function, or an idiom

 Thanks
 P

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Alternatives to contains?

2009-01-29 Thread Kevin Downey
actually rhickey showed up on irc and pointed something out:

 15:23   rhickey : user= (.contains [1 2 3] 2)
 15:23   rhickey : true
 15:23   rhickey : user= (.contains '(1 2 3) 2)
 15:23   rhickey : true
 15:23   rhickey : what contains debate? :)


so because seqs, vectors, etc are java collections

user= (.contains (map #(.getName %) (.getMethods (class (seq [:a]
contains)
true

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html

On Thu, Jan 29, 2009 at 3:38 PM, Jason Wolfe jawo...@berkeley.edu wrote:


  In that case, it makes me think of the degenerate example (I realize
  this is slightly stupid):
 
  (some #{false} (list false))

 Maybe this is an argument for adding any? to the list of core
 functions?

 -Jason
 



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Distributed Clojure

2009-01-29 Thread Kevin Downey

have you looked at the available java frameworks like hadoop? there is
also some kind of java interface to erlang
instead of reinventing the wheel again...

On Thu, Jan 29, 2009 at 6:15 AM, Greg Harman ghar...@gmail.com wrote:

 One of Clojure's big selling points (obviously) is the support for
 concurrent programming. However, the performance gains you get with
 this concurrency hits a scalability wall once you're fully utilizing
 all the cores available in your server. The next step, of course, is
 to add additional servers.

 So, I've been mulling over the idea of putting together a framework
 for distributed applications. I think it should deal with issues such
 as:

 * Locating, assessing, and registering CPUs
 * Division of large jobs into smaller sub-jobs
 * Dispatching of jobs, including optimization planning (send more jobs
 to faster CPUs)
 * Failure recovery
 * Seamless code integration (so that this can be retrofit as an
 optimization) both horizontally and vertically
   * Horizontal = take one time-consuming task and parallelize it
   * Vertical = take two sequential tasks and pipeline them across
 different servers

 Is anybody already working on something similar? Is this already on
 the Clojure language roadmap as something to be added after 1.0?

 Any design advice or feature requests if I were to put something like
 this together?

 -Greg
 



--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: purpose of clojure-slim.jar

2009-01-29 Thread Kevin Downey

clojure-slim.jar lacks compiled clojure code. The java code is
compiled, so clojure-slim.jar  is still completely usable as clojure,
it just have to compile things like core.clj when it loads them.

On Thu, Jan 29, 2009 at 4:56 PM, kkw kevin.k@gmail.com wrote:

 Hi folks,

I noticed that when I run 'ant' to build Clojure, in addition to
 clojure.jar, 'ant' gives birth to clojure-slim.jar. The build.xml says
 the clojure-slim.jar lacks compiled Clojure code. I don't know what
 purpose clojure-slim.jar serves. I searched the 
 http://groups.google.com/group/clojure/
 and found zero hits. Where would clojure-slim.jar be useful?

 Kev
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: What is defn-

2009-02-03 Thread Kevin Downey

as a namespace is to a java package, defn- is to private, and defn is to public

On Tue, Feb 3, 2009 at 8:19 PM, Terrence Brannon metap...@gmail.com wrote:

 What is the significance of the dash after defn? How does it differ
 from defn?

 Source:
 http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages:Clojure:Chapter_1#.3B_1.1.4_The_Elements_of_Programming_-_Compound_Procedures

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Tools for parsing arguments

2009-02-06 Thread Kevin Downey

you can also use map destructuring.

(defn x [{:keys [a b c]}]
  [a b c])

user= (x {:a 1 :b 2 :c 3})
 [1 2 3]

On Fri, Feb 6, 2009 at 7:52 AM, Jeffrey Straszheim
straszheimjeff...@gmail.com wrote:
 That is remarkably simple and elegant.

 On Fri, Feb 6, 2009 at 10:20 AM, Stuart Sierra the.stuart.sie...@gmail.com
 wrote:

 On Feb 6, 10:06 am, David Nolen dnolen.li...@gmail.com wrote:
  Is there anything in core or contrib for parsing arguments to a
  function? Since Clojure fns don't support optional args or even keyword
  args, is there a standard set of helpers functions to do this? I looked
  around but I didn't see anything obvious.

 No, but there is a pattern for keyword args:

 (defn my-function [ args]
  (let [options (apply hash-map args)]
...))

 Then you can call (my-function :keyword value :keyword2 value).

 -Stuart Sierra



 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: core.logic merge substitutions map?

2013-11-18 Thread Kevin Downey
https://github.com/sonian/Greenmail/blob/master/src/clj/greenmail/db.clj#L98-L126
has an example, using clojure.core.logic/all to make a goal which is a
conjunction of the clojure.core.logic/== goals

On 11/16/13, 5:04 PM, Mark wrote:
 d'oh!  Answering my own question:  Just compose the unify functions a la 
 (unify (unify a v1 (:v1 r) v2 (:v2 r))
 
 I have a feeling there is a library function/macro that would make this 
 less messy but I can't find it from the cheatsheet.
 
 On Saturday, November 16, 2013 10:31:50 AM UTC-8, Mark wrote:

 I stumbled across Timothy Baldridge's excellent video 
 http://www.youtube.com/watch?v=HHZ8iqswiCwexplaining how to incorporate 
 data sources into core.logic.  It reinvigorated my interest in using 
 core.logic to query SQL RDBMS.  I'm stumbling on a pretty simple thing, I 
 think.  I've got a table that has three columns, a single primary key 
 column and two value columns.  Using the pattern Tim outlines in his video, 
 I've got a relation function that takes three parameters, one for each 
 column and I'm trying to work through the case where the primary key is 
 ground and the value columns are lvars.  This translates to a query of the 
 form SELECT v1, v2 FROM t WHERE pkey=?.  Of course, this returns two values 
 that must be unified.  That's where I'm stuck.

 I know I want to return a substitution map, but I have two lvars to 
 unify.  How do I merge the two substitution maps?

 Sample code:
 (defn pkey-v1-v2-o [pkey v1 v2]
   (fn [a]
 (let [pkey (walk a pkey)
   v1 (walk a v1)
   v2(walk a v2)]
   (condp = [(not (lvar? pkey))
 (not (lvar? v1))
 (not (lvar? v2))]
 [true false false ] (to-stream 
   (let [r (first (query [SELECT v1, v2 FROM T 
 WHERE pkey=? pkey]))]
 (some-merge-fn (unify a v1 (:v1 r))
(unify a v2 (:v2 r)

 


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?



signature.asc
Description: OpenPGP digital signature


Re: odd failure on recursive use of protocol member

2013-12-10 Thread Kevin Downey
extend mutates some state (the protocol definition), so what is happen
here is comp is returning a new function built from the value of the
rest-serialize var (the protocol function before the extend changes it)
and the value of the deref var.

I have not verified this, but I suspect if you use (fn [x]
(rest-serialize (deref x))) instead of the comp version, you will get
the behaviour you expected

On 12/10/13, 11:50 AM, Michael Blume wrote:
 I have a protocol RestSerializable to represent data that can be serialized 
 to json from a REST interface.
 
 (defprotocol RestSerializable
   (rest-serialize [this]
Convert to something Cheshire can JSONify))
 
 By default, things are left alone
 
 (extend Object
   RestSerializable
   {:rest-serialize identity})
 
 But I want atoms and the like to be transparent when serialized
 
 (extend clojure.lang.IDeref
   RestSerializable
   {:rest-serialize (comp rest-serialize deref)})
 
 I would expect this to mean that, say, 
 
 (- 42 atom atom atom atom rest-serialize)
 
 would just unwrap to 42, but in fact it only unwraps the outer atom and 
 leaves the inner ones alone.
 
 Here's where it gets weird though. If I just evaluate the extend 
 clojure.lang.IDeref form again, rest-serialize suddenly gains the ability 
 to unwrap *two* layers of atoms. Eval it again and it can unwrap *three*. 
 Kinda feels like the exercises in Little Schemer when they're building up 
 to the Y Combinator.
 
 Here's my REPL session demonstrating this (not shown, but I've verified 
 this behavior is the same in Clojure 1.5.1 and Clojure 1.6.0-alpha3)
 
 $ lein repl
 nREPL server started on port 46049 on host 127.0.0.1
 REPL-y 0.2.1
 Clojure 1.5.1
 Docs: (doc function-name-here)
   (find-doc part-of-name-here)
   Source: (source function-name-here)
  Javadoc: (javadoc java-object-or-class-here)
 Exit: Control+D or (exit) or (quit)
  Results: Stored in vars *1, *2, *3, an exception in *e
 
 user= (defprotocol RestSerializable
   #_=   (rest-serialize [this]
   #_=Convert to something Cheshire can JSONify))
 RestSerializable
 user= 
 
 user= (extend Object
   #_=   RestSerializable
   #_=   {:rest-serialize identity})
 nil
 user= 
 
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 #Atom@56153406: #Atom@a0aa211: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@3c19a5b0: #Atom@37cce4a3: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@9f6e629: #Atom@308092db: 7
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 #Atom@7fb48906: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@41e224a5: 7
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 7
 user= (quit)
 Bye for now!
 


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?



signature.asc
Description: OpenPGP digital signature


Re: let bindings

2014-01-20 Thread Kevin Downey
On 1/20/14, 12:38 PM, Andy Smith wrote:
 Hi,
 
 (let bindings form) is a special form. As I understand it, let can be 
 reformulated in terms of functions e.g.
 
  (let [x 2] (* x 20)) equivalent to ((fn [x] (* x 20)) 2)
 (let [x 3 y (* x x)] (- y x)) equivalent to ((fn [x] ((fn [x y] (- y x)) x 
 (* x x))) 3)
  
 So if we can always reformulate in this was, why cant let be implemented as 
 a macro rather than a special form?
 
 Where have I gone wrong in my understanding here?
 
 Andy
 

Clojure has made several choices which make implementing let via macro
expanding to function application a nonstarter:

1. Clojure is compiled.
  There is no interpreter for clojure, all clojure code is compiled to
bytecode before executing, even at the repl. So the compiler needs to be
fast for interactive work and cannot spend a lot of time in optimizing
passes typically used to avoid function call overhead for every local
name binding.

2. Debuggers
  There are a number of nice debugging tool kits for Java/the JVM. They
operating by reading metadata (like local names) from class files.
Because clojure maps let bound locals to the same JVM construct as Java,
you can re-use Java debuggers for Clojure.

3. JVM interop
  The JVM does not have TCO built in, so in order to provide general
constant space tail calls you must do extensive code transforms(breaks 1
and 2) or use your own calling convention(method call and trampoline,
instead of just a method call) which would complicate interop. Clojure
instead provides less general construct loop/recur for constant space
iteration. loop/recur is local to a function body, so if let macro
expanded to a fn call, you would not be able to recur from inside a let.

So while technically possible (there are scheme impls on the jvm that
may) Clojure does not expand let in to a fn call

-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: test.check, quickcheck concurrency

2014-03-31 Thread Kevin Downey
On 3/28/14, 9:48 PM, Brian Craft wrote:
 Re: John Hughes' talk at clojure/west, at the end he did a fairly 
 incredible demo of testing concurrency. It doesn't look like this was 
 implemented in test.check (or I'm not finding it). Are there any plans?
 

from my understanding his approach is using quickcheck to generate
histories and then check those histories for linearizability.

maybe some combination of test.check and
https://github.com/aphyr/knossos could do that.

-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding type hint causes compiler error

2009-07-05 Thread Kevin Downey

On Sun, Jul 5, 2009 at 5:18 AM,
philip.hazel...@gmail.comphilip.hazel...@gmail.com wrote:

 Hi,

 The following code works as expected:

 (import 'javax.imageio.ImageIO 'java.io.File
 'java.awt.image.BufferedImage)
 (defn bi-get-pixels
  [bi]
  (vec (.. bi (getData) (getPixels 0 0 (.getWidth bi) (.getHeight bi)
 nil
 (bi-get-pixels (. ImageIO read (File. /home/phil/prog/small-
 test.png)))

 But if *warn-on-reflection* is true, it generates four warnings. If we
 try to shut it up with a type hint:

 (defn bi-get-pixels
  [#^BufferedImage bi]
  (vec (.. bi (getData) (getPixels 0 0 (.getWidth bi) (.getHeight bi)
 nil

 Exception in thread main java.lang.IllegalArgumentException: More
 than one matching method found: getPixels (imagio-test.clj:7)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:4558)
 ...
 Caused by: java.lang.IllegalArgumentException: More than one matching
 method found: getPixels
        at clojure.lang.Compiler.getMatchingParams(Compiler.java:2122)
        at clojure.lang.Compiler$InstanceMethodExpr.init
 (Compiler.java:1159)
        at clojure.lang.Compiler$HostExpr$Parser.parse(Compiler.java:
 810)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:4551)
        ... 34 more

 The problem here is that getPixels has three forms: (
 http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/Raster.html )
  double[]       getPixels(int x, int y, int w, int h, double[] dArray)
          Returns a double array containing all samples for a
 rectangle of pixels, one sample per array element.
  float[]        getPixels(int x, int y, int w, int h, float[] fArray)
          Returns a float array containing all samples for a rectangle
 of pixels, one sample per array element.
  int[]  getPixels(int x, int y, int w, int h, int[] iArray)
          Returns an int array containing all samples for a rectangle
 of pixels, one sample per array element.

 In each case, if the final argument is NULL it is ignored, and if not
 the array is populated with the return data from the call (generating
 an error if it's not large enough).

 Is it possible to specify which invocation of getPixels I intend
 without passing an array? I've tried putting #^ints in some likely-
 looking places, but nil can't be type-hinted and the others seem to
 have no effect. I've also tried splitting the .. up:

 (defn bi-get-pixels
  [#^BufferedImage bi]
  (let [rast (.getData bi)
        #^ints pi (.getPixels rast 0 0 (.getWidth bi) (.getHeight bi) nil)]
    pi))

you change (.getPixels rast 0 0 (.getWidth bi) (.getHeight bi) nil)
to something like (.getPixels rast (int 0) (int 0) (.getWidth bi)
(.getHeight bi) nil)


 But this doesn't work either. I could do manual reflection on Raster
 to get the correct method and .invoke it, but that seems far more
 complicated than necessary. Any other ideas?

 -Phil
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ArithmeticException with doubles

2009-07-10 Thread Kevin Downey

On Fri, Jul 10, 2009 at 1:00 PM, Daniel Lyonsfus...@storytotell.org wrote:


 On Jul 10, 2009, at 12:24 PM, Sean Devlin wrote:


 A quick java program:

 public static void main(String[] args) {
    System.out.println(1.0/0.0);
 }

 Infinity


 On Jul 10, 11:08 am, John Harrop jharrop...@gmail.com wrote:
 This is odd:
 user= (/ 1.0 0.0)
 #CompilerException java.lang.ArithmeticException: Divide by zero
 (NO_SOURCE_FILE:0)

 Shouldn't it be Double/POSITIVE_INFINITY?

 I think there's still room for an argument here, if anyone wants to
 have one.

 http://scienceblogs.com/goodmath/2008/10/infinity_is_not_a_number.php

 I'm not convinced that x/0 is arithmetically infinity thanks to Mark's
 blog post there and it sure bugs me when I do something stupid and get
 Infinity back instead of an error. It's like a timebomb in my code,
 concealing where the real mistake was. I do like having the constant
 there for doing algorithms that depend on it (Dijkstra's SSSP comes to
 mind) but I think x/0 is an error (unless it's 0/0).

 —
 Daniel Lyons


 


using math knowledge to answer (corner) cases of the floating point
spec is silly
people using doubles should be able to expect doubles to behave like doubles

-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure vectors

2009-07-13 Thread Kevin Downey

the sequence functions operate on sequences. if you pass in something
that is not a sequence, like a vector, they call seq on it internally.
so what you get back from filter or map is a sequence. conj has
consistent behavior across types, you just get a different type out of
map/filter/etc then what goes in.

On Mon, Jul 13, 2009 at 8:15 AM, Jan Rychterj...@rychter.com wrote:

 I've been trying to implement stacks using vectors in Clojure. In case
 you wonder why, it's because I need stacks with a fast item count
 operation. While experimenting I discovered some vector properties which
 were unexpected.

 conj adds at the end of the vector as expected:

 user (conj [1 2 3] 4)
 [1 2 3 4]

 However, after reading Programming Clojure (page 114) I expected to be
 able to use sequence functions, such as drop-last, without my vectors
 changing representation. It seems this is not the case, as after calling
 drop-last (or indeed any of the seq functions) conj no longer adds at
 the end:

 user (conj (drop-last 1 [1 2 3]) 4)
 (4 1 2)

 I don't know if it also has performance implications (does it turn my
 vector into a list?). So it turns out that pretty much the only
 operations I can use on my vectors are subvec and pop:

 user (conj (subvec [1 2 3] 0 2) 4)
 [1 2 4]
 user (conj (pop [1 2 3]) 4)
 [1 2 4]
 user

 I didn't expect this to happen. Most tutorials (and Stuart Halloway's
 book) emphasize the generality of the sequence functions, only
 mentioning that subvec is faster for vectors. I think the fact that they
 also change subsequent behavior of conj is fundamental and should be
 printed in bold type.

 Am I missing something here?

 And while we're on the subject -- any hints for implementing a stack
 with a fast item count? (apart from a list with a separate counter)

 --J.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: another binding issue?

2009-07-14 Thread Kevin Downey

closures capture lexical scope, binding creates dynamic scope. lexical
scope is where a closure is defined, dynamic is when it is called.

because filter is lazy, the closure is called outside the dynamic
scope created by binding

On Jul 14, 1:07 pm, Aaron Cohen remled...@gmail.com wrote:
 I'm a little unclear on why this happens still.
 #(= % a) is a closure, correct?  My understanding is that this should
 capture the environment when it is defined.  Why does the environment not
 include the current bindings?

 -- Aaron

 On Tue, Jul 14, 2009 at 4:03 PM, Mark Engelberg 
 mark.engelb...@gmail.comwrote:





  On Tue, Jul 14, 2009 at 12:40 PM, Jarkko Oranenchous...@gmail.com wrote:
   This is a common gotcha. It's actually a laziness issue: the seq
   produced by filter is realised only after it exits the binding scope,
   thus producing '(1). You need to use doall to force the seq if you
   want the binding to apply.

  Yeah, but more and more I'm finding that with complex code, it can be
  rather difficult to identify the parts that are lazy and the parts
  that aren't.  Which makes using binding rather risky.  I've started to
  refactor most of my code to avoid dynamic binding, because I'm tired
  of getting burned by this gotcha.  Which is a shame.
--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: another binding issue?

2009-07-14 Thread Kevin Downey

this is how you do it:

user= (def a 0)
#'user/a
user= (binding [a 1] (map #(+ % a) (range 5)))
(0 1 2 3 4)
user= (binding [a 1] (let [a a] (map #(+ a %) (range 5
(1 2 3 4 5)
user=

you capture the dynamic scope in the lexical scope so the closure can
close over it.

dunno how applicable this is to more complex uses of binding

On Tue, Jul 14, 2009 at 6:09 PM, Mark Engelbergmark.engelb...@gmail.com wrote:

 It almost seems like what you want is for lazy data structures to
 close over the dynamic vars that have been modified from their root
 bindings at the time the lazy data structure is created.  Seems like
 coming up with well-defined semantics for this would be an interesting
 research problem, and if done properly, could end up matching people's
 intuition and being a lot more useful than the current awkwardness of
 the way that vars and laziness interact.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Function overriding? Way to do it, similar to in Java

2009-07-24 Thread Kevin Downey

yes there is a way: http://clojure.org/multimethods

On Fri, Jul 24, 2009 at 11:44 AM, BerlinBrownberlin.br...@gmail.com wrote:

 Are there ways to override functions so that if you have different
 parameters, you get different logic?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure success story ... hopefully :-)

2009-08-21 Thread Kevin Downey

user= (defmulti length empty?)
#'user/length

user= (defmethod length true [x] 0)
#MultiFn clojure.lang.mult...@1807ca8

user= (defmethod length false [x] (+ 1 (length (rest x
#MultiFn clojure.lang.mult...@1807ca8

user= (length [1 2 3 4])
4


On Fri, Aug 21, 2009 at 12:41 PM, Michel
Salimmichael.silva...@gmail.com wrote:

 On Fri, 2009-08-21 at 11:02 -0700, Sigrid wrote:
 Hi,

 I read the related story on InfoQ and found it an extremely
 interesting and motivating read, Clojure being applied in such an
 interesting field as machine learning!

 There is something in the article I'd like to understand better, so
 i'm just asking here on the group:

 The way that Rich elected to de-couple destructuring bind from
 pattern matching was brilliant.

 Could someone point me to what the difference is? I know pattern
 matching e.g. from the PLT scheme implementation, and there the
 pattern matching also provides the binding and destructuring I
 think...?

 Clojure allows destructuring of vectors, which happens to be what its
 functions' argument lists are, so you get most of the benefits of
 pattern matching. It's not full-blown, though, so (correct me if I'm
 wrong) the equivalent of this is not possible:

 length [] = 0
 length (_:xs) = 1 + (length xs)

 Regards,

 --
 Michel


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure classpaths

2009-09-01 Thread Kevin Downey

you could try running this test script:

http://gist.github.com/179346

the script downloads clojure and does a test aot compile.

if everything works the only output you should see is Hello World

example:

hiredman rincewind ~% sh ./clojure-aot-test.sh
Hello World


On Tue, Sep 1, 2009 at 11:37 AM, Terrance Davisterrance.da...@gmail.com wrote:

 The details help a lot. I was able to ensure I am doing the same steps
 with a file not found exception instead of a working file.

 I notice that the you used 'clojure.jar' whereas I am using
 'clojure-1.0.0.jar'. Did you happen to compile your clojure.jar from
 source? I used the current release download. I am starting to wonder
 if I need to build from source to get this classpath problem to go
 away.

 On Tue, Sep 1, 2009 at 12:05 PM, Krukowkarl.kru...@gmail.com wrote:



 On Sep 1, 5:03 pm, Terrance Davis terrance.da...@gmail.com wrote:
 Okay. Here's some additional information.

 I have tried on OS X 10.6 and Vista and no dice either place. I am NOT

 This works for me on Mac:
 krukow:~/examples$ ls -R
 classes         clojure.jar     src
 ./classes:
 ./src:
 clojure
 ./src/clojure:
 examples
 ./src/clojure/examples:
 hello.clj
 krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.main
 Unable to find a $JAVA_HOME at /usr, continuing with system-provided
 Java...
 Unable to find a $JAVA_HOME at /usr, continuing with system-provided
 Java...
 Clojure 1.1.0-alpha-SNAPSHOT
 user= (compile 'clojure.examples.hello)
 clojure.examples.hello
 user= (clojure.examples.hello.)
 #hello clojure.examples.he...@dfbabd
 user= ^D
 krukow:~/examples$ java -cp clojure.jar:./src:./classes
 clojure.examples.hello Karl
 Unable to find a $JAVA_HOME at /usr, continuing with system-provided
 Java...
 Unable to find a $JAVA_HOME at /usr, continuing with system-provided
 Java...
 Hello Karl!
 krukow:~/examples$

 


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dynamically Changing Functions in Compiled Code

2009-09-05 Thread Kevin Downey

gen-class generates a stub java class that dispatches to clojure
functions, you can re-def the clojure functions that back the stubbed
out class.

On Sat, Sep 5, 2009 at 12:10 PM, Gorsals...@tewebs.com wrote:

 I am trying to add clojure code to an eclipse plugin. To do so, the
 code i compiled into class files via the clojure-dev plugin. I have a
 generate class, ParenMatcher, which i use ever so often. This class
 has a function which i would like to change dynamically while
 debugging it. In other words,  If an error is thrown inside it, i
 would like to change it instead of closing the plugin and restarting
 all over again!

 I've tried recompiling while the plugin is running, but that doesn't
 work. Any ideas how to do this code hot swapping?
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dynamically Changing Functions in Compiled Code

2009-09-05 Thread Kevin Downey

http://gist.github.com/163140

for example this code creates a repl on port 4445 you can interact
with via telnet. so you would have the plugin evaluate this code (to
start the repl) you can then telnet in, and past new definitions for
the functions

On Sat, Sep 5, 2009 at 8:23 PM, Seth Burleighs...@tewebs.com wrote:

 How is this supposed to work? I use AOT compilation to produce the class 
 files, and I have tried to recompile the functions but it doesn't appear to 
 have an effect. I'm including the clojure as class files, are you saying that 
 all I have to do is recompile the clojure functions? Of course, I have to 
 admit, when I compile something I only know how to compile the whole 
 namespace not just the functions. I guess what I'm saying is that I have no 
 idea how to use the REPL with a running eclipse plugin which has clojure code 
 in it. So I can't simply redef it...

 -Original Message-
 From: clojure@googlegroups.com [mailto:cloj...@googlegroups.com] On Behalf Of 
 Kevin Downey
 Sent: Saturday, September 05, 2009 7:46 PM
 To: clojure@googlegroups.com
 Subject: Re: Dynamically Changing Functions in Compiled Code


 gen-class generates a stub java class that dispatches to clojure
 functions, you can re-def the clojure functions that back the stubbed
 out class.

 On Sat, Sep 5, 2009 at 12:10 PM, Gorsals...@tewebs.com wrote:

 I am trying to add clojure code to an eclipse plugin. To do so, the
 code i compiled into class files via the clojure-dev plugin. I have a
 generate class, ParenMatcher, which i use ever so often. This class
 has a function which i would like to change dynamically while
 debugging it. In other words,  If an error is thrown inside it, i
 would like to change it instead of closing the plugin and restarting
 all over again!

 I've tried recompiling while the plugin is running, but that doesn't
 work. Any ideas how to do this code hot swapping?
 




 --
 And what is good, Phaedrus,
 And what is not good—
 Need we ask anyone to tell us these things?




 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Correct idiom for looping inside a catch or finally form?

2009-09-13 Thread Kevin Downey

user= (macroexpand '(with-open [x A y Y] do stuff here))
(let* [x A] (try (clojure.core/with-open [y Y] do stuff here) (finally
(. x clojure.core/close
user=

with-open expands to a (try (finally (.close ...)))

On Sun, Sep 13, 2009 at 7:38 PM, Richard Newman holyg...@gmail.com wrote:

 Clojure does not seem to support iteration inside catch or finally
 forms.

 Apparently not directly. Splitting the iteration into a separate named
 function works, though:

 (defn print-seq [foo]
   (doseq [x foo]
     (println x)))

 (let [foo (atom [1 2 3])]
   (try
     (throw (new Exception foo))
   (catch Exception e
     (print-seq @foo


 so you could try

 (defn close-all-files [files]
   (doseq [file files]
     (.close file)))

 (let [files (atom [])]
   (try
     (open-my-many-files files)
     ;; the files atom now refers to a vector of open file handles
     (do-dangerous-io @files)
     (finally
       (close-all-files @files

 -R

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Procedure for getting patches applied

2009-09-16 Thread Kevin Downey

have you seen http://clojure.org/patches ?

On Wed, Sep 16, 2009 at 12:53 PM, Howard Lewis Ship hls...@gmail.com wrote:
 What is the procedure for getting patches (to clojure-contrib) committed?
 I've created a couple of issues in Assembla, created and attached patches.
 What's the next step to get it actually picked up?
 http://www.assembla.com/spaces/clojure-contrib/tickets/6-Add-set-of-regular-expression-functions
 http://www.assembla.com/spaces/clojure-contrib/tickets/24?batch=tickets_report_id=3ticket_id=24commit=Go+%C2%BB
 Is there a particular action to trigger, or person to assign to?

 --
 Howard M. Lewis Ship

 Creator of Apache Tapestry

 The source for Tapestry training, mentoring and support. Contact me to learn
 how I can get you up and productive in Tapestry fast!

 (971) 678-5210
 http://howardlewisship.com

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java/scala oneliner

2009-09-17 Thread Kevin Downey

:(

map is lazy, so you'll need to wrap it in doall

(dotimes [i 4] (println Happy Birthday ({2 Dear XXX} i To You)))

On Thu, Sep 17, 2009 at 9:17 PM, David Nolen dnolen.li...@gmail.com wrote:
 Actually to be fair, here's a Clojure version that uses as little whitespace
 as the Scala and Java ones do.
 (map #(strHappy Birthday %)(assoc (vec (replicate 4To You))2Dear XXX))
 ; - 76 chars

 On Fri, Sep 18, 2009 at 12:14 AM, David Nolen dnolen.li...@gmail.com
 wrote:

 Your basic approach seems sound:
 (map #(str Happy Birthday  %) (assoc (vec (replicate 4 To You)) 2
 Dear XXX) - 81 chars including white space
 for(int i=0;i4;i++){System.out.println(Happy Birthday +(i==2?Dear
 XXX:To You));}) - 88 chars
 (1 to 4).map{i=Happy Birthday %s.format(if(i==3)Dear XXXelseTo
 You)}.foreach{println(_)} - 95 chars
 Anyone have a shorter version? :)
 On Thu, Sep 17, 2009 at 11:53 PM, Wilson MacGyver wmacgy...@gmail.com
 wrote:

 This blog post got me thinking.
 http://www.artima.com/weblogs/viewpost.jsp?thread=268561

 Basically it contains both a Java one liner and Scala one liner.

 Java:
 for(int i=0; i4; i++) { System.out.println(Happy Birthday  + (i==2
 ? Dear XXX : To You)); }

 Scala:
 (1 to 4).map { i = Happy Birthday %s.format(if (i == 3) Dear XXX
 else To You) }.foreach { println(_) }

 the goal is to generate

 Happy Birthday To You
 Happy Birthday To You
 Happy Birthday Dear XXX
 Happy Birthday To You


 I started thinking about how to do this in clojure. My first reaction was
 to
 think of the sentences as two sequences. Uses replicate to generate
 them, and map str to join them from two collections.

 ie, (map str (replicate 4 Happy Birthday )...

 Is there a more clojure way to do it?
 because using replicate to generate the 2nd sequence seem like cheating.
 ie, replicate 2 To You, 1 Dear XXX, and then To You again.



 --
 Omnem crede diem tibi diluxisse supremum.





 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: agents swallowing exceptions?

2009-10-19 Thread Kevin Downey

If any exceptions are thrown by an action function, no nested
dispatches will occur, and the exception will be cached in the Agent
itself. When an Agent has errors cached, any subsequent interactions
will immediately throw an exception, until the agent's errors are
cleared. Agent errors can be examined with agent-errors and cleared
with clear-agent-errors.

-- http://clojure.org/agents

On Mon, Oct 19, 2009 at 3:41 PM, Raoul Duke rao...@gmail.com wrote:

 hello,

 it seems like when i'm running agent stuff via load-file etc. in the
 repl, exceptions in fns the agent runs don't appear to be logged
 anywhere, they are seemingly silently swallowed. personally i find
 that frustrating. is there some way to make them always verbose / spit
 out to stdout? or am i just crazy and they are showing up and i just
 don't see them? :}

 many thanks.

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Removing duplication of redis/with-server in every function?

2009-10-23 Thread Kevin Downey

I think the point of this style of api is you just define your functions like

(defn one [] )
(defn two [] )

and call  the function like

(redis/with-server *db*
(one) (two))


On Thu, Oct 22, 2009 at 2:44 PM, Radford Smith radscr...@gmail.com wrote:

 I'm trying out redis-clojure. Right now, my code looks like this:

 (defn one []
  (redis/with-server *db*
    (...)))

 (defn two []
  (redis/with-server *db*
    (...)))

 (defn three []
  (redis/with-server *db*
    (...)))

 It feels wrong to repeat myself every time I need to use the database.
 Is there a way to abstract out the (redis/with-server) part?

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Constructing Java Interop calls

2009-10-28 Thread Kevin Downey

you can always just construct the call as a string or as a
datastructure and pass it through read/eval

On Wed, Oct 28, 2009 at 2:04 PM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 28.10.2009 um 20:46 schrieb Tiago Antão:

 But my point is to be able to construct the method name in runtime.

 You'll need reflection for that. AFAIU method calls are wired in the
 bytecode and hence the method name must be known at compile time.

 Sincerely
 Meikel





-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Constructing Java Interop calls

2009-10-29 Thread Kevin Downey

user= ((eval `(fn [x#] (~(symbol .setFileSelectionMode) x# 1))) jfc)
nil
user=


On Thu, Oct 29, 2009 at 6:38 AM, Meikel Brandmeyer m...@kotka.de wrote:

 Hi,

 On Oct 29, 2:07 pm, Tiago Antão tiagoan...@gmail.com wrote:

 The eval form still shows some problems, if I do this preparation:

 (import javax.swing.JFileChooser)
 (def jfc (new JFileChooser))

 And then do:

 user= (.setFileSelectionMode jfc 1)
 nil

 All good here, but, if I do the eval variation,
 user= (eval (list (symbol .setFileSelectionMode) jfc 1))

 Another example which shows that eval is not worth the trouble. It is
 better to use reflection. You cannot embed the JFileChooser as a
 object into the code. You have to construct it in your eval. (eval `
 (let [chooser# (JFileChooser.)] (~(symbol .setFileSelectionMode)
 chooser# 1) chosser#)).

 Hopes this helps.

 Sincerely
 Meikel

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Constructing Java Interop calls

2009-10-30 Thread Kevin Downey

eval calls read for somethings.

2009/10/30 Tiago Antão tiagoan...@gmail.com:

 On Thu, Oct 29, 2009 at 1:38 PM, Meikel Brandmeyer m...@kotka.de wrote:
 All good here, but, if I do the eval variation,
 user= (eval (list (symbol .setFileSelectionMode) jfc 1))

 Another example which shows that eval is not worth the trouble. It is
 better to use reflection. You cannot embed the JFileChooser as a
 object into the code. You have to construct it in your eval. (eval `
 (let [chooser# (JFileChooser.)] (~(symbol .setFileSelectionMode)
 chooser# 1) chosser#)).

 Thanks for all the people that helped. But I just wonder, why?
 I mean, why one cannot embed an object in the eval code?

 Tiago

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Creating custom exceptions in clojure gen--class use?

2009-11-01 Thread Kevin Downey

it'd be nice if clojure came with an Exception class that extended
IMeta so you could use (catch MetaException e (if (= :my-exception
(type e)) do-stuff (throw e)))

On Sun, Nov 1, 2009 at 1:07 PM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 01.11.2009 um 20:47 schrieb Teemu Antti-Poika:


 The only way I have managed to achieve this so far is to pre-compile
 the class using gen-class and a separate compilation step. While
 googling for solution I came across the old gen-and-load-class, which
 seemed to do the trick in the old days (?) but is there a current way
 do achieve the same?

 gen-class is what you are looking for. You can also use
 clojure.contrib.condition, but that also requires a compilation step.

 Be aware: you have to compile the class only once! As long as you
 don't change the signatures, you can redefine the underlying clojure
 code for the methods as you like without the need of recompilation. So
 compilation is a very weak argument against a solution if it solves
 your problem.

 Sincerely
 Meikel





-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Applying static java method to seq

2009-11-02 Thread Kevin Downey

(Integer/parseInt 5) is actually (. Integer parseInt 5) which
works fine because . is the operator position, and . is a special
form

On Mon, Nov 2, 2009 at 11:32 AM, ataggart alex.tagg...@gmail.com wrote:

 If (Integer/parseInt 5) works, then not all functions need be an
 implementation of IFn; or perhaps more precisely, clojure knows when a
 call is being made to an IFn vs a static java method.  It would be
 nice for consistency if whatever makes that work also treated Integer/
 parseInt as a function with respect to higher-order functions such as
 map.  Even the naive implementation of just automatically wrapping
 such uses in an anonymous function would go a long way to removing
 boiler-plate.




 On Nov 2, 11:03 am, Richard Newman holyg...@gmail.com wrote:
  Direct references to methods don't work in higher-order functions
  for some reason.

 The reason is simply that Java methods are not first-class objects in
 Clojure.

 Clojure functions are classes that implement IFn, and thus can be
 passed around as objects. That's all higher-order functions are.

 The reason the anonymous function technique works is that it creates a
 class that implements IFn, which just happens to call the Java method
 you want.
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Baffled by NPE

2009-11-03 Thread Kevin Downey

(f (first items)) = nil
((f (first items)) (for-each f (rest items))) = (nil (for-each f
(rest items))) = (.invoke nil (for-each f (rest items))) = calling a
method on nil is a NPE

lists are function applications

On Tue, Nov 3, 2009 at 9:33 AM, Dean Wampler deanwamp...@gmail.com wrote:
 I'm working the exercises in SICP using Clojure and learning Clojure as I
 go. I've stumbled across a mystifying NullPointerException. I'm implementing
 exercise 2.23, where you're supposed to implement a for-each method that
 takes a function and a list of items. It applies the function to teach item.
 Here's what I tried.
 (defn for-each [f items]
   (if (not (empty? items))
       ((f (first items)) (for-each f (rest items)   ; line #3

 (for-each (fn [x] (println (* x x))) (list 1 2 3 4 5))
 Here's the output:
 1
 4
 9
 16
 25
 Exception in thread main java.lang.NullPointerException (ex2.23.clj:0)
         at clojure.lang.Compiler.eval(Compiler.java:4620)
         at clojure.lang.Compiler.load(Compiler.java:4934)
         at clojure.lang.Compiler.loadFile(Compiler.java:4901)
         at clojure.main$load_script__7261.invoke(main.clj:210)
         at clojure.main$script_opt__7298.invoke(main.clj:262)
         at clojure.main$main__7322.doInvoke(main.clj:337)
         at clojure.lang.RestFn.invoke(RestFn.java:413)
         at clojure.lang.Var.invoke(Var.java:359)
         at clojure.lang.AFn.applyToHelper(AFn.java:173)
         at clojure.lang.Var.applyTo(Var.java:476)
         at clojure.main.main(main.java:37)
 Caused by: java.lang.NullPointerException
         at user$for_each__1.invoke(ex2.23.clj:3)
         at user$for_each__1.invoke(ex2.23.clj:3)
         at user$for_each__1.invoke(ex2.23.clj:3)
         at user$for_each__1.invoke(ex2.23.clj:3)
         at user$for_each__1.invoke(ex2.23.clj:3)
         at user$eval__4.invoke(ex2.23.clj:5)
         at clojure.lang.Compiler.eval(Compiler.java:4604)
         ... 10 more

 I tried replacing the list in the last line with a vector. Same result.
 Suggestions welcome!
 dean

 --
 Dean Wampler
 coauthor of Programming Scala (O'Reilly)
 -  http://programmingscala.com

 twitter: @deanwampler, @chicagoscala
 Chicago-Area Scala Enthusiasts (CASE):
 -  http://groups.google.com/group/chicagoscala
 -  http://www.meetup.com/chicagoscala/ (Meetings)
 http://www.linkedin.com/in/deanwampler
 http://www.polyglotprogramming.com
 http://aquarium.rubyforge.org
 http://www.contract4j.org

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Consistency of the API

2009-11-09 Thread Kevin Downey

I don't understand, the error message you get is the error that occurred.

the docstring from even? says it throws an exception if the argument
is not and integer.

I would hope that anyone that has read the docstring for contains?
would not use (contains? 'foo 'bar), because, uh, that just makes no
sense. I mean that usage does not match what is indicated in the
docstring

2009/11/9 Tiago Antão tiagoan...@gmail.com:

 Hi all,

 Just a question about the consistency of the API:
 When one passes a strange (ie, wrong type) object to contains?, say
 (contains? 'blab 'a)
 the result is a false.
 But if  one passes the wrong type to, e.g., even?, like
 (even? 'a)
 The result is:
 java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to
 java.lang.Number (NO_SOURCE_FILE:0)

 This seems a bit inconsistent, in the sense that one would expect the
 same behavior for the same kind of error.

 So the question is: is there any thing less obvious here (at least for
 me), or is this a real issue with the API?

 Thanks,
 Tiago

 --
 The hottest places in hell are reserved for those who, in times of
 moral crisis, maintain a neutrality. - Dante

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Consistency of the API

2009-11-09 Thread Kevin Downey

the behavior of functions outside of their domain is undefined. I
guess I still don't get it. why would you use a function on something
outside of its domain? do people just pick functions at random to
compose their programs?


2009/11/9 Tiago Antão tiagoan...@gmail.com:

 On Mon, Nov 9, 2009 at 8:08 PM, Kevin Downey redc...@gmail.com wrote:

 I don't understand, the error message you get is the error that occurred.

 Both of them honor their documentation - no doubt. My point is not
 that, my point is that the behavior is different between the 2
 functions for the same kind of issue:

 What is the rationale for even? and contains? having different
 behaviors for the exact same error (ie, one throws the other works
 fine and just returns false on a type error)? From a design
 perspective this seems to increase the cognitive load to programmers
 without any (apparent) reason.

 One would imagine that both functions should have the same behavior
 for the same kind of error...

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Consistency of the API

2009-11-09 Thread Kevin Downey

what makes functional programming better is the reduction of state. so
for example, if I decide that the function call out to contains? is
too much overhead in a tight loop, I can just copy and paste the
relevant code without being concerned that I might miss some crucial
piece of state it twiddles somewhere.

The true beauty of functional programming has little directly to do
with modes of failure. The beauty of functional programming is
transparency of code. I would argue that the kinds of errors you see
are an exact result of this transparency, each one is a little X-ray
window into the inner workings of the function.

On Mon, Nov 9, 2009 at 12:49 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:

 Here's another way to think about it.

 Why is functional programming better than imperative programming?

 One common answer to this question is that functional programs are
 easier to debug.  Why?  Because in an imperative program, if one part
 has an error, the error doesn't necessarily manifest in the portion of
 code that has the error.  Instead, a little piece of memory or state
 can be corrupted in one spot, and then much, much later, an error
 happens as a result of this inconsistency.  Thus the need for
 sophisticated debuggers and steppers to identify where the corruption
 happened (since the manifestation of the error doesn't really help you
 know the source of the problem).

 However, in a functional program, you have these well-defined pieces
 that reliably return the same output for a given set of inputs, making
 it easier to test individual components, and when something produces
 an error, it's pretty easy to pinpoint the function where things went
 wrong.

 Unfortunately, when core functions don't produce errors for invalid
 inputs, then you have a similar problem as with imperative languages.
 It becomes rather easy to write a program where the consequence of an
 error is far removed from the source.

 I have been told that Erlang programmers have developed a culture
 where errors are generally not caught or disguised in any way.
 There's sort of a crash early and crash hard philosophy, to increase
 the likelihood that a crash will happen in the block of code that is
 causing the problem and not later.

 On Mon, Nov 9, 2009 at 12:35 PM, Mark Engelberg
 mark.engelb...@gmail.com wrote:
 On Mon, Nov 9, 2009 at 12:32 PM, Kevin Downey redc...@gmail.com wrote:

 the behavior of functions outside of their domain is undefined. I
 guess I still don't get it. why would you use a function on something
 outside of its domain? do people just pick functions at random to
 compose their programs?

 Of course they don't pick functions at random, but people do make
 mistakes.  Although I don't mind Clojure's approach, it is reasonable
 for people to want clear error messages when they use a function
 improperly.


 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure event handling

2009-11-12 Thread Kevin Downey
http://paste.lisp.org/display/87611#2

infinite seq of swing events

On Thu, Nov 12, 2009 at 1:48 AM, Jeff Rose ros...@gmail.com wrote:
 On Nov 12, 1:22 am, nchubrich nicholas.chubr...@gmail.com wrote:
 I'm curious what the best idiomatic way of handling events is (e.g.
 receiving a series of messages and dispatching functions on the basis
 of the messages).  One could use the 'experimental' add-watch(er)
 functions.  But it might also be nice to do something stream-oriented,
 e.g. a doseq on a stream of events.  But the trouble is this dies as
 soon as the events stop arriving.  Can event seqs be 'kept alive'
 somehow (preferably without blocking)?
     This seems like a pretty basic capability, so I figured it was
 worth provoking discussion about.

 Nick.

 I think the typical way to handle this currently is by using a typical
 handler function that is called whenever an event is fired.  If the
 events will be long running then you can use agents or a thread pool
 (executor framework).  If you need to dispatch events to other
 handlers then use multi-methods.

 It seems that what you are really asking for though, is a way to treat
 a stream of events as a sequence.  This is what they recently
 introduced in .net land, with the RX framework:

 http://www.leading-edge-dev.de/?p=501

 Given that clojure has a nice library of sequence manipulation and
 predicate functions, I think doing something similar could be useful.
 I don't have a clear sense for how it would work though.  You could
 form a pipeline of sequence processing functions that get called
 whenever a new event is fired, maybe by using a promise that gets
 fulfilled when the event hits the pipeline?

 -Jeff

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Proposal: Extend behavior of hash-map

2009-11-17 Thread Kevin Downey
user= (import 'java.util.HashMap)
java.util.HashMap
user= (def m (doto (HashMap.) (.put 'a :a) (.put 'b :b)))
#'user/m
user= m
#HashMap {b=:b, a=:a}
user= (into {} m)
{b :b, a :a}
user= (class *1)
clojure.lang.PersistentArrayMap
user=


On Tue, Nov 17, 2009 at 1:56 PM, Richard Newman holyg...@gmail.com wrote:
 Sean,

 If the class implements Map, then it already behaves as an associative
 data structure in Clojure. E.g.,

 (map (fn [[k v]] (println v))
      (doto (java.util.HashMap.)
        (.put foo bar)
        (.put baz noo)))

 (get (doto (java.util.HashMap.)
        (.put foo bar)
        (.put baz noo)) foo)
 = bar

 That means you can write read-map as

 (defn read-map [m]
   (merge {} m))

 -R

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: String to Decimal Conversion

2009-11-22 Thread Kevin Downey
1.1 is not representable as an Integer(Java class, or primitive int)
and is not an integer (mathematical sense) so expecting to be
representable as one, is kind of... odd.

On Sun, Nov 22, 2009 at 4:14 PM, Don josereyno...@gmail.com wrote:
 I am having a problem converting a string to decimal.  I want to
 convert 1.0 to decimal 1.0.  I have tried the java.lang.Integer
 class

 use= (Integer/parseInt 1.1)
 java.lang.NumberFormatException: For input string:
 1.1 (NO_SOURCE_FILE:0)

 But it won't give.  It does however work when I run it with 1.

 Any suggestions would be greatly appreciated.  Thank you.

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: String to Decimal Conversion

2009-11-22 Thread Kevin Downey
user= (read-string 1.1)
1.1
user=


On Sun, Nov 22, 2009 at 4:48 PM, Don josereyno...@gmail.com wrote:
 Thanks a bunch Richard.

 On Nov 22, 4:47 pm, Richard Newman holyg...@gmail.com wrote:
  I am having a problem converting a string to decimal.  I want to
  convert 1.0 to decimal 1.0.

 For a double (not decimal):

         (Double/parseDouble 1.1)
         =
         1.1

 for a decimal:

         (BigDecimal. 1.1)
         1.1M

 Note that Clojure has reader support for BigDecimal (the M).

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Question about future

2009-11-25 Thread Kevin Downey
future also uses the same threadpool as agents, so once you call
future the threadpool spins up, and just sort of sits around for a
while before the jvm decides to exit, which is why the program would
sit around for 50 seconds

On Wed, Nov 25, 2009 at 10:30 AM, Hong Jiang h...@hjiang.net wrote:
 Thanks for your replies David and Sean. Yes, I made a mistake thinking
 that future takes a function and its arguments, so the function was
 never called in my program.

 On Nov 25, 8:21 am, David Brown cloj...@davidb.org wrote:
 On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote:
 Hi all,

 I'm new to Clojure and playing with small programs. Today I wrote a
 snippet to figure out how future works:

 (defn testf []
   (let [f (future #(do
                      (Thread/sleep 5000)
                      %)
                   5)
         g 7]
     (+ g @f)))

 You don't ever evaluate the function containing the sleep, you just
 create it, and then immediately return 5.

 Future contains an explicit do, so you can just do the steps in the
 future:

      [f (future
           (Thread/sleep 5000)
          5)
          ...

 Or, if you want to get the function call in, you'll need to call it:

      [f (future (#(do (Thread/sleep 5000) %) 5)) ...]

 David

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Updating Agent

2009-12-01 Thread Kevin Downey
uh, and you just want the agent to reference an empty vector?
(send a (comp second list) [])
(send a (constantly []))
(send a empty)
...

On Tue, Dec 1, 2009 at 2:37 PM, Don josereyno...@gmail.com wrote:
 I actually came up with this function that takes in an agent and
 proceeds to pop each item while agent still has items.
 It's rugged, so maybe someone else will have a better solution.


 (defn ca [c]
  (let [cnt (count @c)]
    (loop [i cnt]
      (if (not (= i 0))
        (do
          (send c pop)
          (await c)
          (recur (dec i)))



 On Dec 1, 2:27 pm, Don josereyno...@gmail.com wrote:
 I am having trouble resetting an agent.

 I created a vector agent as such:

 (def ce2 (agent []))

 I add to this vector by:

 (send ce2 conj 2)
 (await ce2)

 But I am having trouble thinking of a way to reset this agent.  I
 don't believe there is a reset function for agents.

 Thank You

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Second Lisp to Learn

2009-12-21 Thread Kevin Downey
instant second lisp: just write your own interpreter

On Sun, Dec 20, 2009 at 6:39 PM, Jonathan Smith
jonathansmith...@gmail.com wrote:
 Lisp Flavored Erlang is an extremely interesting lisp. in my opinion.

 You get Erlang, and you also get s-expressions and macros.

 Common Lisp and Scheme are the obvious choices, I suppose.

 Learning common lisp I would probably go towards clozure common lisp,
 or clisp.

 (SBCL is fine (great, even) on linux, but when i tried it last on
 windows, there were issues).

 For scheme, PLT scheme is awesome, but scheme really isn't my thing.

 On Dec 20, 3:31 pm, Sean Devlin francoisdev...@gmail.com wrote:
 Hi everyone,
 After hacking Clojure for a while, I've come to the conclusion that
 studying a second Lisp would help.  So, what do the people here
 think?  What is a good Lisp to study?  Are there particular dialects 
 distributions that are interesting? The things that are important to
 me are:

 A community at least 1/10th as awesome as this one.  Seriously.
 Libs in Lisp - I want to see if there are ideas worth stealing.
 Available documentation - I have to be able to read about it, and
 teach myself online.

 Thanks,
 Sean

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Proposal: clojure.io

2010-01-01 Thread Kevin Downey
I think something more abstract would be good. A function or macro
where you pass it an IO Spec and it takes care of all the class
stuff.

(io/read [:bytes :from SOMETHING :as p]
  (do-stuff-with-a-byte p))

(io/read [:lines :from SOMETHING :as p]
   (do-stuff-with-a-string p))

(io/read [:lines :from SOMETHING]) ;no :as binding or body, results
in a lazy-seq of lines

so you can specify the IO behavior you want, and let the
implementation map the spec to a class.

that being said, you would still want something like duckstreams for
interop, and possibly io/read and io/write would be implemented using
duckstreams. So I see no harm in pulling duckstreams in.

P.S. scopes are great for the lazy-seq case

On Fri, Jan 1, 2010 at 1:34 PM, Phil Hagelberg p...@hagelb.org wrote:
 Sean Devlin francoisdev...@gmail.com writes:

 1.  I'd recommend adding support for general unix file utilities.
 I've written some of them myself, and you can review/borrow/steal code
 from here:

 http://github.com/francoisdevlin/devlinsf-clojure-utils/blob/master/src/lib/sfd/file_utils.clj

 These are all one-line wrappers around Java methods. I know Rich has
 stated that the Clojure philosophy is to avoid such wrappers unless they
 provide significant additional value. Perhaps this will need to change
 as people start to write more cross-platform code, but I don't know if
 we're to that point yet.

 2.  duck-streams works very well for text, but not binary formats.  I
 know there was discussion about it here:

 http://groups.google.com/group/clojure/browse_thread/thread/416ca90d3ce2fa3/d64648f34e5c8668

 I believe it's the case that reader and writer don't work for binary
 formats, but copy should. Copying between two files or between a file
 and a byte array should work fine unless I'm missing something. This
 should be better-documented though.

 3.  There should be a brainstorming session to see what objects reader/
 writer will dispatch over, and the multimethods improved accordingly.
 This should probably happen anyway.

 It covers everything I can think of, but if you've got suggestions let's
 hear them.

 -Phil

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


gui repl

2010-01-03 Thread Kevin Downey
I have been playing with a gui repl for clojure: http://github.com/hiredman/Repl
instructions are light, but you can check it out, and use lien to jar
it up, it is gen-class'ed (but does not require AOt'ing) and has a
-main function so you can run it from an uberjar.

http://www.thelastcitadel.com/images/Screenshot-Repl.png is a
screenshot of me playing with incater

the repl is built around swing and jcomponents, so it is possible to
display a button in the repl and attach an action listener to it and
do neat stuff.

I have a sort little video clip of fooling around with the repl
http://www.thelastcitadel.com/lab/repl.m4v
(http://www.thelastcitadel.com/lab/repl.ogv same video)

Anyhoo, it seems like there is an interest in this sort of thing so I
wanted to make this available

-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: gui repl

2010-01-04 Thread Kevin Downey
ah, well, the differences are:

a. this repl is written in Clojure

b. this repl can print arbitrary jcomponents, not just text. for
example in the screenshot a ChartPanel from JFreeChart is rendered in
the repl

On Sun, Jan 3, 2010 at 11:42 PM, Albert Cardona sapri...@gmail.com wrote:
 I built a Swing REPL for clojure some time ago, it's part of Fiji.
 Launch from Plugins - Scripting - Clojure Interpreter menu command.

 http://pacific.mpi-cbg.de

 Code here:

 http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/Clojure/Clojure_Interpreter.java;hb=HEAD

 Albert
 --
 Albert Cardona
 http://albert.rierol.net

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure unicode on Windows

2010-01-13 Thread Kevin Downey
java uses local settings, on windows the default encoding is some
godawful thing (same on Mac, still godawful, but different) set
file.encoding to pick something sane

On Wed, Jan 13, 2010 at 1:52 PM, Lukas Lehner lehner.lu...@gmail.com wrote:
 Hi all

 The clojure unicode reading, evaluating and printing was discussed  already
 with various results. Let me add one more, and kindly ask for advice if
 anyone has.

 OS: Windows 7
 clojure 1.1
 C:\java -version
 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
 java version 1.6.0_17
 Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
 Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

 chcp: 437

 java clojure.main
 user= éáú
 java.lang.Exception: Unable to resolve symbol: ��� in this context
 (NO_SOURCE_FILE:0)

 You see the problem.

 chcp: 65001

 java clojure.main
 user= éáú


 C:\

  In this case REPL is killed without any message


 File unicode-test.clj in unicode:
 (println (seq (.split őúáé öüü? sdf \\W+)))

 c:\java clojure.main unicode-test.clj
 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
 Exception in thread main java.lang.Exception: Unable to resolve symbol: 
 in this context (unicode-test.clj:0)0)

 rest of the error at http://clojure.pastebin.com/m2235d7fb


 OS: FreeBSD 7.2
 clojure 1.1
 java -version
 java version 1.6.0_07
 Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
 Diablo Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

 locale
 LANG=en_US.UTF-8
 LC_CTYPE=en_US.UTF-8
 LC_COLLATE=en_US.UTF-8
 LC_TIME=en_US.UTF-8
 LC_NUMERIC=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8
 LC_MESSAGES=en_US.UTF-8
 LC_ALL=en_US.UTF-8

 java clojure.main
 user= éőó
 java.lang.Exception: Unable to resolve symbol: ó�éőó in this context
 (NO_SOURCE_FILE:0)
 user= éőó
 éőó
 user= (println éőó)
 éőó
 nil
 user= (def éőó 0)
 java.lang.Exception: Unable to resolve symbol: �0 in this context
 (NO_SOURCE_FILE:6)
 user=

 better but still not bulletproof

 testing also the same script like on windows
 java clojure.main unicode-test.clj
 ( sfd)

 No errors :) but of course it did not split the way I wanted...


 Anyone having better results with unicode and encoding? Preferably on
 windows.


 Thank you in advance
 Lukas





 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: clojure unicode on Windows

2010-01-15 Thread Kevin Downey
are you using the repl directly? or wrapped in jline or rlwrap?

On Wed, Jan 13, 2010 at 3:02 PM, Lukas Lehner lehner.lu...@gmail.com wrote:
 Ok, tried to put this at the top of the file, but same bad result on Win
 (System/setProperty file.encoding  UTF8)

 and actually here
 http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding
 it looks like JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 has the same effect,
 and should be used (and I am using it)

 Is everybody here running macs and linuxes? :(

 And, more important now is actually REPL
 user= (System/setProperty file.encoding  UTF8)
 UTF8
 user= éőó
 �o�
 user=

 L

 On 1/13/2010 11:34 PM, Kevin Downey wrote:

 java uses local settings, on windows the default encoding is some
 godawful thing (same on Mac, still godawful, but different) set
 file.encoding to pick something sane

 On Wed, Jan 13, 2010 at 1:52 PM, Lukas Lehnerlehner.lu...@gmail.com
  wrote:


 Hi all

 The clojure unicode reading, evaluating and printing was discussed
  already
 with various results. Let me add one more, and kindly ask for advice if
 anyone has.

 OS: Windows 7
 clojure 1.1
 C:\java -version
 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
 java version 1.6.0_17
 Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
 Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

 chcp: 437

 java clojure.main
 user=  éáú
 java.lang.Exception: Unable to resolve symbol: ��� in this context
 (NO_SOURCE_FILE:0)

 You see the problem.

 chcp: 65001

 java clojure.main
 user=  éáú


 C:\

  In this case REPL is killed without any message


 File unicode-test.clj in unicode:
 (println (seq (.split őúáé öüü? sdf \\W+)))

 c:\java clojure.main unicode-test.clj
 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
 Exception in thread main java.lang.Exception: Unable to resolve symbol:
 
 in this context (unicode-test.clj:0)0)

 rest of the error at http://clojure.pastebin.com/m2235d7fb


 OS: FreeBSD 7.2
 clojure 1.1
 java -version
 java version 1.6.0_07
 Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
 Diablo Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

 locale
 LANG=en_US.UTF-8
 LC_CTYPE=en_US.UTF-8
 LC_COLLATE=en_US.UTF-8
 LC_TIME=en_US.UTF-8
 LC_NUMERIC=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8
 LC_MESSAGES=en_US.UTF-8
 LC_ALL=en_US.UTF-8

 java clojure.main
 user=  éőó
 java.lang.Exception: Unable to resolve symbol: ó�éőó in this context
 (NO_SOURCE_FILE:0)
 user=  éőó
 éőó
 user=  (println éőó)
 éőó
 nil
 user=  (def éőó 0)
 java.lang.Exception: Unable to resolve symbol: �0 in this context
 (NO_SOURCE_FILE:6)
 user=

 better but still not bulletproof

 testing also the same script like on windows
 java clojure.main unicode-test.clj
 ( sfd)

 No errors :) but of course it did not split the way I wanted...


 Anyone having better results with unicode and encoding? Preferably on
 windows.


 Thank you in advance
 Lukas





 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en






 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: hash literal oddity?

2010-01-18 Thread Kevin Downey
what you are seeing is the transition from arraymap to hashmap

On Mon, Jan 18, 2010 at 6:46 PM, Stuart Halloway
stuart.hallo...@gmail.com wrote:
 Is this expected behavior?

 {1 this 1 is 1 strange}
 = {1 this, 1 is, 1 strange}

 (into {} {1 this 1 is 1 strange})
 = {1 strange}

 {1 this 1 is 1 strange 1 but 1 if 1 I 1 try 1 hard 1
 enough}
 = {1 enough}

 Stu






 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
clojure structs are an optimized version of maps for a set of shared
keys. if you don't have a defined set of shared keys you just have a
map. so by all means, use a map

On Tue, Jan 19, 2010 at 3:52 PM, Andreas Wenger
andi.xeno...@googlemail.com wrote:
 Hi,

 I would like to know why defstruct without providing any keys (like
 (defstruct s)) is not allowed (exception: Must supply keys).

 Let me shortly describe why I think that this would be useful: Imagine
 you have a defstruct like in Rich's Ants demo:

 (defstruct cell :food :pher) ;may also have :ant and :home

 :ant and :home are optional, since they are not often used (Rich
 actually states in his talk, that this is an advantage compared to
 Java where we would always have to store null for each of the
 optional class members). Image, you use (struct-map cell ...) very
 often in your program. Now, you notice that :food and :pher are also
 not used very often, and that most times only one or two of the four
 possible keys are actually used. So you make them all optional:

 (defstruct cell) ;may have :food, :pher, :ant and :home

 This is not allowed. You have to remove the whole defstruct, which
 makes all your (struct-map cell ...) calls useless. This is bad,
 because you have to replace it everywhere and struct-map has a very
 nice documentary style you want to use anyway. (Later, when we notice
 that at least one key is obligatory, we again have to find these
 places and convert them back to struct-map...)

 In practice, I had this problem with a struct containing 10 possible
 keys, where mostly only 1-2 are used in practice. Now I have to remove
 the whole defstruct... or let at least one arbitrary key be non-
 optional, which is more a hack than a nice solution.

 Looking in the PersistentStructMap.java, I found out that allowing
 structs with no obligatory key would be no problem at all (change 2
 lines?). I don't know why it was written that way, but I think here
 Clojure puts a spoke in me wheel where it just not needed.

 Any comments? Thanks!


 Andi

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
I fail to see how it requires changing a lot of code. it just means
you need to change the place where you create your maps. which if you
are also type tagging them is a lot of repetitive code, so it should
already be factored out into a function, so then you just switch out
one function.

On Tue, Jan 19, 2010 at 3:59 PM, Andreas Wenger
andi.xeno...@googlemail.com wrote:
 On 20 Jan., 00:56, Kevin Downey redc...@gmail.com wrote:
 clojure structs are an optimized version of maps for a set of shared
 keys. if you don't have a defined set of shared keys you just have a
 map. so by all means, use a map

 You're talking about the implementation in the background, but I am
 talking about nice code.
 I'm aware that defstruct with optional keys introduce a slight
 overhead compared to normal hashmaps, but that is minimal and
 defstruct/struct-map is much cleaner and more documentary that a pure
 hashmap.
 I can not find a reason why Clojure forbids to make use of this nice
 feature.

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
how is that not an argument? I'm pretty sure I just used it as one.

keep in mind defstruct is largely to be superseded by deftype.

http://clojure.org/contributing

On Tue, Jan 19, 2010 at 4:10 PM, Andreas Wenger
andi.xeno...@googlemail.com wrote:
 I fail to see how it requires changing a lot of code. it just means
 you need to change the place where you create your maps. which if you
 are also type tagging them is a lot of repetitive code, so it should
 already be factored out into a function, so then you just switch out
 one function.

 That's probably true, but you just argue why this inconsistency in
 Java is
 not overly severe. But this is no argument for not fixing this
 inconsistency.

 Remember, it would only need to change 2 or 3 lines in
 PersistentStructMap,
 which is less than the lines I have to fix in my clojure code for only
 one
 single instance of this problem.

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
I think your use of workaround is pejorative. And can it even be
called a work around if it is a best practice even when there is
nothing to work around?

On Tue, Jan 19, 2010 at 4:28 PM, Andreas Wenger
andi.xeno...@googlemail.com wrote:
 how is that not an argument? I'm pretty sure I just used it as one.

 What I wanted to say is that you are completely right, if you say that
 it is easy to create a workaround.
 But although doing this is easy, this does not mean that we should not
 fix this inconsistency (or do you see none?) anyway.

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Empty defstruct

2010-01-20 Thread Kevin Downey
empty classes in Java what does that mean?

as I said, structs are an optimization on maps, that optimization
doesn't work for empty structs, so empty structs of course don't
make sense

On Wed, Jan 20, 2010 at 12:39 AM, Andreas Wenger
andi.xeno...@googlemail.com wrote:
 I think your use of workaround is pejorative. And can it even be
 called a work around if it is a best practice even when there is
 nothing to work around?

 I just can't understand why throwing an exception should be more
 useful than returning some object you can actually work with.
 I wouldn't throw an exception for empty vectors or list either. Why
 artificially introducing this constraint where it is not necessary at
 all?

 Please help me to understand why I am wrong. Why are empty structs in
 C, empty classes in Java, empty hashmaps in Clojure, why are all of
 these objects allowed (of course, because it makes sense), but empty
 defstructs are forbidden by a if-empty-then-exception where it is not
 necessary or helpful at all?

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: REPL vs Script + Regex Problem!

2010-02-02 Thread Kevin Downey
for is lazy, and your code formatting is horrible.

On Tue, Feb 2, 2010 at 2:48 PM, Wardrop t...@tomwardrop.com wrote:
 I've noticed that the output of a script, is often different to the
 output of the same commands if run on the REPL. This makes sense, but
 here's a situation which has got me a little confused. I'm trying to
 run this code as a script...

 (use '[clojure.contrib.duck-streams])

 (for [line (line-seq (reader C:\\filedupes.txt))]
  (cond
    ((complement nil?) (re-matches #([0-9]+) byte\(null\)each:
 line))
      (println Byte pattern!)
    ((complement nil?) (re-matches #.*(\.[0-9a-zA-Z]+) line))
      (println File pattern!)
  )
 )

 (println Finished!)

 The problem is, the only output I get is Finished!. If however, I
 run this on the command line, I get a long list of nil's in amongst
 the strings Byte pattern! and File pattern!. I expect the nil's
 not to show when this is run as a script, but why are the
 aforementioned strings not being output?

 While you're at it, you may be able to help me with an additional
 problem I'm trying to tackle. As you can see if the above code, I'm
 trying to match on certain lines of a text file. I'm using cond to
 do this with as a switch statement is the only way I know how to
 achieve what I'm after. Anyway, I not only want the regex to be used
 in the condition expression, but also want to capture the first sub-
 match (i.e. what's in the parenthesis inside the regex). What's the
 best way I can do this, without having to re-run the regex twice.

 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Seattle Clojure meeting

2010-02-03 Thread Kevin Downey
the 11th at Zokas is good for me

On Wed, Feb 3, 2010 at 10:07 PM, ajay gopalakrishnan ajgop...@gmail.com wrote:
 I'm in!
 But on 11th. I cannot make it on 15th


 On Wed, Feb 3, 2010 at 7:01 PM, Phil Hagelberg p...@hagelb.org wrote:

 Hello, clojurists of Seattle.

 Let's meet! I'm thinking of getting folks together from 7pm to 9pm at Zoka
 in the University District: http://bit.ly/c9jinW Topics may include
 Leiningen, deftype/protocols, getting set up with Emacs, or even getting
 another pair of eyes on that pet project that you've been playing around
 with recently. I suspect it'll be mostly talking and getting to know people,
 but bring laptops.

 I'm thinking of either the 11th or the 15th, depending on what works best
 for the most people. Let me know if you think you can make it to one or both
 of these times.

 -Phil

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Implicit style streams in Clojure

2010-02-08 Thread Kevin Downey
don't use def inside functions, ever. in scheme define is lexically scoped,
so you do that sort of thing. clojure is not scheme. if you want a lexically
scoped function use a lexical scoping construct like let or letfn.

On Mon, Feb 8, 2010 at 12:12 PM, Brenton bashw...@gmail.com wrote:

 What is the Clojure best practice, if there is one, for writing a
 function like this:

 pre
 (defn integral [integrand initial-value dt]
  (def --integral (cons initial-value
  (lazy-seq (add-streams (scale-
 streams integrand dt)

 --integral
  --integral)
 /pre

 integrand is a stream of values.

 I don't like the fact that --integral is visible outside of the
 integral function but I don't know how else to implement this
 efficiently. I am using -- here as a naming convention to identify
 vars that are defined within other functions.

 Also, what is general feeling about defs inside of functions?

 Brenton

 --
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: defn within defn

2010-02-10 Thread Kevin Downey
scheme's define is scoped inside a function. clojure is not scheme.
clojure's def (which defn uses) is not lexical or scoped in anyway, it
always operates on global names. if you want lexical scope please use
one of clojure's lexical scoping constructs, let or letfn.

On Wed, Feb 10, 2010 at 1:28 PM, Hozumi fat...@googlemail.com wrote:
 Hi all.
 Is it not recommended to use defn within defn?

 Normal function is faster than the function which has inner function
 which actually doesn't run.
 --
 (defn aaa1 []
  (defn bbb [] 1)
  1)

 (defn aaa2 [] 1)

 user (time (dotimes [_ 1000] (aaa1)))
 Elapsed time: 4083.291 msecs
 nil
 user (time (dotimes [_ 1000] (aaa2)))
 Elapsed time: 58.34 msecs
 nil
 --
 In scheme's case both code have been excuted in the same time.

 None of clojure code I have seen have inner function.
 I like inner function because it doesn't consume a name from namespace
 and make it clear that inner function is only used by outer function.
 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 post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


  1   2   3   >