Re: (map f coll) using memfn

2008-10-15 Thread mb

Hi,

On 16 Okt., 05:13, Timothy Pratley <[EMAIL PROTECTED]> wrote:
> Just a few follow on questions...
> 1) Is there any way to do away with the input bindings altogether? map
> doesn't need input bindings, but memfn does. I don't quite grasp why
> they are needed for memfn, or how to construct an input binding based
> on the number of collections. ie: I would need to generate a list of
> symbols the size of the number of collections (map gensym colls) 
> I know that code wont work, but there must be a way.

Maybe you find this helpful: http://paste.lisp.org/display/67182

  (map #(jcall "Timothy" 'substring %1 %2) (iterate inc 0) [3 4 5])

Please note, that the annotation does not allow variadic application
while jcall does. It's trivial to cut arguments, eg.

  #(jcall obj 'method %1 fixed-arg %2 another-fixed %&)

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: toUpperCase on java.lang.String

2008-10-15 Thread Timothy Pratley

Oh wow, powerful syntax!

> user=> (-> "hello" .toUpperCase (.replace "H" "J"))
> "JELLO"

> .. would also work, but I pretty much always prefer -> because you can
> mix in non-methods, and the methods are clearly indicated with a
> leading dot.  In fact, I could imagine lobbying to have .. removed
> (while we're making breaking changes...)

What does 'mix in non-methods' means? I read the (doc ->) but I really
don't follow that explination.
I agree that (-> is a much nicer syntax than (.. and now that I see
how you use it will use it instead.

Speaking of which... I have to say that for someone getting their head
around form expressions the docs are quite terse. Its not always
trivial to find a simple example (I usually find something searching
the groups and wiki and non-api sections of the website). IMHO The
docs would really benefit from an example for each entry. Now I know
that is a great deal of work, so I've started a wiki entry:
http://en.wikibooks.org/wiki/Clojure_Programming_Examples
Where I'm attempting to gather examples I come across from various
sources which have helped me. The idea being that if it ever gets
close to covering the api, they could be somehow programatically
stripped into the (doc and voila there would be examples for every
syntax definition. Just meantioning so that others can look/add and or
comment on the idea.


Regards,
Tim.


--~--~-~--~~~---~--~~
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: Can macros be used for blunt token-pasting?

2008-10-15 Thread Mike Hinchey

On Oct 15, 9:12 pm, Tom Lynch <[EMAIL PROTECTED]> wrote:
> On Oct 16, 2:03 pm, Asbjørn  Bjørnstad <[EMAIL PROTECTED]> wrote:
>
> > Why would it be? Code generation is a ideological yes-yes
> > in lisps.
>
> No idea.  I was just vaguely aware of Strong Opinions floating around
> on topics such as this.  The code I indicated has nothing to do with
> what I'm actually looking at.
>

I've wanted to do this type of thing before (with CL) and generally
try to avoid it, so I'll share my reason: the declaration does not
appear in source code.  This would be particularly confusing if the
macro wrapped code that was meant to reference these symbols because
they could shadow variables you intended to use.

(defmacro let-paste-tokens [[f s] & body]
  `(let [~(symbol (str f s)) 2] [EMAIL PROTECTED]))

(let [foobar 1] (let-paste-tokens [foo bar] foobar))
=> 2

Unless you understand the magic of let-paste-tokens, you can't read
with the normal semantics of clojure code.  Maybe this is not so bad
with a top-level def as in your example, but you still can't grep to
find where some symbol is declared, etc.

-Mike

--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

Thanks again Rich.

Another question about agents. I understand that the actions are
executed automatically by the thread pool. Is there any manual way to
schedule the actions to agents, in case I need some manual control?
--~--~-~--~~~---~--~~
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: splat operator

2008-10-15 Thread Martin DeMello

On Oct 15, 8:07 pm, Michel Salim <[EMAIL PROTECTED]> wrote:
>
> Ah, so to clarify, you need some way to say
>
> (. "hello" (replace \l \m))
>
> but if \l and \m are given in a list, rather than as two separate
> things? Sounds like you might need to write a function to do that.

Yes, apply works in general, but breaks within a doto block.

martin
--~--~-~--~~~---~--~~
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: Can macros be used for blunt token-pasting?

2008-10-15 Thread Tom Lynch

Ah, thanks -- it was the ability of the symbol call to generate a new
sym from a string that I was missing.

On Oct 16, 2:03 pm, Asbjørn  Bjørnstad <[EMAIL PROTECTED]> wrote:
> Why would it be? Code generation is a ideological yes-yes
> in lisps.

No idea.  I was just vaguely aware of Strong Opinions floating around
on topics such as this.  The code I indicated has nothing to do with
what I'm actually looking at.

Thanks

Tom

--~--~-~--~~~---~--~~
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: Can macros be used for blunt token-pasting?

2008-10-15 Thread Asbjørn Bjørnstad



On Oct 16, 10:02 am, Tom Lynch <[EMAIL PROTECTED]> wrote:
> Hi all, I have a naive question regarding Clojure macros.  As someone
> new to Lisp-style macros, can I use the system to generate new names
> using substitution / token-pasting?
>
> Conceptually something like
>
> (defmacro paste-tokens [first second]
>  `(def ~first~second []))
>
> so that (paste-tokens foo bar) expands to (def foobar []).
>
> I realise this may be a huge ideological no-no :-)

Why would it be? Code generation is a ideological yes-yes
in lisps.

user=> (defmacro paste-tokens [f s] `(def ~(symbol (str f s)) []))
nil
user=> (macroexpand-1 '(paste-tokens foo bar))
(def foobar [])

--
 -asbjxrn
--~--~-~--~~~---~--~~
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: Can macros be used for blunt token-pasting?

2008-10-15 Thread Chouser

On Wed, Oct 15, 2008 at 10:02 PM, Tom Lynch <[EMAIL PROTECTED]> wrote:
>
> Hi all, I have a naive question regarding Clojure macros.  As someone
> new to Lisp-style macros, can I use the system to generate new names
> using substitution / token-pasting?
[snip]

> I realise this may be a huge ideological no-no :-)

Well, you'd better have a darn good reason to not be using namespaces
or a hash-map or something. :-)

But sure, it's possible:

user=> (defmacro paste-tokens [first second]
 `(def ~(symbol (str first second)) []))
nil
user=> (macroexpand '(paste-tokens foo bar))
(def foobar [])

The thing to realize is that your macro is just returning a data
structure, and of course you can return a data structure that includes
computed symbol names.  Another way to write the above macro may help
defuse some of the magic quoting magic:

(defmacro paste-tokens [first second]
  (list 'def (symbol (str first second)) []))

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



Re: toUpperCase on java.lang.String

2008-10-15 Thread Stephen C. Gilardi

Hi Parth,

> But if I do this in a doto, it doesn't seem to work but
> I don't get any error message.
>
> user=> (doto (new java.lang.String "hello") (toUpperCase))
> "hello"
> user=> (class (new java.lang.String))
> #=java.lang.String
>
> Shouldn't this be working? If this is (by design) because strings are
> immutable (so no doto) shouldn't there be an error message?
>
> What am I missing here.

"doto" operates on an object and returns the object that it operated  
on. In your case, it's the original string that gets returned. Strings  
are immutable so the toUpperCase call created a new string which was  
then thrown away.

The "->" operator will accomplish what you're looking for here. It  
returns the result of the operations, each result becoming the input  
for the next::

user=> (-> (String. "hello") .toUpperCase)
"HELLO"

--Steve


--~--~-~--~~~---~--~~
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: toUpperCase on java.lang.String

2008-10-15 Thread Chouser

On Wed, Oct 15, 2008 at 11:20 PM, Parth Malwankar
<[EMAIL PROTECTED]> wrote:
>
> But if I do this in a doto, it doesn't seem to work but
> I don't get any error message.
>
> user=> (doto (new java.lang.String "hello") (toUpperCase))
> "hello"
> user=> (class (new java.lang.String))
> #=java.lang.String

doto returns the original object, not the results of any of the
following method calls.  That means it works well for mutable objects,
where in the end you want the mutated object.  But since Strings are
immutable, methods like toUpperCase are returning a new String, not
mutating the old one.  So all you're getting back is your original
String.

Perhaps -> would work better in this case:

user=> (-> "hello" .toUpperCase (.replace "H" "J"))
"JELLO"

.. would also work, but I pretty much always prefer -> because you can
mix in non-methods, and the methods are clearly indicated with a
leading dot.  In fact, I could imagine lobbying to have .. removed
(while we're making breaking changes...)

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



toUpperCase on java.lang.String

2008-10-15 Thread Parth Malwankar

Calling a java method on a string directly works.

user=> (.toUpperCase "hello")
"HELLO"
user=> (class "hello")
#=java.lang.String

But if I do this in a doto, it doesn't seem to work but
I don't get any error message.

user=> (doto (new java.lang.String "hello") (toUpperCase))
"hello"
user=> (class (new java.lang.String))
#=java.lang.String

Shouldn't this be working? If this is (by design) because strings are
immutable (so no doto) shouldn't there be an error message?

What am I missing here.

Parth

--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread Timothy Pratley

Thanks so much for all the replies, that showed the way to what I
wanted (simplified example using substring):

(defn lazy-self [me]
  ((fn rfib [a] (lazy-cons a (rfib a))) me))
(defmacro map-obj [jobj jmeth argbinds & colls]
  `(map (memfn ~jmeth [EMAIL PROTECTED]) (lazy-self ~jobj) [EMAIL PROTECTED]))

(map-obj "Timothy" substring (i j) (iterate inc 0) [3 5 4])

=> ("Tim" "imot" "mo")

ie: I was able to create a macro map-obj which will take a java object
and map a method to a given binding+input collection

Just a few follow on questions...
1) Is there any way to do away with the input bindings altogether? map
doesn't need input bindings, but memfn does. I don't quite grasp why
they are needed for memfn, or how to construct an input binding based
on the number of collections. ie: I would need to generate a list of
symbols the size of the number of collections (map gensym colls) 
I know that code wont work, but there must be a way.
2) Is there a better way than my creation of a lazy-self function, or
is this pretty much the right thing to do?
3) Would I be better off making a macro that expands into a (doto
statement?


Regards,
Tim.
--~--~-~--~~~---~--~~
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: splat operator

2008-10-15 Thread Michel Salim



On Oct 15, 9:08 pm, Martin DeMello <[EMAIL PROTECTED]> wrote:
> On Oct 15, 5:49 pm, Martin DeMello <[EMAIL PROTECTED]> wrote:
>
> > Is there any sort of "splat" operator that expands a list into an
> > inline sequence of arguments? Failing that, is there any way to use
> > apply within a doto block?

Ah, so to clarify, you need some way to say

(. "hello" (replace \l \m))

but if \l and \m are given in a list, rather than as two separate
things? Sounds like you might need to write a function to do that.

Regards,

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



Can macros be used for blunt token-pasting?

2008-10-15 Thread Tom Lynch

Hi all, I have a naive question regarding Clojure macros.  As someone
new to Lisp-style macros, can I use the system to generate new names
using substitution / token-pasting?

Conceptually something like

(defmacro paste-tokens [first second]
 `(def ~first~second []))

so that (paste-tokens foo bar) expands to (def foobar []).

I realise this may be a huge ideological no-no :-)

Thanks

Tom

--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread Rich Hickey



On Oct 15, 10:31 pm, CuppoJava <[EMAIL PROTECTED]> wrote:
> I just found your ants demo Rich. It looks amazingly concise.
>
> Just a quick question: What does the # symbol do?
>
> ie. what's happening here?
>
> ( #(println "hi") )
>
> is # short for: (fn [] ( ... )) ?

Yes, #(...) => (fn [args] (...))

Described fully here:

http://clojure.org/reader

Rich
--~--~-~--~~~---~--~~
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: splat operator

2008-10-15 Thread Michel Salim



On Oct 15, 9:08 pm, Martin DeMello <[EMAIL PROTECTED]> wrote:
> On Oct 15, 5:49 pm, Martin DeMello <[EMAIL PROTECTED]> wrote:
>
> > Is there any sort of "splat" operator that expands a list into an
> > inline sequence of arguments? Failing that, is there any way to use
> > apply within a doto block?
>
> > e..g
>
> > (def search-replace '("ll" "")
> > (def target "hello world")
>
> > (doto target
> >   ;(apply replace search-replace) <-- that, except something that
> > works
>
(replace {"ll" ""} "hello world")

(notice the use of a map rather than a list). This produces a
sequence, though; and wrapping it with (into "" ...) does not work
since a string does not appear to have full Clojure sequence
semantics.

I'm probably missing something regarding string handling, though. But
from what I've seen, it appears that the recommended way is to use
Java's built-in string methods here.

Regards,

--
Michel Salim
--~--~-~--~~~---~--~~
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: Asking for Permission

2008-10-15 Thread [EMAIL PROTECTED]

Rich,thanks,

After i finish my translating work, I will contact you to see whether
it fit on your
web. But i hope so   :)

Best regards

Gerry



On Oct 16, 6:55 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 14, 1:05 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > hello,rich,
>
> > i'm from china,  i found content  in  your Clojure  web is  thoughtful
> > and attractive, i wanna translate it to chinese,
>
> > it will be helpful for  learning Clojure by myself, also for other
> > chinese interested in Clojure language and generic softwares design,
> > but i can't find license of your web content but Clojure software.
>
> I definitely would like to support that. Would you want me to host it
> at clojure.org? There might be some issues with the Wiki software
> there (it's wikispaces)
>
> I'll look into a suitable doc license.
>
> Rich
--~--~-~--~~~---~--~~
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: Documentation bug: assoc

2008-10-15 Thread Michel Salim



On Oct 15, 8:38 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 15, 8:14 pm, Michel Salim <[EMAIL PROTECTED]> wrote:
>
> > The documentation for assoc (both using find-doc and on the website)
> > stipulates that the index must be <= (count col). This is incorrect,
> > though, since index ranges from [0, (count col)) ?
>
> No, the docs are correct - you can assoc one past the end, it's
> equivalent to conj:
>
> (assoc [] 0 :fred)
> -> [:fred]
>
Ah yes, that works. Weird, I had an earlier example that failed, but I
could not reproduce it -- must have made a mistake somewhere, as I was
trying to figure out how to modify references at the same time.

It would be nice to have the two use cases documented -- actually,
just discovered you can keep extending it too:

(assoc [] 0 :a 1 :b 2 :c)

Presumably the left-to-right extension of the vector is part of
assoc's semantics.

Thanks,

--
Michel Salim
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

I just found your ants demo Rich. It looks amazingly concise.

Just a quick question: What does the # symbol do?

ie. what's happening here?

( #(println "hi") )

is # short for: (fn [] ( ... )) ?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



splat operator

2008-10-15 Thread Martin DeMello

Is there any sort of "splat" operator that expands a list into an
inline sequence of arguments? Failing that, is there any way to use
apply within a doto block?

e..g

(def search-replace '("ll" "")
(def target "hello world")

(doto target
  ;(apply replace search-replace) <-- that, except something that
works

martin
--~--~-~--~~~---~--~~
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: splat operator

2008-10-15 Thread Martin DeMello

On Oct 15, 5:49 pm, Martin DeMello <[EMAIL PROTECTED]> wrote:
> Is there any sort of "splat" operator that expands a list into an
> inline sequence of arguments? Failing that, is there any way to use
> apply within a doto block?
>
> e..g
>
> (def search-replace '("ll" "")
> (def target "hello world")
>
> (doto target
>   ;(apply replace search-replace) <-- that, except something that
> works

(okay, bad example,  i forgot the string was immutable anyway :) but
it's mostly the general syntax i'm after)

martin
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread Rich Hickey



On Oct 15, 7:53 pm, CuppoJava <[EMAIL PROTECTED]> wrote:
> Mmm, this is really mind-bending. Particularly because it's a game
> framework, so the state changes with time. Thinking about it from a
> functional programming perspective takes some thinking.
>
> Rich, Agents seem capable of doing some amazing things. Is there a way
> to implement a light-weight threading library with Agents? A link or
> paper would be invaluable.
>

Agents implement a threading system. They use real threads, but not
one per agent. It is certainly possible to have tens of thousands of
agents. Try them!

Rich

--~--~-~--~~~---~--~~
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: Documentation bug: assoc

2008-10-15 Thread Rich Hickey



On Oct 15, 8:14 pm, Michel Salim <[EMAIL PROTECTED]> wrote:
> The documentation for assoc (both using find-doc and on the website)
> stipulates that the index must be <= (count col). This is incorrect,
> though, since index ranges from [0, (count col)) ?
>

No, the docs are correct - you can assoc one past the end, it's
equivalent to conj:

(assoc [] 0 :fred)
-> [:fred]

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



Documentation bug: assoc

2008-10-15 Thread Michel Salim

The documentation for assoc (both using find-doc and on the website)
stipulates that the index must be <= (count col). This is incorrect,
though, since index ranges from [0, (count col)) ?

Thanks,

--
Michel Salim
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

Mmm, this is really mind-bending. Particularly because it's a game
framework, so the state changes with time. Thinking about it from a
functional programming perspective takes some thinking.

Rich, Agents seem capable of doing some amazing things. Is there a way
to implement a light-weight threading library with Agents? A link or
paper would be invaluable.

Thanks a lot
  -Patrick
--~--~-~--~~~---~--~~
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: regex literal syntax

2008-10-15 Thread Chouser

On Wed, Oct 15, 2008 at 7:12 PM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> Patch applied - SVN rev 1070 - thanks!

Possible reader docs:

Regex patterns (#"pattern")
A regex pattern is read and compiled at read time. The pattern is
passed directly to the java.util.regex.Pattern compile method, so its
quoting rules apply instead of the string literal quoting rules.  This
means that unlike string literals, backslashes in regex patterns do
not need to be escaped with another backslash.  For example, #"\d*"
matches zero or more digits.

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



Re: regex literal syntax

2008-10-15 Thread Rich Hickey



On Oct 10, 5:02 pm, Chouser <[EMAIL PROTECTED]> wrote:
> On Fri, Oct 10, 2008 at 7:48 AM, Chouser <[EMAIL PROTECTED]> wrote:
>
> > Of course that means I need to do this for you when printing...
>
> I've attached an updated patch with a new print method, against the
> latest SVN 1058.
>
> If you really want to dig into the ugliness, here's a test I've been
> using.  Apply the attached patch, rebuild clojure, and then load up
> this code:
>
> (import '(java.util.regex Pattern)
> '(java.io PushbackReader StringReader))
> (defn test-re [s & [ts]]
>   (let [p1 (Pattern/compile s)
> p2 (read (PushbackReader. (StringReader. (prn-str p1]
> (println (str "raw str: " s))
> (print   (str "prn1:  " (prn-str p1)))
> (print   (str "prn2:  " (prn-str p2)))
> (println (if (= (prn-str p1) (prn-str p2)) "PASS" "FAIL"))
> (when ts
>   (println (str "match1: " (re-find p1 ts)))
>   (println (str "match2: " (re-find p2 ts)))
>   (println (if (= (re-find p1 ts) (re-find p2 ts)) "PASS" "FAIL")))
> (println)))
>
> You run it by passing in a string to be compiled by Pattern.  This is
> essentially the "old format" without the leading # char:
>
> user=> (test-re "foo")
> raw str: foo
> prn1:  #"foo"
> prn2:  #"foo"
> PASS
>
> If my print method is correct, prn1 and prn2 should always be the
> same, and thus PASS.  Also what you're seeing there is the "new
> format".  In this case, both the old and new formats are the same.
>
> If you pass in an optional second string, test-re will try to match it
> with both patterns:
>
> user=> (test-re "a \\\"\\w*\\\" please" "a \"word\" please")
> raw str: a \"\w*\" please
> prn1:  #"a \"\w*\" please"
> prn2:  #"a \"\w*\" please"
> PASS
> match1: a "word" please
> match2: a "word" please
> PASS
>
> Again, if my patch if my patch is correct, match1 and match2 should be
> the same, and thus another PASS.  Here you can see how the new format
> (prn1 and prn2) are simpler than the old format, as well as being
> identical to what Pattern actually operates on (raw str).
>
> Here's a truly nasty example prompted by Christophe Grand's comment:
>
> user=> (test-re "a\"\\Qb\"c\\d\\Ee\"f" "a\"b\"c\\de\"f")
> raw str: a"\Qb"c\d\Ee"f
> prn1:  #"a\"\Qb\E\"\Qc\d\Ee\"f"
> prn2:  #"a\"\Qb\E\"\Qc\d\Ee\"f"
> PASS
> match1: a"b"c\de"f
> match2: a"b"c\de"f
> PASS
>
> If you can find *any* input that produces FAIL, please let me know.
>

Patch applied - SVN rev 1070 - thanks!

If you use regex literals, this is a breaking change - you must fix
them as described above (basically, \ doesn't need to be escaped
anymore).

Rich

--~--~-~--~~~---~--~~
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: Asking for Permission

2008-10-15 Thread Rich Hickey



On Oct 14, 1:05 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> hello,rich,
>
> i'm from china,  i found content  in  your Clojure  web is  thoughtful
> and attractive, i wanna translate it to chinese,
>
> it will be helpful for  learning Clojure by myself, also for other
> chinese interested in Clojure language and generic softwares design,
> but i can't find license of your web content but Clojure software.
>

I definitely would like to support that. Would you want me to host it
at clojure.org? There might be some issues with the Wiki software
there (it's wikispaces)

I'll look into a suitable doc license.

Rich

--~--~-~--~~~---~--~~
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: remainder function

2008-10-15 Thread Rich Hickey



On Oct 15, 5:44 pm, Achim Passen <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Am 15.10.2008 um 23:35 schrieb Islon:
>
> > Is there a remainder (rest of the division) function in closure? (as
> > java '%' operator).
> > I browse the docs but couldn't find one.
>
> clojure/rem
> ([num div])
>rem[ainder] of dividing numerator by denominator.
>
> I ran into the same problem some time ago - find-doc/searching for
> "remainder" doesn't work here, for obvious reasons. Maybe it's a good
> idea to change the doc string?
>

Done - thanks for the report.

Rich

--~--~-~--~~~---~--~~
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: remainder function

2008-10-15 Thread Islon
Same problem for me.
I didn't know there's a find-doc function, thanks!

Regards

On Wed, Oct 15, 2008 at 6:44 PM, Achim Passen <[EMAIL PROTECTED]>wrote:

>
> Hi,
>
> Am 15.10.2008 um 23:35 schrieb Islon:
>
> > Is there a remainder (rest of the division) function in closure? (as
> > java '%' operator).
> > I browse the docs but couldn't find one.
>
> clojure/rem
> ([num div])
>   rem[ainder] of dividing numerator by denominator.
>
> I ran into the same problem some time ago - find-doc/searching for
> "remainder" doesn't work here, for obvious reasons. Maybe it's a good
> idea to change the doc string?
>
> Kind regards,
> achim
>
> >
>

--~--~-~--~~~---~--~~
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: remainder function

2008-10-15 Thread Brian Doyle
The function is 'rem'.

user=> (rem 5 2)
1


On Wed, Oct 15, 2008 at 3:35 PM, Islon <[EMAIL PROTECTED]> wrote:

> Is there a remainder (rest of the division) function in closure? (as java
> '%' operator).
> I browse the docs but couldn't find one.
>
> >
>

--~--~-~--~~~---~--~~
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: remainder function

2008-10-15 Thread Achim Passen

Hi,

Am 15.10.2008 um 23:35 schrieb Islon:

> Is there a remainder (rest of the division) function in closure? (as  
> java '%' operator).
> I browse the docs but couldn't find one.

clojure/rem
([num div])
   rem[ainder] of dividing numerator by denominator.

I ran into the same problem some time ago - find-doc/searching for  
"remainder" doesn't work here, for obvious reasons. Maybe it's a good  
idea to change the doc string?

Kind regards,
achim

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



remainder function

2008-10-15 Thread Islon
Is there a remainder (rest of the division) function in closure? (as java
'%' operator).
I browse the docs but couldn't find one.

--~--~-~--~~~---~--~~
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: What Windows IDE are you using?

2008-10-15 Thread Dmitri P

I followed Hans's instructions and was able to use compojure's repl
script as swank-clojure-binary. Also, I don't use jline on windows
because cmd provides sufficient editing facilities. I found that swing
JFrame displayed through setVisible hangs slime, it probably needs a
thread wrapper.


On Oct 13, 2:33 am, "Hans Huebner" <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 11, 2008 at 20:34, CuppoJava <[EMAIL PROTECTED]> wrote:
> > If anyone is using Windows, please share what environment you're using
> > to program in.
>
> I am using Emacs and Slime, and that works rather well.
>
> Emacs for Windows:http://ourcomments.org/cgi-bin/emacsw32-dl-latest.pl
> Slime:http://common-lisp.net/project/slime/
> Emacs Clojure mode and Slime for Clojure:http://clojure.codestuffs.com/
>
> My .emacs contains the following Clojure specific Slime setup code.
> The paths need to be modified, and I use swank-clojure-binary instead
> of the Jar method that is described as first choice in the
> swank-clojure documentation.
>
> ;; clojure
> (add-to-list 'load-path "h:/clojure/clojure-mode")
>
> (require 'clojure-auto)
> (load-library "clojure-mode")
>
> (add-to-list 'load-path "h:/clojure/swank-clojure")
> (setq swank-clojure-binary "h:/clojure/clojure.sh")
> (require 'swank-clojure-autoload)
>
> Hope this helps,
> Hans
--~--~-~--~~~---~--~~
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: What Windows IDE are you using?

2008-10-15 Thread Fredrik Appelberg
On Wed, Oct 15, 2008 at 6:05 PM, Mike Hinchey <[EMAIL PROTECTED]> wrote:

>
> I use emacs and slime, also.  Has anyone used http://jdee.sourceforge.net/
> with Clojure, or even just with Java?
>

I've made a few attempts to get going with JDEE, but never really got off
the ground. It has *tons* of dependencies and is a pain to install (although
there is a rather nice apt-gettable package if you happen to be running
Ubuntu), and I never could get it to run like I wanted to.

Some of the components of JDEE are nice, though. I rather like ECB for code
browsing, but the default keybindings for switching between windows are
horrible.

Cheers,
-- Fredrik
==
What am I up to? http://twitter.com/appelberg

--~--~-~--~~~---~--~~
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: Can't find swank/core/DebugQuitException under rev. 1068

2008-10-15 Thread Rich Hickey



On Oct 15, 2:22 pm, "Matthew D. Swank" <[EMAIL PROTECTED]>
wrote:
> On Oct 15, 10:45 am, "Matthew D. Swank" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > Picking the abort restart in the slime debugging window causes an
> > exception:
> > java.lang.NoClassDefFoundError: swank/core/DebugQuitException
> > (NO_SOURCE_FILE:0)
> >   [Thrown class clojure.lang.Compiler$CompilerException]
>
> > Restarts:
> >  0: [ABORT] Return to SLIME's top level.
> >  1: [CAUSE] Throw cause of this exception
>
> > Backtrace:
> >   0: clojure.lang.Compiler.eval(Compiler.java:4116)
> >   1: clojure.eval__778.invoke(boot.clj:1431)
>
> > This seems to be related to a change in clojure and not swank-clojure
> > as it does not happen under rev. 1064.
>
> This went away in rev 1069 (Rich?).
>

Quite possibly. I don't know what that specific problem was about, but
I've backed out the interim code gen that was tripping up people
tracking the head.

Rich

--~--~-~--~~~---~--~~
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: Preliminary AOT support and swank-clojure startup times

2008-10-15 Thread Matthew D. Swank



On Oct 14, 6:35 pm, "Matthew D. Swank" <[EMAIL PROTECTED]>
wrote:
> On Oct 14, 4:48 pm, Randall R Schulz <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Tuesday 14 October 2008 14:17, Matthew D. Swank wrote:
>
> > > Just a data-point:
> > > OS: Windows-XP
> > > CPU: Pentium-IV 2.8 Ghz
> > > Mem: 504 MB
>
> > > JDK:1.6u10rc
>
> > > Startup time of swank-clojure rev. 1064: 6 s.
> > > Startup time of swank-clojure rev. 1068: 120 s!
>
> > You managed to slow it down by a factor of 20??
>
> > I dare say, I could top that...
>
> Well, for the time being the difference seems limited to windows and
> 1.6u10rc.  I won't be able to test another windows vm till
> tomorrow...curious.

Cutting my finger on the mini-tower and a subsequent reboot seems to
have alleviated the matter.  No intuition as to whether it was the
blood sacrifice or the restart that was causal.

Matt
--~--~-~--~~~---~--~~
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: What Windows IDE are you using?

2008-10-15 Thread Paul Drummond

On Oct 15, 5:05 pm, Mike Hinchey <[EMAIL PROTECTED]> wrote:
> I use emacs and slime, also.  Has anyone used http://jdee.sourceforge.net/
> with Clojure, or even just with Java?
>

I tried to get it working in Java a while back but failed miserably -
I can't really remember exactly what the problems were, sorry.  I will
say I was (and still am) very new to EMACS so I probably made a lot of
newbie mistakes.  If people here recommend it I might try again

Would be great to be able to use EMACS full-time at work to hack Java
*and* Clojure, but for now I must resort to Eclipse for my Java
hacking :)

Paul.
--~--~-~--~~~---~--~~
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: Can't find swank/core/DebugQuitException under rev. 1068

2008-10-15 Thread Matthew D. Swank

On Oct 15, 10:45 am, "Matthew D. Swank" <[EMAIL PROTECTED]>
wrote:
> Picking the abort restart in the slime debugging window causes an
> exception:
> java.lang.NoClassDefFoundError: swank/core/DebugQuitException
> (NO_SOURCE_FILE:0)
>   [Thrown class clojure.lang.Compiler$CompilerException]
>
> Restarts:
>  0: [ABORT] Return to SLIME's top level.
>  1: [CAUSE] Throw cause of this exception
>
> Backtrace:
>   0: clojure.lang.Compiler.eval(Compiler.java:4116)
>   1: clojure.eval__778.invoke(boot.clj:1431)
>
> This seems to be related to a change in clojure and not swank-clojure
> as it does not happen under rev. 1064.


This went away in rev 1069 (Rich?).

Matt
--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread Paul Drummond

It's funny how things suddenly click.  While out for a run (the only
time I seem to be able find clarity it seems) I started thinking that
it would be nice to have macros for "require" and "use" so that you
don't have to worry about quoting then I realized that's exactly what
ns is for!

I *should* be using ns like this:

user=> (ns user (:require [clojure.contrib.zip-filter :as zf]))

For some reason I was convinced the ns macro was for use in static
library modules that need to be in their own distinct namespace.  That
is - I thought, it was used to create NEW namespaces.  It didn't click
that ns is more general and allows you to modify existing namespaces
and therefore is just as useful in that sense at the REPL.

Cheers,
Paul.

BTW: That patch is great Stephen - if this gets incorporated it will
make future mistakes with the use of ns very easy to diagnose, 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: (map f coll) using memfn

2008-10-15 Thread mb

Hi,

On 15 Okt., 19:09, "Graham Fawcett" <[EMAIL PROTECTED]> wrote:
> >  (map f coll (range (count coll)))
>
> Rather than (range (count coll)), I would use (iterate inc 0), which
> incurs no overhead for counting the argument.

There is not only the overhead of counting, (count coll) might
also destroy the laziness of the collection.

user=> (count (for [i (range 3)] (do (println i) i)))
0
1
2
3

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hi,

On 15 Okt., 19:11, CuppoJava <[EMAIL PROTECTED]> wrote:
> I'm trying to use this macro to port a game-framework that I've
> written in Ruby, to Clojure.
> ...
> Do you guys have any ideas? Or a direction that I might consider
> looking in?

I can only offer a general advice:

Don't stick to close to your original code.

You said, you used coroutines in Ruby and now you are
asking for them in Clojure. Maybe you should take one
step back and take a view from the distance and try to
think in Clojure.

Suppose the yield in your original post is not a coroutine
thing, but some utility function.

Just to see, that instead of calling it in a loop, one can
also construct the inputs in a seq and map yield over
it, takes sometimes hours for me. But when I get such
sudden idea (which is maybe obvious for experienced
Clojure programmers), I'm always surprised by the
compression it yields. Real case: some >10 pages of
code were shrunk to ~2 pages of code with the same
functionality. I thought, "wtf did I do in the first version?"

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread Jim Menard

On Wed, Oct 15, 2008 at 1:09 PM, Graham Fawcett
<[EMAIL PROTECTED]> wrote:
>
> On Wed, Oct 15, 2008 at 8:21 AM, Jim Menard <[EMAIL PROTECTED]> wrote:
>>
>> On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley
>> <[EMAIL PROTECTED]> wrote:
>>>
>>> Can I get some help with (map f coll)...
>>>
>>> What I want to do is map a java function that takes 2 arguments over a
>>> list
>>> where the first argument is the index into the list itself
>>> and the second argument is taken from the list
>>>
>>> The problem being map uses a function of 1 argument.
>>> Does that mean I need to create my own map, or is there a better way?
>>
>> map can take more than one argument. If it has N arguments, it calls f
>> with N arguments, each taken from the Nth value of each collection. So
>> you should be able to pass in an infinite sequence like this UNTESTED
>> code:
>>
>>  (map f coll (range (count coll)))
>
> Rather than (range (count coll)), I would use (iterate inc 0), which
> incurs no overhead for counting the argument.

You're right; that's better. I'm a Clojure newbie, so I appreciate
learning the faster/smaller/more idiomatic way to do things.

Jim
-- 
Jim Menard, [EMAIL PROTECTED], [EMAIL PROTECTED]
http://www.io.com/~jimm/

--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread Rich Hickey



On Oct 15, 1:11 pm, CuppoJava <[EMAIL PROTECTED]> wrote:
> Thanks for replying Rich and Meikel,
> I'm trying to use this macro to port a game-framework that I've
> written in Ruby, to Clojure.
>
> Essentially, I just need the ability to spawn an extremely large
> amount (~1) of light-weight threads. My framework takes care of
> sequencing them in the right order. I did this in Ruby using
> continuations and coroutines. I thought it'd be rather elegant to
> represent a thread as a lazy-sequence of functions in Clojure, but ran
> into this stumbling block.
>
> Do you guys have any ideas? Or a direction that I might consider
> looking in?
>

You have these facilities, to use separately or together:

agents
lazy sequences
delays

Rich

--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread Rich Hickey



On Oct 15, 11:26 am, "Jim Menard" <[EMAIL PROTECTED]> wrote:
> On Wed, Oct 15, 2008 at 8:21 AM, I wrote:
> > map can take more than one argument. If it has N arguments, it calls f
> > with N arguments, each taken from the Nth value of each collection.
>
> Too many "N"s. Restated, map takes a function f and N collections,
> each of which should have the same number of elements M. It calls f M
> times with N arguments each time, using the i'th element of each of
> the collections. (Darn, I'm wordy :-)
>

Hmm... I still prefer (doc map), but I'd like to clarify that the
collections do not need to be the same length, map will stop as soon
as any one is exhausted.

Rich
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

Thanks for replying Rich and Meikel,
I'm trying to use this macro to port a game-framework that I've
written in Ruby, to Clojure.

Essentially, I just need the ability to spawn an extremely large
amount (~1) of light-weight threads. My framework takes care of
sequencing them in the right order. I did this in Ruby using
continuations and coroutines. I thought it'd be rather elegant to
represent a thread as a lazy-sequence of functions in Clojure, but ran
into this stumbling block.

Do you guys have any ideas? Or a direction that I might consider
looking in?

Thanks again for all your help and support
  -Patrick
--~--~-~--~~~---~--~~
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: read NPE

2008-10-15 Thread Rich Hickey



On Oct 15, 12:14 pm, MikeM <[EMAIL PROTECTED]> wrote:
> In SVN 1067, the following throws an NPE:
>
> (let [frdr (new java.io.StringReader "{:a 1}")
>   prdr (new java.io.PushbackReader frdr)
>   eof   (new Object)]
>(read prdr nil eof)
> )
>
> Using false instead of nil works:
>
> (let [frdr (new java.io.StringReader "{:a 1}")
>   prdr (new java.io.PushbackReader frdr)
>   eof   (new Object)]
>(read prdr false eof)
> )
> ; => {:a 1}

Fixed - SVN rev 1069, thanks for the report.

Rich
--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread Graham Fawcett

On Wed, Oct 15, 2008 at 8:21 AM, Jim Menard <[EMAIL PROTECTED]> wrote:
>
> On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley
> <[EMAIL PROTECTED]> wrote:
>>
>> Can I get some help with (map f coll)...
>>
>> What I want to do is map a java function that takes 2 arguments over a
>> list
>> where the first argument is the index into the list itself
>> and the second argument is taken from the list
>>
>> The problem being map uses a function of 1 argument.
>> Does that mean I need to create my own map, or is there a better way?
>
> map can take more than one argument. If it has N arguments, it calls f
> with N arguments, each taken from the Nth value of each collection. So
> you should be able to pass in an infinite sequence like this UNTESTED
> code:
>
>  (map f coll (range (count coll)))

Rather than (range (count coll)), I would use (iterate inc 0), which
incurs no overhead for counting the argument.

Best,
Graham

--~--~-~--~~~---~--~~
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: Suggest changing update-in to accept additional args for "f"

2008-10-15 Thread Rich Hickey

On Mon, Oct 13, 2008 at 11:02 AM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
>
> I've enclosed a modified definition of update-in that allows the
> update function "f" to take arguments in addition to "old" value being
> updated. The new definition does everything the old definition does
> (when additional arguments are not supplied), but it allows "f" to be
> an existing function more of the time rather than a new closure that
> packages up additional arguments.
>
> Here's an example:
>
>user=> (def m {:a {:b 1}})
>#=(var user/m)
>user=> (update-in m [:a :b] inc)
>{:a {:b 2}}
>user=> (update-in m [:a :b] #(+ % 2)) ; current or new
>{:a {:b 3}}
>user=> (update-in m [:a :b] + 2) ; new
>{:a {:b 3}}
>
> Suggested update-in:
>
> (defn update-in
>   "'Updates' a value in a nested associative structure, where ks is a
>   sequence of keys and f is a function that will take the old value
> and any
>   supplied args and return the new value, and returns a new nested
>   structure.  If any levels do not exist, hash-maps will be created."
>   ([m [k & ks] f & args]
>(if ks
>  (assoc m k (apply update-in (get m k) ks f args))
>  (assoc m k (apply f (get m k) args)
>

Good idea - patch applied (rev 1069) - thanks!

Rich

--~--~-~--~~~---~--~~
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: emacs-cvs and swank-clojure under os-x 10.4

2008-10-15 Thread Fredrik Appelberg
On Wed, Oct 15, 2008 at 5:26 PM, Matthew D. Swank <
[EMAIL PROTECTED]> wrote:

>
> > Yeah, I had som problems with this as well. As far as I can tell, my
> problem
> > was that swank-clojure-extra-classpaths defaulted to '~/.clojure/*', but
> the
> > ability to specify wildcards in the classpath was added in Java 6. As I
> was
> > running Java 5, that had no effect.
> >
> > I worked around it by hacking swank-clojure.el and adding a call to
> > file-expand-wildcards in swank-clojure-cmd to let emacs expand the
> classpath
> > before it was passed to the JVM. I can send you a patch if you like.
>
> Yes, that seems to be the problem. Could you post the patch to the
> news group?  That is unless Jeffery is considering folding it into
> swank-clojure anyway.
>

Here's the patch. It's really just a simple hack to get wildcard expansion
to work and I didn't put much thought into it. Hope it helps, though.

Cheers,
-- Fredrik
==
What am I up to? http://twitter.com/appelberg

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



swank-clojure.el.patch
Description: Binary data


Re: is clojure known to work on any phones with javame?

2008-10-15 Thread Michel Salim

A related question would be: does it work on Android?

Thanks,

--
Michel Salim

On Oct 15, 12:46 am, "Kevin Downey" <[EMAIL PROTECTED]> wrote:
> 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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hi,

On 15 Okt., 18:33, CuppoJava <[EMAIL PROTECTED]> wrote:
> That solution will work for this simple case, but my goal is to make
> it possible to create lazy-sequences in a more straight-forward
> manner. So that we can use the usual sequence functions (doseq,
> dorun, loop) instead of the lazy-equivalents (for).
> Is what I'm asking for impossible?

Obviously I misunderstood your question. The sequence you
wanted would have been just the lazy-cat w/o the map call.

Your are asking for something like coroutines.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread Rich Hickey



On Oct 15, 12:33 pm, CuppoJava <[EMAIL PROTECTED]> wrote:
> Hi Meikel,
> That solution will work for this simple case, but my goal is to make
> it possible to create lazy-sequences in a more straight-forward
> manner. So that we can use the usual sequence functions (doseq, dorun,
> loop) instead of the lazy-equivalents (for).

I think Meikel's solution looks much cleaner, and is shorter. Also,
calling doseq and dorun 'the usual' isn't really the case for Clojure
-  both are imperative, and less frequently used in idiomatic code.

> Is what I'm asking for impossible?

Nothing is impossible, but what you are asking for is imperative
generators. Any such generators have to know about any iteration
constructs they may contain, and how to transform them. The C#
spec[1]  has an example of how they are implemented. You'd need to
make a macro that expanded into a multi-way conditional with each
branch doing a lazy-cons onto a recursive call with the new state.

Generators might make sense for an imperative language, but they would
be inelegant and non-idiomatic for Clojure, IMO.

Rich

[1] 
http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CSharp%20Language%20Specification.doc
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

Hi Meikel,
That solution will work for this simple case, but my goal is to make
it possible to create lazy-sequences in a more straight-forward
manner. So that we can use the usual sequence functions (doseq, dorun,
loop) instead of the lazy-equivalents (for).
Is what I'm asking for impossible?
--~--~-~--~~~---~--~~
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: packaging App (cross-platform) without scripts, only jar

2008-10-15 Thread R. P. Dillon

> Cool, thanks. That worked (http://jalat.com/static-files/
> Is it possible to have a subdirectory in the classpath
> as well, or does everything have to be from the root? (Ie. Could
> clojure have been in a subdirectory lib and classpath have been set to
> ". lib/"?)
> I tried that but it seems like that was parsed to a pathname outside
> of the jar.

>From what I've done with Executable jars, the classpath specified in
the manifest will tend to be the root (".").

As an aside, another way to approach this if you don't feel like
tearing apart clojure.jar is to create your own jar without clojure,
and specify a relative path to clojure.jar:

Project
|_YourJar.jar
|_lib
   |_clojure.jar

and then you can put make your manifest in YourJar.jar say something
like:

Class-Path: .:lib/clojure.jar

Maybe someone else know if there is any other way to get the Class-
Path in a jar to point to a subdirectory of the jar -- I haven't seen
that.

-Rick
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hello,

On 15 Okt., 17:53, CuppoJava <[EMAIL PROTECTED]> wrote:
> What's supposed to do is take an arbitrary-form, and create a lazy
> sequence out of calls to "yield".

You can construct the inputs in a lazy sequence and then map
yield over that:

(map yield
 (lazy-cat (for [i (range 3)]
 i)
   [(if true "Hello World" "Dlrow Olleh")]
   (for [i (range 2)
 j (range 2)]
 [i j])))

Since map, lazy-cat and for are all lazy, it should do, what
you want.

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



read NPE

2008-10-15 Thread MikeM

In SVN 1067, the following throws an NPE:

(let [frdr (new java.io.StringReader "{:a 1}")
  prdr (new java.io.PushbackReader frdr)
  eof   (new Object)]
   (read prdr nil eof)
)

Using false instead of nil works:

(let [frdr (new java.io.StringReader "{:a 1}")
  prdr (new java.io.PushbackReader frdr)
  eof   (new Object)]
   (read prdr false eof)
)
; => {:a 1}
--~--~-~--~~~---~--~~
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: What Windows IDE are you using?

2008-10-15 Thread Mike Hinchey

I use emacs and slime, also.  Has anyone used http://jdee.sourceforge.net/
with Clojure, or even just with Java?

-Mike

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



Help writing this Lazy Sequence Macro

2008-10-15 Thread CuppoJava

Hi guys,
I'm just wondering if it's possible for the following macro to be
written.
What's supposed to do is take an arbitrary-form, and create a lazy
sequence out of calls to "yield".

Here's an example:

(lazy-seq
  (doseq i (range 3)
(yield i))
  (if true
(yield "hello world")
(yield "dlrow olleh"))
  (doseq j (range 2)
(doseq k (range 2)
  (yield [j k]

This should produce the following lazy sequence:
0, 1, 2, "hello world", [0 0], [0 1], [1 0], [1 1]

It's important to me for the sequence to be genuinely lazy too. The
code to produce the corresponding values shouldn't even run, until the
values are needed.

Thanks for your help
-Patrick
--~--~-~--~~~---~--~~
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: primitive meta data

2008-10-15 Thread Islon
Thanks for the advices.
The unchecked version run as fast as java.
Before I go solve some interesting problem I have to learn the language ;)
Thanks anyway.

On Wed, Oct 15, 2008 at 12:04 PM, Chouser <[EMAIL PROTECTED]> wrote:

>
> On Wed, Oct 15, 2008 at 7:08 AM, Parth Malwankar
> <[EMAIL PROTECTED]> wrote:
> >
> > On Oct 15, 8:34 am, Islon <[EMAIL PROTECTED]> wrote:
> >>
> >> (defn dumb-test []
> >>   (let [#^Float f2 567.09723]
> >> (loop [#^Float f 1.8, i 1000]
> >>   (if (zero? i)
> >> f
> >> (recur (/ f f2) (dec i))
>
> The type hints aren't really helping there, I think.  #^Float might
> help if you were calling a Java function and wanted to avoid the
> runtime reflection lookup cost, but you're only calling Clojure
> functions so it doesn't help.
>
> On my machine, about 180 msecs
>
> To get unboxed primitives, you have to do more like what Parth did:
>
> > (defn dumb-test []
> >  (let [f2 (float 567.09723)]
> >(loop [f (float 1.2), i (long 1000)]
> >  (if (zero? i)
> >f
> >(recur (/ f f2) (dec i))
>
> On my machine that's 48 msecs.
>
> But we can do a bit better, just by using unchecked-dec:
>
> (defn dumb-test []
>  (let [f2 (float 567.09723)]
>   (loop [f (float 1.2), i (long 1000)]
> (if (zero? i)
>   f
>(recur (/ f f2) (unchecked-dec i))
>
> That's 24 msecs for me.
>
> But I don't know how useful these kinds of micro-benchmarks really
> are.  Clojure's "fast enough" so let's go solve some interesting
> problems...
>
> --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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Can't find swank/core/DebugQuitException under rev. 1068

2008-10-15 Thread Matthew D. Swank

Picking the abort restart in the slime debugging window causes an
exception:
java.lang.NoClassDefFoundError: swank/core/DebugQuitException
(NO_SOURCE_FILE:0)
  [Thrown class clojure.lang.Compiler$CompilerException]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [CAUSE] Throw cause of this exception

Backtrace:
  0: clojure.lang.Compiler.eval(Compiler.java:4116)
  1: clojure.eval__778.invoke(boot.clj:1431)

This seems to be related to a change in clojure and not swank-clojure
as it does not happen under rev. 1064.

Matt
--~--~-~--~~~---~--~~
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: primitive meta data

2008-10-15 Thread Rich Hickey



On Oct 15, 11:04 am, Chouser <[EMAIL PROTECTED]> wrote:
> On Wed, Oct 15, 2008 at 7:08 AM, Parth Malwankar
>
> <[EMAIL PROTECTED]> wrote:
>
> > On Oct 15, 8:34 am, Islon <[EMAIL PROTECTED]> wrote:
>
> >> (defn dumb-test []
> >>   (let [#^Float f2 567.09723]
> >> (loop [#^Float f 1.8, i 1000]
> >>   (if (zero? i)
> >> f
> >> (recur (/ f f2) (dec i))
>
> The type hints aren't really helping there, I think.  #^Float might
> help if you were calling a Java function and wanted to avoid the
> runtime reflection lookup cost, but you're only calling Clojure
> functions so it doesn't help.
>
> On my machine, about 180 msecs
>
> To get unboxed primitives, you have to do more like what Parth did:
>
> > (defn dumb-test []
> >  (let [f2 (float 567.09723)]
> >(loop [f (float 1.2), i (long 1000)]
> >  (if (zero? i)
> >f
> >(recur (/ f f2) (dec i))
>
> On my machine that's 48 msecs.
>
> But we can do a bit better, just by using unchecked-dec:
>
> (defn dumb-test []
>  (let [f2 (float 567.09723)]
>(loop [f (float 1.2), i (long 1000)]
>  (if (zero? i)
>f
>(recur (/ f f2) (unchecked-dec i))
>
> That's 24 msecs for me.
>
> But I don't know how useful these kinds of micro-benchmarks really
> are.  Clojure's "fast enough" so let's go solve some interesting
> problems...
>

Exactly. It's likely that that 24 msecs is the same time as the
original Java would be on your box. It's already been demonstrated
that with the -server JIT, Clojure can, in inner loops involving
primitives, equal the speed of Java. So everyone can rest assured that
that capability is there should they need it. The way to get it is as
you've demonstrated, with primitive casts. Type hints are only for
helping the compiler with Java method calls.

But until there's a real performance challenge that's the bottleneck
in a real application, there's no reason to get involved in this kind
of micro-optimization - it's really a waste of time.

Writing code in the clearest, most high-level way is best, and as you
say, in Clojure, is usually fast enough.

Rich

--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread Jim Menard

On Wed, Oct 15, 2008 at 8:21 AM, I wrote:

> map can take more than one argument. If it has N arguments, it calls f
> with N arguments, each taken from the Nth value of each collection.

Too many "N"s. Restated, map takes a function f and N collections,
each of which should have the same number of elements M. It calls f M
times with N arguments each time, using the i'th element of each of
the collections. (Darn, I'm wordy :-)

Jim
-- 
Jim Menard, [EMAIL PROTECTED], [EMAIL PROTECTED]
http://www.io.com/~jimm/

--~--~-~--~~~---~--~~
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: emacs-cvs and swank-clojure under os-x 10.4

2008-10-15 Thread Matthew D. Swank

On Oct 15, 6:47 am, "Fredrik Appelberg" <[EMAIL PROTECTED]>
wrote:
> On Tue, Oct 14, 2008 at 9:49 PM, Matthew D. Swank <
>
>
>
> [EMAIL PROTECTED]> wrote:
>
> > swank-clojure seems to work fine; it just seems that java is ignoring
> > 'swank-clojure-extra-classpaths.
>
> > in slime:
>
> > user> (require 'clojure.contrib.zip-filter)
> > java.io.FileNotFoundException: Could not locate Clojure resource on
> > classpath: clojure/contrib/zip_filter/zip_filter.clj (NO_SOURCE_FILE:
> > 0)
>
> > at a shell:
>
> > java -cp /sw/local/src/clojure/target/clojure-lang-1.0-SNAPSHOT.jar:/
> > Users//.clojure/clojure-contrib.jar clojure.lang.Repl
> > Clojure
> > user=> (require 'clojure.contrib.zip-filter)
> > nil
> > user=>
>
> > Anyone using clojure on a mac?
>
> Yeah, I had som problems with this as well. As far as I can tell, my problem
> was that swank-clojure-extra-classpaths defaulted to '~/.clojure/*', but the
> ability to specify wildcards in the classpath was added in Java 6. As I was
> running Java 5, that had no effect.
>
> I worked around it by hacking swank-clojure.el and adding a call to
> file-expand-wildcards in swank-clojure-cmd to let emacs expand the classpath
> before it was passed to the JVM. I can send you a patch if you like.

Yes, that seems to be the problem. Could you post the patch to the
news group?  That is unless Jeffery is considering folding it into
swank-clojure anyway.

Thanks,

Matt
--~--~-~--~~~---~--~~
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: What Windows IDE are you using?

2008-10-15 Thread Fredrik Appelberg
On Mon, Oct 13, 2008 at 8:33 AM, Hans Huebner <[EMAIL PROTECTED]>wrote:

>
> On Sat, Oct 11, 2008 at 20:34, CuppoJava <[EMAIL PROTECTED]>
> wrote:
> > If anyone is using Windows, please share what environment you're using
> > to program in.
>
> I am using Emacs and Slime, and that works rather well.
>
> Emacs for Windows: http://ourcomments.org/cgi-bin/emacsw32-dl-latest.pl
> Slime: http://common-lisp.net/project/slime/
> Emacs Clojure mode and Slime for Clojure: http://clojure.codestuffs.com/
>

This is pretty much identical to my setup. SLIME is the reason I went back
to Emacs from Vim, and nowadays I pretty much use it for everything
(although I do fire up Eclipse every now and then for refactoring and
debugging). Emacs for Windows is actually pretty decent.

BTW, does anyone know of a good stand-alone java profiler that plays nice
with Clojure? Preferably open source...

Cheers,
-- Fredrik

--~--~-~--~~~---~--~~
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: primitive meta data

2008-10-15 Thread Chouser

On Wed, Oct 15, 2008 at 7:08 AM, Parth Malwankar
<[EMAIL PROTECTED]> wrote:
>
> On Oct 15, 8:34 am, Islon <[EMAIL PROTECTED]> wrote:
>>
>> (defn dumb-test []
>>   (let [#^Float f2 567.09723]
>> (loop [#^Float f 1.8, i 1000]
>>   (if (zero? i)
>> f
>> (recur (/ f f2) (dec i))

The type hints aren't really helping there, I think.  #^Float might
help if you were calling a Java function and wanted to avoid the
runtime reflection lookup cost, but you're only calling Clojure
functions so it doesn't help.

On my machine, about 180 msecs

To get unboxed primitives, you have to do more like what Parth did:

> (defn dumb-test []
>  (let [f2 (float 567.09723)]
>(loop [f (float 1.2), i (long 1000)]
>  (if (zero? i)
>f
>(recur (/ f f2) (dec i))

On my machine that's 48 msecs.

But we can do a bit better, just by using unchecked-dec:

(defn dumb-test []
 (let [f2 (float 567.09723)]
   (loop [f (float 1.2), i (long 1000)]
 (if (zero? i)
   f
   (recur (/ f f2) (unchecked-dec i))

That's 24 msecs for me.

But I don't know how useful these kinds of micro-benchmarks really
are.  Clojure's "fast enough" so let's go solve some interesting
problems...

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



Re: using libraries

2008-10-15 Thread Paul Drummond

On Oct 15, 2:21 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> Here's the portion of (doc require) where it's mentioned:
>
> [...]
>    Libspecs
>
>    A libspec is a lib name or a vector containing a lib name followed by
>    options expressed as sequential keywords and arguments.
>
>    Recognized options: :as
>    :as takes a symbol as its argument and makes that symbol an alias  
> to the
>      lib's namespace in the current namespace.
> [...]
>
> If you'd like to make a suggestion for improved clarity, please do.

You know, now I understand how it works the docs make perfect sense!

I swear I read it 50 times before my initial post and it didn't sink
in, but that's just me.

If you start modifying the docs to accommodate my simple mind you'll
be on forever!  :)

Seriously though, the docs are clear - I'll be sure to read them more
thoroughly before posting in the future.

Thanks for your help,
Paul.
--~--~-~--~~~---~--~~
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: packaging App (cross-platform) without scripts, only jar

2008-10-15 Thread Asbjørn Bjørnstad



On Oct 15, 4:57 am, "R. P. Dillon" <[EMAIL PROTECTED]> wrote:
> On Oct 14, 10:04 am, Asbjørn  Bjørnstad <[EMAIL PROTECTED]> wrote:
> >
> > So it is not possible to put the clj files into the jar so that no
> > unzipping
> > is neccessary? I tried, but my java/jar knowledge is basically zero.
> > --
> >  -asbjxrn
>
> I put together an quick tutorial of how I made an executable jar for
> an example "Hello World" app in Clojure.  Suggestions welcome.
>
> http://rpdillon.googlepages.com/creatingexecutablejarswithclojure

Cool, thanks. That worked (http://jalat.com/static-files/
ChordLib.jar). Is it possible to have a subdirectory in the classpath
as well, or does everything have to be from the root? (Ie. Could
clojure have been in a subdirectory lib and classpath have been set to
". lib/"?)
I tried that but it seems like that was parsed to a pathname outside
of the jar.
--
 -asbjxrn
--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread Stephen C. Gilardi


On Oct 15, 2008, at 3:22 AM, Paul Drummond wrote:

> Hmmm.  Now I am getting this:
>
> (require 'clojure.contrib.zip-filter :as 'zf)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.Symbol (NO_SOURCE_FILE:0)
>
> Any ideas?

I've enclosed a patch to boot.clj that will give a clearer error  
message in this case:

user=> (require 'clojure.contrib.zip-filter :as 'zf)
java.lang.IllegalArgumentException: not a libspec or prefix list: :as  
(NO_SOURCE_FILE:0)

--Steve

diff --git src/clj/clojure/boot.clj src/clj/clojure/boot.clj
index 7de6888..d27b0a1 100644
--- src/clj/clojure/boot.clj
+++ src/clj/clojure/boot.clj
@@ -3168,20 +3168,28 @@
(printf ")\n"))
  (apply refer lib (mapcat seq filter-opts))

+(def list?)
+
  (defn- load-libs
"Loads libs, interpreting libspecs, prefix lists, and flags for
forwarding to load-lib"
[& args]
-  (let [flags (filter keyword? args)
+  (let [flag? #{:reload :reload-all :require :use :verbose}
+flags (filter flag? args)
  opts (interleave flags (repeat true))
-args (filter (complement keyword?) args)]
+args (filter (complement flag?) args)]
  (doseq arg args
-  (if (libspec? arg)
-(apply load-lib nil (prependss arg opts))
-(let [[prefix & args] arg]
-  (throw-if (nil? prefix) "prefix cannot be nil")
-  (doseq arg args
-(apply load-lib prefix (prependss arg opts
+  (cond (libspec? arg)
+(apply load-lib nil (prependss arg opts))
+(list? arg)
+(let [[prefix & args] arg]
+  (throw-if (nil? prefix) "prefix cannot be nil")
+  (doseq arg args
+(apply load-lib prefix (prependss arg opts
+:else
+(throw (IllegalArgumentException.
+(format "not a libspec or prefix list: %s"
+arg)))

  ;; Public



--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread Stephen C. Gilardi


On Oct 15, 2008, at 5:03 AM, Paul Drummond wrote:

>
> On Oct 15, 9:34 am, mb <[EMAIL PROTECTED]> wrote:
>> You might want to try (require ['clojure.contrib.zip-filter :as  
>> 'zf]).
>> AFAIR, you have to use [] when you want to specify :as.
>
> Ah, that's it!  This isn't clear (or mentioned unless I'm mistaken) in
> the docs.
>
> Thanks for your help.
>
> Paul.

I'm sorry I didn't diagnose the problem with your require statement  
properly in my initial reply.

Quoting the entire vector saves a quote as well:

  (require '[clojure.contrib.zip-filter :as zf])

Here's the portion of (doc require) where it's mentioned:

[...]
   Libspecs

   A libspec is a lib name or a vector containing a lib name followed by
   options expressed as sequential keywords and arguments.

   Recognized options: :as
   :as takes a symbol as its argument and makes that symbol an alias  
to the
 lib's namespace in the current namespace.
[...]

If you'd like to make a suggestion for improved clarity, please do.

--Steve


--~--~-~--~~~---~--~~
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: are pr & friends correct for regexps?

2008-10-15 Thread Stuart Halloway

Yep, I was on an older build. Nevermind. :-)

> On Mon, Oct 13, 2008 at 9:06 AM, Stuart Halloway
> <[EMAIL PROTECTED]> wrote:
>>
>> (prn #"\\w+")
>> -> \w+
>
> Works for me, SVN 1067:
> user=> #"\\w+"
> #"\\w+"
> user=> (prn #"\\w+")
> #"\\w+"
> nil
>
> --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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: (map f coll) using memfn

2008-10-15 Thread Jim Menard

On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley
<[EMAIL PROTECTED]> wrote:
>
> Can I get some help with (map f coll)...
>
> What I want to do is map a java function that takes 2 arguments over a
> list
> where the first argument is the index into the list itself
> and the second argument is taken from the list
>
> The problem being map uses a function of 1 argument.
> Does that mean I need to create my own map, or is there a better way?

map can take more than one argument. If it has N arguments, it calls f
with N arguments, each taken from the Nth value of each collection. So
you should be able to pass in an infinite sequence like this UNTESTED
code:

  (map f coll (range (count coll)))

Jim

>
>
> Specifically what I'm struggling with:
>
> (def *scene-graph* (new javax.media.j3d.BranchGroup))
>
> (defn poly [label points]
>   (let [la (new javax.media.j3d.LineArray (count points)
> (.COORDINATES javax.media.j3d.LineArray)]
> (map (memfn javax.media.j3d.LineArray.setCoordinate idx (new
> javax.vecmath.Point3f x y 0) points)
> (.addChild *scene-graph* (new javax.media.j3d.Shape3D la
>
> The intention being that points is a list of x,y coordinates
> I construct a LineArray which is the size of points
> then for every point I need to call setCoordinate(index, Point3f(x,y))
> The LineArray then makes a Shape3D which can be added to the scene
> graph.
>
>
> Regards,
> Tim.
>
>
>
>
>
> >
>



-- 
Jim Menard, [EMAIL PROTECTED], [EMAIL PROTECTED]
http://www.io.com/~jimm/

--~--~-~--~~~---~--~~
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: emacs-cvs and swank-clojure under os-x 10.4

2008-10-15 Thread Fredrik Appelberg
On Tue, Oct 14, 2008 at 9:49 PM, Matthew D. Swank <
[EMAIL PROTECTED]> wrote:

>
> swank-clojure seems to work fine; it just seems that java is ignoring
> 'swank-clojure-extra-classpaths.
>
> in slime:
>
> user> (require 'clojure.contrib.zip-filter)
> java.io.FileNotFoundException: Could not locate Clojure resource on
> classpath: clojure/contrib/zip_filter/zip_filter.clj (NO_SOURCE_FILE:
> 0)
>
>
> at a shell:
>
> java -cp /sw/local/src/clojure/target/clojure-lang-1.0-SNAPSHOT.jar:/
> Users//.clojure/clojure-contrib.jar clojure.lang.Repl
> Clojure
> user=> (require 'clojure.contrib.zip-filter)
> nil
> user=>
>
> Anyone using clojure on a mac?
>

Yeah, I had som problems with this as well. As far as I can tell, my problem
was that swank-clojure-extra-classpaths defaulted to '~/.clojure/*', but the
ability to specify wildcards in the classpath was added in Java 6. As I was
running Java 5, that had no effect.

I worked around it by hacking swank-clojure.el and adding a call to
file-expand-wildcards in swank-clojure-cmd to let emacs expand the classpath
before it was passed to the JVM. I can send you a patch if you like.

Cheers,
-- Fredrik

--~--~-~--~~~---~--~~
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: Making a living on Clojure

2008-10-15 Thread Chance

Have any of you had a look at the Commercial Users of Functional
Programming (CUFP) group?  They are not specific to Clojure, but are
people who have been working on making the business case for
functional languages like clojure.  They would probably be interested
in this discussion.

http://groups.google.com/group/cufp

Regards,
Chance


On Oct 14, 3:13 pm, Fogus <[EMAIL PROTECTED]> wrote:
> I am attempting to work Clojure (at least partially) into my job, but
> in doing so I wonder how many of you here use it at your own jobs as
> opposed to relegating it to hobby.
>
> -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
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: Refs and ensure

2008-10-15 Thread Rich Hickey

On Oct 14, 10:33 pm, Tom Davies <[EMAIL PROTECTED]> wrote:
> In relational database terms, Clojure's STM has 'read-committed'
> isolation when you don't use 'ensure', then?

No, it's snapshot isolation, which is distinct from all of the
traditional isolation levels:

http://en.wikipedia.org/wiki/Snapshot_isolation

Read committed doesn't promise anything about the relationship between
multiple reads in the same transaction. Snapshot isolation says
they'll all represent the same point in time - it's a stronger
guarantee.

A useful paper contrasting isolation levels:

http://www.cs.umb.edu/~poneil/iso.pdf

Rich


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



(map f coll) using memfn

2008-10-15 Thread Timothy Pratley

Can I get some help with (map f coll)...

What I want to do is map a java function that takes 2 arguments over a
list
where the first argument is the index into the list itself
and the second argument is taken from the list

The problem being map uses a function of 1 argument.
Does that mean I need to create my own map, or is there a better way?


Specifically what I'm struggling with:

(def *scene-graph* (new javax.media.j3d.BranchGroup))

(defn poly [label points]
   (let [la (new javax.media.j3d.LineArray (count points)
(.COORDINATES javax.media.j3d.LineArray)]
 (map (memfn javax.media.j3d.LineArray.setCoordinate idx (new
javax.vecmath.Point3f x y 0) points)
 (.addChild *scene-graph* (new javax.media.j3d.Shape3D la

The intention being that points is a list of x,y coordinates
I construct a LineArray which is the size of points
then for every point I need to call setCoordinate(index, Point3f(x,y))
The LineArray then makes a Shape3D which can be added to the scene
graph.


Regards,
Tim.





--~--~-~--~~~---~--~~
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: primitive meta data

2008-10-15 Thread Parth Malwankar



On Oct 15, 8:34 am, Islon <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I've made a dumb (very dumb) performance comparison function just to play
> with the language.
> I wanted to mark some symbols with a float primitive type but the compiler
> complained so I had to annotate it with the Float class.
> Here is the function:
>
> (defn dumb-test []
>   (let [#^Float f2 567.09723]
>     (loop [#^Float f 1.8, i 1000]
>       (if (zero? i)
>         f
>         (recur (/ f f2) (dec i))
>
> And the test:
>
> (loop [i 50]
>   (time (dumb-test))
>   (if (zero? i)
>     i
>     (recur (dec i
>
> There's a way to put a float primitive type in the metadata to prevent the
> Float -> float unboxing?
> Feel free to point some mistakes I probably made, I've just started learn
> clojure.
>

> The clojure version took an average: "Elapsed time: 217.833342 msecs" in my
> machine.

The following was somewhat faster.

(defn dumb-test []
  (let [f2 (float 567.09723)]
(loop [f (float 1.2), i (long 1000)]
  (if (zero? i)
f
(recur (/ f f2) (dec i))

I get about 59ms on my machine.
user=> (time (dumb-test))
"Elapsed time: 59.245176 msecs"
0.0

Parth



>
> The java version (below) took average 23 msecs:
>
> private static float dumbTest() {
>         float f = 1.8f;
>         float f2 = 567.09723f;
>         for(int i = 0; i < 1000; i++) {
>             f /= f2;
>         }
>         return f;
>     }
>
> Regards.
> Islon
--~--~-~--~~~---~--~~
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: Refs and ensure

2008-10-15 Thread Tom Davies

In relational database terms, Clojure's STM has 'read-committed'
isolation when you don't use 'ensure', then?

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



primitive meta data

2008-10-15 Thread Islon
Hi.

I've made a dumb (very dumb) performance comparison function just to play
with the language.
I wanted to mark some symbols with a float primitive type but the compiler
complained so I had to annotate it with the Float class.
Here is the function:

(defn dumb-test []
  (let [#^Float f2 567.09723]
(loop [#^Float f 1.8, i 1000]
  (if (zero? i)
f
(recur (/ f f2) (dec i))

And the test:

(loop [i 50]
  (time (dumb-test))
  (if (zero? i)
i
(recur (dec i

There's a way to put a float primitive type in the metadata to prevent the
Float -> float unboxing?
Feel free to point some mistakes I probably made, I've just started learn
clojure.

The clojure version took an average: "Elapsed time: 217.833342 msecs" in my
machine.

The java version (below) took average 23 msecs:

private static float dumbTest() {
float f = 1.8f;
float f2 = 567.09723f;
for(int i = 0; i < 1000; i++) {
f /= f2;
}
return f;
}

Regards.
Islon

--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread Paul Drummond

On Oct 15, 9:34 am, mb <[EMAIL PROTECTED]> wrote:
> You might want to try (require ['clojure.contrib.zip-filter :as 'zf]).
> AFAIR, you have to use [] when you want to specify :as.

Ah, that's it!  This isn't clear (or mentioned unless I'm mistaken) in
the docs.

Thanks for your help.

Paul.
--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread mb

Hi,

On 15 Okt., 09:22, Paul Drummond
<[EMAIL PROTECTED]> wrote:
> Hmmm.  Now I am getting this:
>
> (require 'clojure.contrib.zip-filter :as 'zf)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.Symbol (NO_SOURCE_FILE:0)
>
> Any ideas?

You might want to try (require ['clojure.contrib.zip-filter :as 'zf]).
AFAIR, you have to use [] when you want to specify :as.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: using libraries

2008-10-15 Thread Paul Drummond

Hmmm.  Now I am getting this:

(require 'clojure.contrib.zip-filter :as 'zf)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.Symbol (NO_SOURCE_FILE:0)

Any ideas?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---