Re: ANN: clj-dropbox, Dropbox client library in Clojure

2010-07-25 Thread aria42
How are you accessing the authorization url? If by hand you mean you
manually go to the url, this is what you're supposed to do. I don't
think
you can visit the authorization url via a browser agent unless the
agent is logged in to dropbox antecedently and you change the browser
agent
so it looks like a normal browser.

On Jul 24, 3:20 pm, Mikael Sundberg 
wrote:
> Looks realy nice
> i Tried it, and i cant get the example oath dance to work. i get:
> Bad Response: 403
> {"error": "Token is not an authorized request token."}
>   [Thrown class java.lang.RuntimeException]
>
> i used "" or nil as a callback-url. i assume thats where the problem is.
>
> if i do the dance by hand and copy the result the client works great!
>
> /Micke
>
> 2010/7/23 Marc Spitzer :
>
>
>
> > I need to look at this.  Thanks for the toy.
>
> > marc
>
> > On Thu, Jul 22, 2010 at 8:23 PM, aria42  wrote:
> >> Hi all,
>
> >> I've released my clojure library for accessing the Dropbox API. Its
> >> called clj-dropbox and it can be found at:
>
> >>http://github.com/aria42/clj-dropbox
>
> >> Hope some people get use out of it. Feel free to email or leave
> >> comments and/or suggestions
>
> >> Best,
> >> Aria
>
> >> --
> >> 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
>
> > --
> > Freedom is nothing but a chance to be better.
> > --Albert Camus
>
> >  The problem with socialism is that eventually you run out
> > of other people's money.
> > --Margaret Thatcher
>
> > --
> > 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


Re: ANN: clj-dropbox, Dropbox client library in Clojure

2010-07-25 Thread aria42
Hmmm, can you privately send me some more details about what you did?
Did you go to the authorization
site and get an "ok" from dropbox before calling the request-callback;
that error typically means the user didn't
authorize your app? I know its a straightforward
question, but just checking. Dropbox knows the oauth dance is a little
brittle and they have a bypass
I'll include in the next update where you ship off user email and
password and they return the user token. It
completely defeats the point of OAuth, but they know the process is
buggy enough to include.

Thanks, Aria

On Jul 24, 3:20 pm, Mikael Sundberg 
wrote:
> Looks realy nice
> i Tried it, and i cant get the example oath dance to work. i get:
> Bad Response: 403
> {"error": "Token is not an authorized request token."}
>   [Thrown class java.lang.RuntimeException]
>
> i used "" or nil as a callback-url. i assume thats where the problem is.
>
> if i do the dance by hand and copy the result the client works great!
>
> /Micke
>
> 2010/7/23 Marc Spitzer :
>
>
>
> > I need to look at this.  Thanks for the toy.
>
> > marc
>
> > On Thu, Jul 22, 2010 at 8:23 PM, aria42  wrote:
> >> Hi all,
>
> >> I've released my clojure library for accessing the Dropbox API. Its
> >> called clj-dropbox and it can be found at:
>
> >>http://github.com/aria42/clj-dropbox
>
> >> Hope some people get use out of it. Feel free to email or leave
> >> comments and/or suggestions
>
> >> Best,
> >> Aria
>
> >> --
> >> 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
>
> > --
> > Freedom is nothing but a chance to be better.
> > --Albert Camus
>
> >  The problem with socialism is that eventually you run out
> > of other people's money.
> > --Margaret Thatcher
>
> > --
> > 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


ANN: clj-dropbox, Dropbox client library in Clojure

2010-07-22 Thread aria42
Hi all,

I've released my clojure library for accessing the Dropbox API. Its
called clj-dropbox and it can be found at:

http://github.com/aria42/clj-dropbox

Hope some people get use out of it. Feel free to email or leave
comments and/or suggestions

Best,
Aria

-- 
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


Maps with functions for default values

2010-07-12 Thread aria42
Is there a way to set up a map so that there is a default function
which depending on the key returns a value if one is not present in
the map. I can obviously write this with a deftype and have it
implement Associative, Seqable, etc. so it behaves like a built-in
map, but just wondering if there was a way to get this out-of-the-box.

Thanks, Aria

-- 
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: --> macro proposal

2010-07-07 Thread aria42
I've needed --> a few times in my code. I don't think I need it as
much as just -> or ->>. Most of the time I've needed it is because I
or someone else essentially had parameters
in the wrong order. Maybe it belongs in contrib along with -?> which
I've needed sparingly as well, but have found useful and would've been
non-trivial to have conjured.

On Jul 6, 5:22 pm, David Nolen  wrote:
> On Tue, Jul 6, 2010 at 5:02 PM, Greg  wrote:
>
> > I'll make a list here of the reasons given for Yay/Nay so far:
>
> > Nay:
>
> > 1) "I haven't had a need for a general threading macro."
> > 2) The response so far is negative (and consists of repeating point #1
> > above).
>
> 3) It would encourage people to not follow Clojure's conventions around
> argument positions for fns that deal with sequences/collections.
>
> That is a pretty important Nay and illustrates that --> decreases
> readability for people that have spent time with Clojure.
>
> It also points out why -> and ->> are not really about position anyway, it's
> about threading an expression. -> is to make Clojure read left-right instead
> of inside-out. ->> is to make Clojure read left-right when operating on
> sequences/collections.
>
> Both are far, far more common and useful then being able to fill arguments
> anywhere.
>
> 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


Remapping Class Imports

2010-03-30 Thread aria42
Hi,
  Is it possible to remap the name of a class or package import?
Ideally
I'd like to say something like (import [[java.util :as ju] ArrayList
List]) and then use (ju.ArrayList.) to refer to the class. I recall
reading Rich doesn't like auto-imports of all classes in a package or
of renaming class. But what about this? I don't like the choice
between importing a class and using its unqualified name or having to
use a fully qualified name. Its also problematic when you work with
libraries where two classes have the same name (e.g Parser).  Does
anyone have macros to handle this?

Thanks, Aria

-- 
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Accidentally Retaining Head?

2010-03-23 Thread aria42
Whoops duh. That was silly, far to early on the west coast.

On Mar 23, 7:46 am, Per Vognsen  wrote:
> It doesn't seem very accidental: the namespace binding for 'trees' is
> retaining the head. You probably want to wrap it in a function:
>
> (defn trees []
>   ...)
>
> -Per
>
> On Tue, Mar 23, 2010 at 9:40 PM, aria42  wrote:
> > Hi,
> >  I was experimenting with some code and I had an largish sequence I
> > did  a doseq over. The memory hit the ceiling, which you expect since
> > even though the head isn't retained GC doesn't happen until you hit
> > your memory limit (is there a way to change that). Once it hit the
> > memory limit, 1.2 gigs in this case,   the doseq slows to a halt.
>
> >  On the other hand if rather than make a long lazy seq, I do it
> > implicitly in the doseq itself  (see FAST snippet below), the
> > performance is great. Is there anyway to get good performance using a
> > single lazy seq?  Relevant snippets below.
>
> > Thanks, Aria
>
> > (defn lines
> >  "get lines from gz file"
> >  [#^String path]
> >  (-> path
> >      java.io.FileInputStream.
> >      java.util.zip.GZIPInputStream.
> >      java.io.InputStreamReader.
> >      java.io.BufferedReader.
> >      line-seq))
>
> > ; the tree-from-str does some processing, but doesn't have state
> > (def trees (for [l (lines "/usr/local/corpora//NANC/003.gz")
> >                 :when (not (empty? l))
> >                 :let [[t _] (tree/tree-from-str l)]]
> >             t))
>
> > ; SLOW: hits memory limit and becomes slow b/c of constant
> > ; GC hits
> > (doseq [t trees]
> >  (println (str t)))
>
> > ; FAST: low memory
> > (doseq [l (lines "/usr/local/corpora//NANC/003.gz")
> >                 :when (not (empty? l))
> >                 :let [[t _] (tree/tree-from-str l)]]
> >             (println (str t)))
>
> > --
> > 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
>
> > To unsubscribe from this group, send email to 
> > clojure+unsubscribegooglegroups.com or reply to this email with the words 
> > "REMOVE ME" as the subject.
>
>

-- 
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Accidentally Retaining Head?

2010-03-23 Thread aria42
Hi,
  I was experimenting with some code and I had an largish sequence I
did  a doseq over. The memory hit the ceiling, which you expect since
even though the head isn't retained GC doesn't happen until you hit
your memory limit (is there a way to change that). Once it hit the
memory limit, 1.2 gigs in this case,   the doseq slows to a halt.

 On the other hand if rather than make a long lazy seq, I do it
implicitly in the doseq itself  (see FAST snippet below), the
performance is great. Is there anyway to get good performance using a
single lazy seq?  Relevant snippets below.

Thanks, Aria

(defn lines
  "get lines from gz file"
  [#^String path]
  (-> path
  java.io.FileInputStream.
  java.util.zip.GZIPInputStream.
  java.io.InputStreamReader.
  java.io.BufferedReader.
  line-seq))

; the tree-from-str does some processing, but doesn't have state
(def trees (for [l (lines "/usr/local/corpora//NANC/003.gz")
 :when (not (empty? l))
 :let [[t _] (tree/tree-from-str l)]]
 t))

; SLOW: hits memory limit and becomes slow b/c of constant
; GC hits
(doseq [t trees]
  (println (str t)))

; FAST: low memory
(doseq [l (lines "/usr/local/corpora//NANC/003.gz")
 :when (not (empty? l))
 :let [[t _] (tree/tree-from-str l)]]
 (println (str t)))

-- 
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


extending protocol

2010-03-13 Thread aria42
Is there a way to say that a protocol extends another protocol or
interface? I.e. can i specify that a given protocol must also support
the "seq" method from  clojure.lang.Seqable?

-- 
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


Can I make this faster?

2010-02-17 Thread aria42
Hi all, I was playing with the defprotocol/deftype/reify stuff in 1.2,
and I wanted to test how a common abstraction I use would look if I
did with java data structures vs. clojure ones. I've pasted the code
below. I'll wait for you to take a lookSo on my test, I have the
Clojure version about 5x slower than the Java one only one cpu. Now I
know that JavaMapCounter isn't thread safe, while ClojureCounter is,
and that if I had sufficiently many cpus, the clojure version would be
faster. But is there a better way to do what I'm doing with clojure to
get the performance a bit more up to par with javas?

Thanks, Aria

(defprotocol Counter
  (getCount [_ k])
  (incCount! [_ k v])
  (totalCount [_]))

(defn JavaMapCounter []
  (let [counts (java.util.HashMap.)
total (org.apache.commons.lang.mutable.MutableDouble.)]
(reify :as self
 Counter
 (getCount [k] (.get counts k))
 (incCount! [k v]
   (let [cur-v (if-let [x (getCount self k)] x 0.0)]
(.put counts k (+ v cur-v)))
   (.setValue total (+ (.doubleValue total) v)))
 (totalCount [] (.doubleValue total)

(defn ClojureCounter []
  (let [state (atom {:counts (hash-map) :total 0.0})]
(reify :as self
 Counter
 (getCount [k] (if-let [x (get-in @state [:counts,k])] x 0.0))
 (incCount! [k v]
   (swap! state
 (fn [data]
   (let [add-v (fn [x] (if x (+ x v) v))]
  (-> data (update-in  [:counts,k] add-v)
   (update-in [:total] add-v))
 (totalCount [] (:total @state)

(defn testCounter [counter]
  (let [r (java.util.Random. 0)]
(dotimes  [_ 100]
  (incCount! counter (.nextInt r 10) (.nextDouble r)

(time (testCounter (JavaMapCounter)))
(time (testCounter (ClojureCounter)))

-- 
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: Trait-like behavior with Protocols

2010-02-09 Thread aria42
If this situation is common enough, shouldn't defprotocol support
optional implementations which are implicitly merged?

On Feb 9, 6:01 am, Konrad Hinsen  wrote:
> On 09.02.2010, at 02:14, Stuart Sierra wrote:
>
> > On Feb 8, 6:13 pm, aria42  wrote:
> >> (defprotocol Span
> >>   (start [self])
> >>   (stop [self])
> >>   (span-length [self]))
>
> >> Now I know I can just make span-length a function on Span as opposed
> >> to part of the protocol. Is that what one should do?
>
> > Yes.
>
> I would say "it depends".
>
> I have a similar situation in my multiarray package 
> (http://code.google.com/p/clj-multiarray/). In the multiarray protocol, I 
> have two functions, "shape" and "rank", with the latter being by definition 
> the same as (comp count shape). However, I still have "rank" in the protocol, 
> because for some implementations it is more efficient to compute the rank 
> directly, rather than construct a shape vector just for computing its length 
> afterwards.
>
> In such situations it is useful to provide a default implementation and leave 
> it up to each type to implement a more efficient alternative or not. With 
> extend and the maps that go with it, this is easy to achieve: make a map with 
> the default implementations, and merge this with the type-specific 
> implementations fed to extend.
>
> Konrad.

-- 
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


Trait-like behavior with Protocols

2010-02-08 Thread aria42
Is it possible to have default implementations associated with
functions in a protocol? This is most useful when some protocol
functions are defined in terms of other. For instance,

(defprotocol Span
  (start [self])
  (stop [self])
  (span-length [self]))

Now I know I can just make span-length a function on Span as opposed
to part of the protocol. Is that what one should do?

-- 
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: Bug with Clojure 1.2 REPL (aka master branch) ?

2010-01-12 Thread aria42
I was seeing this error too and I reckoned it was because my
clojure.contrib was not compatible with clojure core. I think if
you're using
1.2 master of clojure you need 1.1 master of contrib. Is that right?

On Jan 12, 6:41 pm, David Nolen  wrote:
> Hullo,
>
> I'm trying to run the REPL from the command line. I note that when I include
> jars in the classpath, including clojure libraries works fine (via use for
> example). However when adding libraries of Clojure source directories to the
> classpath I get a very strange error:
>
> user=> (use 'lancet)
> java.lang.NoSuchMethodError: clojure.lang.RestFn.(I)V
> (NO_SOURCE_FILE:0)
>
> I'm pretty sure my class path is OK.
>
> java -cp
> ~/clojure/clojure/clojure.jar:~/clojure/clojure-contrib/clojure-contrib.jar:src:~/development/clojure/libs/lancet/lib/*:~/development/clojure/libs/lancet
> clojure.main
>
> Thanks,
> 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

Re: Inheritance & multiple inheritance using structs

2009-01-22 Thread aria42

[sorry for duplicating content from the email i sent you David]

Would anyone be interested in simplifying some of the boilerplate for
defining methods in clojs? Currently you have to do this,

(defclass circle [shape]
  (:radius 10))
(defmulti area :tag)
(defmethod area ::circle [this] (* (:radius this) (:radius this) (Math/
PI)))

But it seems like 99% of the time this is boilerplate b/c you want
multi-methods to dispatch on :tag, so we should maybe have a shortcut
to let us do this...

(defclass circle [shape]
  (:radius 10)
  (defmethod area [] (* :radius :radius Math/PI)))

I'm not a macro-wiz but it must be possible to alter that defmethod to
check if it's defined and to wrap the symbol refrences with (:symbol
this) and cons this to the argument list.

Just a thought, Aria

On Jan 22, 7:55 pm, "evins.mi...@gmail.com" 
wrote:
> On Jan 19, 12:38 am, David Nolen  wrote:
>
> > Of course it might be the case that not many people are interested in the
> > implementing ideas from CLOS for Clojure
>
> It's definitely interesting. I'd like to have eql specializers and the
> ability to build hierarchies of arbitrary types (e.g. a hierarchy of
> strings for one particular application I'm working on), so any hacking
> around with CLOS-like dispatching and specializers is interesting to
> me.
--~--~-~--~~~---~--~~
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: IntelliJ Plugin

2009-01-13 Thread aria42

Did you ever get around to posting the notes on getting the IntelliJ
plugin to work? I sorely would love IDE support for Clojure in either
Eclipse or IntelliJ. Is the IntelliJ one in a usable state, or is it
not ready for some alpha-level testers?

  Cheers, Aria

On Dec 29 2008, 10:36 am, "Justin Johnson" 
wrote:
> On Sat, Dec 27, 2008 at 8:55 AM, Peter Wolf  wrote:
> > Hi Justin,
> > This is the right place.  Thanks for trying the plugin.
>
> > It would absolutely be helpful to document use of the plugin.  However, I
> > am sure you can tell that it is nowhere near ready.
>
> Yes, I noticed there wasn't much there yet.  I still think it would be great
> if you documented how you build and test.  In particular I found it to be a
> pain to setup my own update site and updatePlugins.xml file just to install
> my own plugin.  It wasn't difficult, but certainly not efficient.  My hope
> was that sharing setup info like this would help me discover more efficient
> ways of working.
>
>
>
> > I would like to get a basic set of features going and then recruit you and
> > Randall to test and document it.  Once it is banged on, we can post the
> > plugin to IntelliJ so it can be installed with a mouse click.
>
> > I am currently working on the Parser, which will give us parens matching
> > and folding, and Compile/Run/Debug/Profile.
>
> > The one big piece I am missing is the REPL.  Any help would be appreciated.
>
> > Peter
>
> > On Wed, Dec 24, 2008 at 4:25 PM, Justin Johnson 
> > wrote:
>
> >> Hi,
>
> >> Is this the appropriate mailing list to talk about the Clojure IntelliJ
> >> plugin?  The Google Code site didn't list any other mailing list.
>
> >>http://code.google.com/p/clojure-intellij-plugin/
>
> >> I went through the process of building and installing the plugin on
> >> Windows XP with IntelliJ IDEA 8.0.1 and thought it might be helpful if I
> >> document what I did on the wiki.  I also have a small suggestion that the
> >> build.xml file use environment variables instead of hard coded paths to
> >> java.home and idea.home.
>
> >> Thanks,
> >> Justin
--~--~-~--~~~---~--~~
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: How much Clojure source code is complicated?

2009-01-13 Thread aria42

For what's it worth, I think the "Programming Clojure" book is
excellent (Okay Stuart, make the check payable to ). My only
complaint is that the I wish there were another largish example
besides the two in there (mc simulation and the lancelet thing).

Cheers, Aria

On Jan 13, 12:58 am, bOR_  wrote:
> Thanks for the answer. I think you'll need a reply from Chouser or
> Rich (or someone alike) when they wake up. The best I can give you is
> this part of the source, where (I think) it is defined how clojure is
> build upon java.
>
> http://code.google.com/p/clojure/source/browse/trunk/src/?r=1205#src/...
>
> On Jan 13, 9:41 am, HB  wrote:
>
> > >Not sure what you want to achieve by studying the source code. I think
> > >the answer that I can give to what works best for you will depend on
> > >what you want to study the source code for.
>
> > I want to be familiar with a language design in general and how it
> > integrates with Java Platform.
>
> > >I'm also not sure what you mean by 'what is the best place to start 
> > >reading.
>
> > What I mean is which file in the source code I have to read in order
> > to start mining.
> > This depends on why I'm reading the source code, right?
>
> > On Jan 13, 10:19 am, bOR_  wrote:
>
> > > Not sure what you want to achieve by studying the source code. I think
> > > the answer that I can give to what works best for you will depend on
> > > what you want to study the source code for.
>
> > > I'm also not sure what you mean by 'what is the best place to start
> > > reading..' The link that I gave before is a direct link to the source
> > > code of clojure. That is the source.
>
> > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/...
>
> > > On Jan 13, 9:04 am, HB  wrote:
>
> > > > Do you suggest that I read "Programming Clojure" first and then trying
> > > > to study the source code?
> > > > What is the best place (file, package or what ever) to start reading
> > > > the source code?
>
> > > > On Jan 13, 10:01 am, bOR_  wrote:
>
> > > > > Here you can peek at the source code of clojure.
>
> > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/...
>
> > > > > It is about 3700 lines, and although you have to get used to a few new
> > > > > functions and names that are normally not exposed when you use
> > > > > clojure, it looks fairly simple.
>
> > > > > Here is the function that defines defn itself. Most functions in the
> > > > > source are a magnitude easier than this one for us newbies =).
>
> > > > > (def
>
> > > > >  #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
> > > > >     name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
> > > > >     to the var metadata"
> > > > >     :arglists '([name doc-string? attr-map? [params*] body]
> > > > >                 [name doc-string? attr-map? ([params*] body)+ attr-
> > > > > map?])}
> > > > >  defn (fn defn [name & fdecl]
> > > > >         (let [m (if (string? (first fdecl))
> > > > >                   {:doc (first fdecl)}
> > > > >                   {})
> > > > >               fdecl (if (string? (first fdecl))
> > > > >                       (rest fdecl)
> > > > >                       fdecl)
> > > > >               m (if (map? (first fdecl))
> > > > >                   (conj m (first fdecl))
> > > > >                   m)
> > > > >               fdecl (if (map? (first fdecl))
> > > > >                       (rest fdecl)
> > > > >                       fdecl)
> > > > >               fdecl (if (vector? (first fdecl))
> > > > >                       (list fdecl)
> > > > >                       fdecl)
> > > > >               m (if (map? (last fdecl))
> > > > >                   (conj m (last fdecl))
> > > > >                   m)
> > > > >               fdecl (if (map? (last fdecl))
> > > > >                       (butlast fdecl)
> > > > >                       fdecl)
> > > > >               m (conj {:arglists (list 'quote (sigs fdecl))} m)]
> > > > >           (list 'def (with-meta name (conj (if (meta name) (meta name)
> > > > > {}) m))
> > > > >                 (cons `fn fdecl)
>
> > > > > On Jan 13, 8:51 am, HB  wrote:
>
> > > > > > Hey,
> > > > > > How much Clojure source code is complicated?
> > > > > > I'm not a programming Godfather but I would like to study Clojure
> > > > > > source code.
> > > > > > Could an intermediate programmer like me grasp the source code?
> > > > > > 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
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: command-line in clojure.contrib suggestions

2009-01-12 Thread aria42

Couldn't it have access to the other bindings so far like let? And
then just have the order of options reflect the partial order induced
by dependency? So is this possible...

(with-command-line *command-line-args*
  "my-program"
  [[size "The size of something" #(if % (Integer/parseInt %) 99)]
   [picture "Path to Picture" #(load-picture % size)]]
  (do-stuff-with-picture))

Also, other suggestions might be being able to declare an option or
conditional dependencies. Ideally we could have lots
of optional keyword arguments :default, :required, :depends, etc...

This is probably more heavy than most people use, but I would
definitely find it useful.

Thanks, Aria


> (with-command-line *command-line-args*
> >  "my-program"
> >  [[picture "Path to Picture" "/default/path"]]
> >  (def picture (load-picture picture))
> >  (blah))
>
> I usually use the body of with-command-line to simply call other
> functions, so it might look more like:
>
> (with-command-line *command-line-args*
>   "my-program"
>   [[picture "Path to Picture" "/default/path"]
>    [size "The size of something" "99"]]
>   (process-picture (load-picture picture) (Integer. size)))
>
> If each option provided a function, that function wouldn't have access
> to any of the other option values, right?  How useful would that be?
>
> --Chouser
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



command-line in clojure.contrib suggestions

2009-01-12 Thread aria42

Hi,
  I've got some suggestions for improving command-line.clj...

It would be great if you could provide a function to be called with
the value of the option and the result of that function binds to the
variable. This would take care of the annoying stuff like calling
(Integer/parseInt intAsStr) to convert to numerics but also things
like loading resources

(with-command-line *command-line-args*
  "my-program"
  [[picture "Path to Picture" (fn [path] (load-picture path))]]
  (blah))

Currently, you'd need to do something like this, where you might re-
def the var

(with-command-line *command-line-args*
  "my-program"
  [[picture "Path to Picture" "/default/path"]]
  (def picture (load-picture picture))
  (blah))

Unless there's something I'm missing.

--~--~-~--~~~---~--~~
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: Probability distributions in Clojure

2009-01-08 Thread aria42

Hey Conrad, this is great. The only suggestion I'd make is that often
times you want a probability distribution which is updatable over
time. This happens in online learning as well as Gibbs sampling where
you always only implicitly store the posterior b/c it's changing
constantly.  So in my research code, I typically seperate the
sufficient statistics of a distribution (raw counts in the case of a
multinomial as well as a total count to avoid wasteful re-
computations) from the logic of yielding a probability (in the case of
multinomials just return count/total-count).  This way it's easy to
update distributions and make changes on the fly such as altering your
smoothing parameters.

On Jan 8, 1:54 am, Konrad Hinsen  wrote:
> I have just added a new module for handling (finite) probability  
> distributions to clojure-contrib. Some examples are included as well,  
> but for those who want to see the examples without downloading the  
> clojure-contrib source code, I also uploaded them to the files  
> section of this group:
>
>        http://groups.google.com/group/clojure/web/
> probability_distributions.clj
>
> This module was initially inspired by the PFP library for Haskell  
> (seehttp://web.engr.oregonstate.edu/~erwig/pfp/, and in particular  
> the first paper under "further information"), but ended up being  
> quite different:
>
> 1) PFP uses lists of (value probability) pairs to represent  
> distributions. Clojure's maps are a more natural fit, so I use maps  
> from values to probabilities.
>
> 2) At the moment, I have only implemented deterministic  
> transformations of finite probability distributions. PFP also offers  
> random sampling, which I plan to add in the future.
>
> 3) I added a second monad, cond-dist, which allows a straightforward  
> implementation of Bayesian filters.
>
> 4) A significant part of the PFP code does nothing else but hide the  
> implementation details behind a few abstract data types. This makes  
> the code much more difficult to understand. In Clojure we don't have  
> to deal with types, so this overhead disappears.
>
> Any feedback is welcome, as always!
>
> Konrad.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Functional Shuffle

2009-01-04 Thread aria42

Hey all, I wanted to write a functional shuffle sequence (not lazy)
rather than call out to Java. If anyone is interested here it is. If
anyone thinks there is a better way to implement the rifle shuffle,
let me know. Not asserting it's the most efficient or anything.

http://clojure.googlegroups.com/web/shuffle.clj?gsc=ma8fHxYAAABESh7T9QW_5DrK_LhfBk4i-vghgYgES8zAzJdW7J9-8w

Cheers, Aria
--~--~-~--~~~---~--~~
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: How To Make Code More Functional?

2008-12-26 Thread aria42

Clojure for Tajan's Algorithm uploaded here
http://clojure.googlegroups.com/web/tarjan.clj?gsc=yOHJ-CEAAAB3Fq8nFW3O6gqQkWXH_xrOYRvSPFZyhAT412614U6EGkzfKN-m9S9niuHrq-IEXAE

- aria

On Dec 26, 6:30 am, aria42  wrote:
> Hi all,
>   I'm just getting started with clojure from a functional background,
> and while I like playing with clojure and accomplishing script like
> tasks, I have no experience with anything larger than about 20 lines.
> I wanted to try to take something with "alot of state" and put it into
> clojure. I decided to code Tarjan's Algorithm for finding all the
> strongly connected components of a graph (http://en.wikipedia.org/wiki/
> Tarjan's_strongly_connected_components_algorithm). I've written this
> code in Java and it's about a 100 lines. Sadly, my clojure version is
> about a 100 lines too. I am more-or-less translating my java code
> (which is more or less translated from Psuedo-Code), but I don't see a
> good way to make this problem more functional, but this is probably
> due to my imperative roots.
>
>   I have the code posted as an attachment here or posted 
> athttp://www.cs.berkeley.edu/~aria42/tarjan.clj.
>
>   Let me know if there's more canonical / functional ways to do
> something like this.
>
>   Thanks, Aria
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How To Make Code More Functional?

2008-12-26 Thread aria42

Hi all,
  I'm just getting started with clojure from a functional background,
and while I like playing with clojure and accomplishing script like
tasks, I have no experience with anything larger than about 20 lines.
I wanted to try to take something with "alot of state" and put it into
clojure. I decided to code Tarjan's Algorithm for finding all the
strongly connected components of a graph (http://en.wikipedia.org/wiki/
Tarjan's_strongly_connected_components_algorithm). I've written this
code in Java and it's about a 100 lines. Sadly, my clojure version is
about a 100 lines too. I am more-or-less translating my java code
(which is more or less translated from Psuedo-Code), but I don't see a
good way to make this problem more functional, but this is probably
due to my imperative roots.

  I have the code posted as an attachment here or posted at
http://www.cs.berkeley.edu/~aria42/tarjan.clj.


  Let me know if there's more canonical / functional ways to do
something like this.

  Thanks, Aria
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



For Comprehension and println (Noob Question)

2008-12-03 Thread aria42

Hi all,
  When I run the following from the REPL, I see the result of the
"println"

(defn read-docs [duc-dir]
  (for [file (.listFiles (java.io.File. duc-dir))
  :when (.isFile file)]
   (do
 (println file)
 (.getName  file


  However, when embedded in a script (using clojure.lang.Script), I
don't see the result of the println. I'm primarily using it for
debugging the compreshension variables.

   Thanks a lot, Aria


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---