Re: Translation from Common Lisp 1

2010-03-19 Thread alux
David, thank you. Your answer seems to be nearest possible to the
origninal spirit. Obviousely the way syntax-quote is resolved
qualified with a namespace makes the easier way impossible.

Regards, alux

On 18 Mrz., 22:17, David Nolen  wrote:
> On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:
> > Hello!
>
> > I much enjoyed reading the tutorialhttp://www.lisperati.com/casting.html
> > , mentioned by eyeris today. The most mind-extending thing (to me,
> > having Java background) is the, admittedly non-idiomatic, use of
> > symbols as data.
>
> > But I have two translation problems, I want to pose before going to
> > sleep (its pitch dark in Europe :). First the easy one:
>
> > Common Lisp
> > (defun describe-path (path)
> >  `(there is a ,(second path) going ,(first path) from here.))
>
> You probably want
>
> (defn describe-path [path]
>    `(~'there ~'is ~'a ~(second path) ~'going ~(first path) ~'from ~'here))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 1

2010-03-19 Thread alux
> >> But using symbols for something like this is a bit contrived anyway.

Yes, But sometimes it needs contrived examples to get the message.
Especially if you have misleading preconceptions. And to me, symbols
had always been a way to refer to stuff. And only that. That had to be
shaken an is now.

(Like the old hastable example: A consistent implementation is
returning a constant. Thats slow and doesnt scale, but it's
consistent. To me thats been illuminating.)

Many thanks to all for the discussion.

alux

On 18 Mrz., 23:21, Richard Newman  wrote:
> >> But using symbols for something like this is a bit contrived anyway.
>
> > Maybe, but I've seen it in other Common Lisp books/tutorials before.
> > e.g. I'm sure PAIP was one of them.
>
> Part of the motivation is that CL symbols always compare with EQ and  
> EQL, whilst strings are not required to do so:
>
> cl-user(9): (eq (concatenate 'string "foo" "bar") "foobar")
> nil
>
> This means you can use nice constructs such as CASE with symbols, but  
> you need to roll your own using string-equal or string= to handle  
> strings.
>
> (Using symbols also saves you typing all those double-quote  
> characters, as well as saving memory and computation during  
> comparison: symbols are interned, unlike strings.)
>
> In Clojure (thanks to Java's immutable interned strings) strings  
> compare efficiently with = just like everything else, so there's less  
> motivation.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 1

2010-03-19 Thread Christophe Grand
If you really wan't to go that way you can also choose to remove the
namespaces:
(defn describe-path [[where what]]
  (map (comp symbol name) `(there is a ~what going ~where from here.)))


On Fri, Mar 19, 2010 at 8:17 AM, alux  wrote:

> > >> But using symbols for something like this is a bit contrived anyway.
>
> Yes, But sometimes it needs contrived examples to get the message.
> Especially if you have misleading preconceptions. And to me, symbols
> had always been a way to refer to stuff. And only that. That had to be
> shaken an is now.
>
> (Like the old hastable example: A consistent implementation is
> returning a constant. Thats slow and doesnt scale, but it's
> consistent. To me thats been illuminating.)
>
> Many thanks to all for the discussion.
>
> alux
>
> On 18 Mrz., 23:21, Richard Newman  wrote:
> > >> But using symbols for something like this is a bit contrived anyway.
> >
> > > Maybe, but I've seen it in other Common Lisp books/tutorials before.
> > > e.g. I'm sure PAIP was one of them.
> >
> > Part of the motivation is that CL symbols always compare with EQ and
> > EQL, whilst strings are not required to do so:
> >
> > cl-user(9): (eq (concatenate 'string "foo" "bar") "foobar")
> > nil
> >
> > This means you can use nice constructs such as CASE with symbols, but
> > you need to roll your own using string-equal or string= to handle
> > strings.
> >
> > (Using symbols also saves you typing all those double-quote
> > characters, as well as saving memory and computation during
> > comparison: symbols are interned, unlike strings.)
> >
> > In Clojure (thanks to Java's immutable interned strings) strings
> > compare efficiently with = just like everything else, so there's less
> > motivation.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to clojure+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>



-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Konrad Hinsen

On 18 Mar 2010, at 16:55, Per Vognsen wrote:


Is there any reason why a .method occurrence in non-operator position
doesn't just do the closure wrapping automagically?


There is two reasons I can think of, though of course I can't know if  
they are the real ones.


First, a technical reason: .method is handled as part of macro  
expansion:


user> (macroexpand-1 '(.hashCode 3))
(. 3 hashCode)

The result is a special form for Java interop. Symbols in non-operator  
positions are not macro-expanded, so some other mechanism would have  
to be invented to handle them in a special way. It would in fact  
create a first "special symbol" category, complicating the semantics  
of the language, so this is not just a technical reason.


Second, a semantic reason: Java method calls are resolved statically  
if possible (you can use reflection warnings to find out where this  
fails), making them very fast. Creating and calling a closure is a  
much slower operation. Rich has stated at several occasions that he  
considers performance in important part of the interface of a  
function, so making a clear syntactic distinction between a fast and a  
slow operation would fit well with that point of view.


Konrad.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Per Vognsen
On Fri, Mar 19, 2010 at 2:46 PM, Konrad Hinsen
 wrote:
> On 18 Mar 2010, at 16:55, Per Vognsen wrote:
>
>> Is there any reason why a .method occurrence in non-operator position
>> doesn't just do the closure wrapping automagically?
>
> There is two reasons I can think of, though of course I can't know if they
> are the real ones.
>
> First, a technical reason: .method is handled as part of macro expansion:
>
>        user> (macroexpand-1 '(.hashCode 3))
>        (. 3 hashCode)
>
> The result is a special form for Java interop. Symbols in non-operator
> positions are not macro-expanded, so some other mechanism would have to be
> invented to handle them in a special way. It would in fact create a first
> "special symbol" category, complicating the semantics of the language, so
> this is not just a technical reason.

Interesting. I had tacitly assumed there was already some "special
symbol" magic going on and so did not know it was a simple case of
macro expansion with a little reader support.

>
> Second, a semantic reason: Java method calls are resolved statically if
> possible (you can use reflection warnings to find out where this fails),
> making them very fast. Creating and calling a closure is a much slower
> operation. Rich has stated at several occasions that he considers
> performance in important part of the interface of a function, so making a
> clear syntactic distinction between a fast and a slow operation would fit
> well with that point of view.

I thought of this as well before posting. A few comments:

1. Creation: You only need to create one closure per function, once
and for all; the closure does not close over anything in the
surrounding scope, it's just a wrapper.
2. Calling: This is such a straightforward case of inlining that
HotSpot will eat it for breakfast. Clojure is full of idioms that
would be death to performance if not for such behavior from HotSpot.
3. Type hinting: This is a deeper problem with first-class methods.
The current manner of type hinting does not work well here. If you
could write SomeClass.someMethod to refer to a specific class's method
and perhaps supply further signature hints in the case of same-arity
overloads, e.g. #^([Integer]) ResultSet.getObject, then this could be
resolved.

-Per

> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to
> clojure+unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread LauJensen
Konrad,

Im not following where this would be a problem in terms of
optimization. In the definition for map,
all that needs to be added is a check for a symbol? and the resulting
sequence could look and act
exactly like it would, had you manually added the #(.method %) right?

If the technical obstacle can be overcome, which Im confident that it
can, then regarding semantics
this have come up several times, where people intuitively assume that
it works, which I completely
understand and think it should, so it wouldn't be adding a layer of
complexity.

Lau

On 19 Mar., 08:46, Konrad Hinsen  wrote:
> On 18 Mar 2010, at 16:55, Per Vognsen wrote:
>
> > Is there any reason why a .method occurrence in non-operator position
> > doesn't just do the closure wrapping automagically?
>
> There is two reasons I can think of, though of course I can't know if  
> they are the real ones.
>
> First, a technical reason: .method is handled as part of macro  
> expansion:
>
>         user> (macroexpand-1 '(.hashCode 3))
>         (. 3 hashCode)
>
> The result is a special form for Java interop. Symbols in non-operator  
> positions are not macro-expanded, so some other mechanism would have  
> to be invented to handle them in a special way. It would in fact  
> create a first "special symbol" category, complicating the semantics  
> of the language, so this is not just a technical reason.
>
> Second, a semantic reason: Java method calls are resolved statically  
> if possible (you can use reflection warnings to find out where this  
> fails), making them very fast. Creating and calling a closure is a  
> much slower operation. Rich has stated at several occasions that he  
> considers performance in important part of the interface of a  
> function, so making a clear syntactic distinction between a fast and a  
> slow operation would fit well with that point of view.
>
> Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Per Vognsen
I don't think passing symbols around and having special case behavior
scattered around different functions is going to help beginners. If
anything, it would confuse them when they try to treat .methods as
first-class functions in their own code and discover that it doesn't
work.

-Per

On Fri, Mar 19, 2010 at 3:10 PM, LauJensen  wrote:
> Konrad,
>
> Im not following where this would be a problem in terms of
> optimization. In the definition for map,
> all that needs to be added is a check for a symbol? and the resulting
> sequence could look and act
> exactly like it would, had you manually added the #(.method %) right?
>
> If the technical obstacle can be overcome, which Im confident that it
> can, then regarding semantics
> this have come up several times, where people intuitively assume that
> it works, which I completely
> understand and think it should, so it wouldn't be adding a layer of
> complexity.
>
> Lau
>
> On 19 Mar., 08:46, Konrad Hinsen  wrote:
>> On 18 Mar 2010, at 16:55, Per Vognsen wrote:
>>
>> > Is there any reason why a .method occurrence in non-operator position
>> > doesn't just do the closure wrapping automagically?
>>
>> There is two reasons I can think of, though of course I can't know if
>> they are the real ones.
>>
>> First, a technical reason: .method is handled as part of macro
>> expansion:
>>
>>         user> (macroexpand-1 '(.hashCode 3))
>>         (. 3 hashCode)
>>
>> The result is a special form for Java interop. Symbols in non-operator
>> positions are not macro-expanded, so some other mechanism would have
>> to be invented to handle them in a special way. It would in fact
>> create a first "special symbol" category, complicating the semantics
>> of the language, so this is not just a technical reason.
>>
>> Second, a semantic reason: Java method calls are resolved statically
>> if possible (you can use reflection warnings to find out where this
>> fails), making them very fast. Creating and calling a closure is a
>> much slower operation. Rich has stated at several occasions that he
>> considers performance in important part of the interface of a
>> function, so making a clear syntactic distinction between a fast and a
>> slow operation would fit well with that point of view.
>>
>> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Clojure 101 - Slime installation

2010-03-19 Thread LauJensen
To avoid confusion Im pasting from another thread:

Getting ready: 
http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-cloju...
Doing simple pages: 
http://www.bestinclass.dk/index.php/2009/12/beating-the-arc-challenge...
Including SQL: 
http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webde...
Making a simple Reddit clone:
http://www.bestinclass.dk/index.php/2010/02/reddit-clone-in-10-minute...
..and extending that with a user database:
http://www.bestinclass.dk/index.php/2010/02/reddit-clone-with-user-re...

I wrote them in a style which targets new-comers, so I hope it will
be
of some help.
Lau

On 18 Mar., 19:56, Tim Johnson  wrote:
> Seehttp://vimeo.com/8398020
> Great video!
>
> But, it would be great if I could capture the *text* of the video,
> (if available) that would be very helpful in referrencing Lau's
> instructions
>
> Anyone know how to do that?
>
> thanks
> --
> Tim
> t...@johnsons-web.comhttp://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Parser irritation

2010-03-19 Thread alux
Hello,

is this a bug or a feature? (And how could I know.)

spels=> (macroexpand `(huhu huhu.))
(spels/huhu huhu.)

If the symbol ends with a dot, it doesnt get resolved with name space.
I suspect thats because it will get special interpretation as Java
constructor. But what kind of magic is at work here?

Thank you, alux

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 2

2010-03-19 Thread alux
Hello Michael, hello Dave,

its actually been the parenthesis.

Thank you. (Now I still have to understand it ;-)

On 18 Mrz., 22:43, Michael Wood  wrote:
> On 18 March 2010 23:40, Dave M  wrote:
>
> > ...
>
> >> (game-action weld chain bucket attic
> >>          (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
> >                ^
> > Your if-condition is nested one form too deeply; try "(if (and (have
> > 'bucket) ...) ...)"
>
> > I haven't tried it, so there might be other problems.
>
> Oh right, yes, I didn't notice before your message that he had "(if
> ((and ..." in his game-action macro :)
>
> --
> Michael Wood 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Parser irritation

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 9:16 am, alux  wrote:

> is this a bug or a feature? (And how could I know.)
>
> spels=> (macroexpand `(huhu huhu.))
> (spels/huhu huhu.)
>
> If the symbol ends with a dot, it doesnt get resolved with name space.
> I suspect thats because it will get special interpretation as Java
> constructor. But what kind of magic is at work here?

This is exactly the case. The magic is `. It either expands the
classname to the full qualified version, if the class is exported. Or
it leaves it alone otherwise.

The reason is, that you can have a class frobnicator.Foo imported in
the namespace where you define your macro. However the user may use
your macro in a namespace which imports yoyodyne.Foo. If the Foo. in
your macro was left alone, it would now refer to yoyodyne.Foo instead
of the intended frobnicator.Foo.

If the class is not imported it must be by definition fully qualified.
And hence ` leaves the symbol with trailing . alone.

Note that something similar happens to the .method notation.

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Parser irritation

2010-03-19 Thread alux
Ah. Interesting.

(btw the "exported" in you second line certainly should be "imported")

So it interprets huhu. as full qualified class name and leaves it
alone.

Thank you for the explanation.

Regards, alux

On 19 Mrz., 09:38, Meikel Brandmeyer  wrote:
> Hi,
>
> On Mar 19, 9:16 am, alux  wrote:
>
> > is this a bug or a feature? (And how could I know.)
>
> > spels=> (macroexpand `(huhu huhu.))
> > (spels/huhu huhu.)
>
> > If the symbol ends with a dot, it doesnt get resolved with name space.
> > I suspect thats because it will get special interpretation as Java
> > constructor. But what kind of magic is at work here?
>
> This is exactly the case. The magic is `. It either expands the
> classname to the full qualified version, if the class is exported. Or
> it leaves it alone otherwise.
>
> The reason is, that you can have a class frobnicator.Foo imported in
> the namespace where you define your macro. However the user may use
> your macro in a namespace which imports yoyodyne.Foo. If the Foo. in
> your macro was left alone, it would now refer to yoyodyne.Foo instead
> of the intended frobnicator.Foo.
>
> If the class is not imported it must be by definition fully qualified.
> And hence ` leaves the symbol with trailing . alone.
>
> Note that something similar happens to the .method notation.
>
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 2

2010-03-19 Thread alux
By the way, you may find a working version at

http://paste.lisp.org/+22IH/1

Kind regards, alux

On 19 Mrz., 09:18, alux  wrote:
> Hello Michael, hello Dave,
>
> its actually been the parenthesis.
>
> Thank you. (Now I still have to understand it ;-)
>
> On 18 Mrz., 22:43, Michael Wood  wrote:
>
> > On 18 March 2010 23:40, Dave M  wrote:
>
> > > ...
>
> > >> (game-action weld chain bucket attic
> > >>          (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) 
> > >> (fn
> > >                ^
> > > Your if-condition is nested one form too deeply; try "(if (and (have
> > > 'bucket) ...) ...)"
>
> > > I haven't tried it, so there might be other problems.
>
> > Oh right, yes, I didn't notice before your message that he had "(if
> > ((and ..." in his game-action macro :)
>
> > --
> > Michael Wood 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clj-sandbox

2010-03-19 Thread Rayne
I'm ecstatic about this. I've been writing a Clojure IRC bot over the
last week or so, and this will really help me get sandboxed Clojure
evaluation working. Thanks.

On Mar 15, 5:22 am, Heinz Nikolaus Gies  wrote:
> My brain is a sive, I forgot the github link 
> o.Ohttp://github.com/Licenser/clj-sandboxsorry for the smap.
>
> Best regards,
> Heinz

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Parser irritation

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 9:49 am, alux  wrote:

> (btw the "exported" in you second line certainly should be "imported")

Woops. Yes. You are right. Should be "imported".

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


REPL behaviour / time / lazyness

2010-03-19 Thread alux
Hello,

I played a bit with Fibonacci again. The slow and inefficient way ;-)

(defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2)

user=> (time (fib0 35))
"Elapsed time: 20874.18345 msecs"
24157817

I use (set! *print-length* 10) and tried some mapping:

user=> (time (map fib0 (iterate inc 1)))
"Elapsed time: 0.913524 msecs"
(2 3 5 8 13 21 34 55 89 144 ...)

Everything fine.
Now what puzzles me:

user=> (time (map fib0 (range 100)))
"Elapsed time: 1.248203 msecs"

The time is printed "immediately", but the result waits about 8
seconds to print!

(1 2 3 5 8 13 21 34 55 89 ...)

Can you tell whats happening here? Especially comparing to the
(iterate inc 1) version ..

Thank you and regards, alux

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 11:27 am, alux  wrote:

> user=> (time (fib0 35))
> "Elapsed time: 20874.18345 msecs"
> 24157817
>
> user=> (time (map fib0 (iterate inc 1)))
> "Elapsed time: 0.913524 msecs"
> (2 3 5 8 13 21 34 55 89 144 ...)
>
> Everything fine.
> Now what puzzles me:
>
> user=> (time (map fib0 (range 100)))
> "Elapsed time: 1.248203 msecs"

As you write in your subject. You are caught by laziness. Wrap the map
in a doall.

(time (doall (map fib0 (iterate inc 1)))
(time (doall (map fib0 (range 100)))

(Don't forget to set print-length!)

What happens? The map returns not a list of sorts but an object, which
computes the result when it is requested. So it completes very fast,
hence the short time reported by the time call. Now outside the time
call the object is received by the Repl which triggers the suspended
computation and prints the result. So the actual work happens outside
the time call. On the other hand, wrapping the map into a doall will
realise the computation immediately (that is inside the time call) and
work will actually show up in form of a longer time reported by time.

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


getRuntime exec call?

2010-03-19 Thread TimDaly
(defn cmdresult [cmdstr]
  (let [args (into [] (seq (.split cmdstr " ")))]
  (BufferedReader.
(InputStreamReader.
  (. (. (. Runtime (getRuntime)) (exec args))
(getInputStream))

(defn readLine [cmdresult] (. cmdresult (readLine)))

(def a (cmdresult "ls *.o"))

This fails claiming:
No matching method found: exec for class java.lang.Runtime

If I replace the Runtime line with:
   (. (. (. Runtime (getRuntime)) (exec "ls")) (getInputStream))
it works and gives me the result of the "ls" system call.

If I replace the Runtime line with
  (. (. (. Runtime (getRuntime)) (exec "ls *.o"))
(getInputStream))
it fails even though it has a string argument.

Suggestions?

Tim Daly

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Instance predicates for deftyped types

2010-03-19 Thread Per Vognsen
It looks like there isn't a way to get at the class behind a deftyped
type other than constructing a dummy instance and taking its class,
because the generated class has a gensymmed name. I was doing
something where I needed to test when something was an instance of a
deftype, so I added this to the `(do ...) block in deftype's
implementation:

   (defn ~(symbol (str name "?")) [x#]
 (instance? ~classname x#))

It would also be nice if the class itself was exposed under some
standardized name, e.g. (symbol (str ~name "-class"))). Any reason
this isn't done right now?

-Per

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
You didnt try this, as I can judge, because you responded in finite
time ;-)

(fib0 35) takes 20 seconds already. So your suggestion

(time (doall (map fib0 (range 100)))

will do all up to 100, time it, and print the first ten, in that
order. (fib0 100) takes a good while (I just estimaded 15 million
years on my computer)

But, well, this one wont be that quick:

> (time (doall (map fib0 (iterate inc 1)))

;-)

My main irritation is still: Why do my range and my iterate version
differer in their print beheavior?

Greetings, alux

Meikel Brandmeyer schrieb:
> Hi,
>
> On Mar 19, 11:27 am, alux  wrote:
>
> > user=> (time (fib0 35))
> > "Elapsed time: 20874.18345 msecs"
> > 24157817
> >
> > user=> (time (map fib0 (iterate inc 1)))
> > "Elapsed time: 0.913524 msecs"
> > (2 3 5 8 13 21 34 55 89 144 ...)
> >
> > Everything fine.
> > Now what puzzles me:
> >
> > user=> (time (map fib0 (range 100)))
> > "Elapsed time: 1.248203 msecs"
>
> As you write in your subject. You are caught by laziness. Wrap the map
> in a doall.
>
> (time (doall (map fib0 (iterate inc 1)))
> (time (doall (map fib0 (range 100)))
>
> (Don't forget to set print-length!)
>
> What happens? The map returns not a list of sorts but an object, which
> computes the result when it is requested. So it completes very fast,
> hence the short time reported by the time call. Now outside the time
> call the object is received by the Repl which triggers the suspended
> computation and prints the result. So the actual work happens outside
> the time call. On the other hand, wrapping the map into a doall will
> realise the computation immediately (that is inside the time call) and
> work will actually show up in form of a longer time reported by time.
>
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread alux
The call to a static method is special, try

(.exec (Runtime/getRuntime) "ls")

Regards, alux

TimDaly schrieb:
> (defn cmdresult [cmdstr]
>   (let [args (into [] (seq (.split cmdstr " ")))]
>   (BufferedReader.
> (InputStreamReader.
>   (. (. (. Runtime (getRuntime)) (exec args))
> (getInputStream))
>
> (defn readLine [cmdresult] (. cmdresult (readLine)))
>
> (def a (cmdresult "ls *.o"))
>
> This fails claiming:
> No matching method found: exec for class java.lang.Runtime
>
> If I replace the Runtime line with:
>(. (. (. Runtime (getRuntime)) (exec "ls")) (getInputStream))
> it works and gives me the result of the "ls" system call.
>
> If I replace the Runtime line with
>   (. (. (. Runtime (getRuntime)) (exec "ls *.o"))
> (getInputStream))
> it fails even though it has a string argument.
>
> Suggestions?
>
> Tim Daly

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: web starting clojure apps without Java code

2010-03-19 Thread Eugen Dück
That would be great! Please post the link here when you're done.

On Mar 18, 5:15 pm, LauJensen  wrote:
> Eugen,
>
> Fantastic insight - I cant wait to work that into a blogpost :)
>
> Lau
>
> On 17 Mar., 15:56, Eugen Dück  wrote:
>
> > All,
>
> > Developing in clojure is a lot of fun, at least it was for me and a
> > project of mine - except for one thing: Deploying the app as Java Web
> > Start app, that took me a bit of time to figure out, and not only
> > because Java Web Start is broken in debian squeeze (for a workaround,
> > see bugs.debian.org/560056 ).
>
> > Java Web Start has been discussed in this group some time ago 
> > (http://groups.google.com/group/clojure/browse_thread/thread/f0c69735c...
> > ), and the proposed solution at that time contained one Java class
> > that did some static initialization (to propagate the necessary
> > permissions to clojure's own classloader) and then went on to call RT
> > to load a clj file, after fiddling around with PushBackReaders and so
> > forth.
>
> > I would like to stay away from RT, as it can change, and I don't want
> > to depend on RT staying the way it is. Now it turns out that Web Start
> > is actually pretty easy if you just AOT your whole app and gen-class
> > your main entry point. That way you don't need any Java code.
>
> > My clj file that contains the entry point starts like this:
>
> > (ns kanshiki.swing
> >   (:gen-class))
>
> > Then I compile the app and create the jar file:
> > mkdir classes
> > java -cp clojure.jar:clojure-contrib-slim.jar:classes:. clojure.main -
> > e "(compile 'kanshiki.swing)"
> > (cd classes; jar cf ../kanshiki-boom.jar *)
> > jarsigner kanshiki-boom.jar
>
> > And the jnlp contains these tags to make it work:
> > ...
> >   
> >     
> >     
> >     
> >   
> >   
> > ...
>
> > The complete jnlp can be found athttp://dueck.org/kanshiki-boom/.
>
> > I plan to introduce and document this beta-grade app soon, but if
> > there's any Japanese learner out there interested in or in need of
> > Kanji handwriting recognition, check it out, but please hold back with
> > any bug reports etc. until I have introduced it.
>
> > Only one quick note: Kanjis you click will automatically be copied to
> > the clipboard, so if you use it together with a kanji dictionary that
> > can search the clipboard like kiten (yes, that's the KDE kanji
> > dictionary with the hge memory leak, the other day it grew to 6GB
> > before I killed it), it is actually useful to look up kanjis or words.
>
> > Oh, and did I mention lately that clojure is pure fun? Thanks again
> > Rich! You've done (and are still doing) a terrific job!
>
> > Eugen

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure-mode-like syntax highlighting for the SLIME REPL

2010-03-19 Thread Rick Moynihan
On 19 March 2010 06:08, Michał Marczyk  wrote:
> Hi Group,
>
> there was a Stack Overflow question recently re: syntax highlighting
> Clojure REPLs. This got me thinking that since I was going to tweak
> SLIME REPL font-lock for quite some time now (I find the default a bit
> too aggressive), I might as well do it now and have it use
> clojure-mode's font-lock settings too.
>
> Here's what I came up with:
> http://gist.github.com/337280

Very cute!  I'd love to see this integrated into clojure-mode!

R.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 12:34 pm, alux  wrote:

> You didnt try this, as I can judge, because you responded in finite
> time ;-)

Ah, yes. Intersperse with (take 10 ...) at will. :)

> My main irritation is still: Why do my range and my iterate version
> differer in their print beheavior?

Because with range you get as first argument to fib0 a 0, while with
iterate you get a 1 as first parameter to fib0.

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
;-)

Still, I dont believe.

I get the same difference with

user=> (time (map fib0 (range 100)))
"Elapsed time: 1.916445 msecs"

more than 5 seconds

(0 1 1 2 3 5 8 13 21 34 ...)

user=> (time (map fib0 (iterate inc 0)))
"Elapsed time: 0.104203 msecs"
(0 1 1 2 3 5 8 13 21 34 ...)

Hm.

Regards, alux

Meikel Brandmeyer schrieb:
> Hi,
>
> On Mar 19, 12:34 pm, alux  wrote:
>
> > You didnt try this, as I can judge, because you responded in finite
> > time ;-)
>
> Ah, yes. Intersperse with (take 10 ...) at will. :)
>
> > My main irritation is still: Why do my range and my iterate version
> > differer in their print beheavior?
>
> Because with range you get as first argument to fib0 a 0, while with
> iterate you get a 1 as first parameter to fib0.
>
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Instance predicates for deftyped types

2010-03-19 Thread Konrad Hinsen
On 19.03.2010, at 12:09, Per Vognsen wrote:

> It looks like there isn't a way to get at the class behind a deftyped
> type other than constructing a dummy instance and taking its class,
> because the generated class has a gensymmed name. I was doing
> something where I needed to test when something was an instance of a
> deftype, so I added this to the `(do ...) block in deftype's
> implementation:

The official approach is to check for type rather than class, the type being 
the namespace-qualified keyword version of the type name. The class is 
considered an implementation detail. Considering that there is already an 
alternative implementation of Clojure (ClojureCLR) and that there might be more 
in the future, this is pretty reasonable in my opinion.

Here's an (untested) example:

(deftype Foo [bar])

(defn is-this-a-foo? [x]
  (identical? (type x) ::Foo))

Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Instance predicates for deftyped types

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 12:09 pm, Per Vognsen  wrote:

> It looks like there isn't a way to get at the class behind a deftyped
> type other than constructing a dummy instance and taking its class,
> because the generated class has a gensymmed name. I was doing
> something where I needed to test when something was an instance of a
> deftype, so I added this to the `(do ...) block in deftype's
> implementation:
>
>        (defn ~(symbol (str name "?")) [x#]
>          (instance? ~classname x#))
>
> It would also be nice if the class itself was exposed under some
> standardized name, e.g. (symbol (str ~name "-class"))). Any reason
> this isn't done right now?

I would not rely on "class" but on "type", which will return the type
tag of the type. Unfortunately the tag does currently not work with
"instance?".

(defn general-instance?
  [t o]
  (isa? (type o) t))

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Simple functional programming lexicon?

2010-03-19 Thread Michael A Wright
You might want to check out:

> http://peepcode.com/products/functional-programming-with-clojure



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Wrapping a java api...

2010-03-19 Thread Martin Hauner
Hi,

I'm trying to wrap the apfloat (arbitrary precision float,
http://www.apfloat.org/apfloat_java)
java library for a small project.

The idea is that the parameters of apfloat calculations get
automatically converted to the
Apfloat class.

My test function is sqrtf (square root float) and the automatic
conversion will allow me to
write (sqrtf 5) without converting the 5 to an Apfloat object first.

sqrtf uses a multimethod apf (apfloat) that takes care of the
conversion.

I wonder if this is the "correct" way of handling this in clojure or
if I'm off track here?


apfloat.clj:

(ns apfloat)

(import '(org.apfloat Apfloat Apint ApfloatMath))

(set! *warn-on-reflection* true)

; default precision
(def *precision* 20)

(def infinite Apfloat/INFINITE)


(declare apf)


(defn sqrtf [a]
  "sqrt of apfloat a"
  (ApfloatMath/sqrt (apf a)))


(defmulti apf
  "creates an Apfloat."
  class)

(defmethod apf Apfloat
  [#^Apfloat a] a)

(defmethod apf Apint
  [#^Apint a]
(if (= Apfloat/INFINITE (.precision a))
  (.precision a (long *precision*))
  a))

(defmethod apf Integer
  ([#^Integer a] (Apfloat. (.longValue a) (long *precision*


--
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


overrding function from other namespace

2010-03-19 Thread Martin Hauner
Hi,

I trying to use clojure.contrib.mock. It says to override the function
report-problem to
integrate it into other test framework like clojure.test.

I've got this working, but the namespace switching looks a bit ugly.
Is there a better
way to handle this? Maybe something like

(ns clojure.contrib.mock
  (defn... the override)
  )

which avoids the extra code to switch back to the original namespace?


(ns apfloattest
  (:use
apfloat
clojure.test
clojure.contrib.mock))


(ns clojure.contrib.mock
  (:use
clojure.test))

; delegate mock reporting to clojure.test
  (defn report-problem
([function expected actual message]
  (is (= expected actual)
(str message " Function name: " function

(ns apfloattest)


(deftest test-sqrtf
  (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5)))

--
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Quines

2010-03-19 Thread yubeshi
Ok, I golfed it.
(def s["(def s%s)(printf(s 0)s)"])(printf(s 0)s)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Simple functional programming lexicon?

2010-03-19 Thread Michael Richter
>
> Also the "Learn you a Haskell for Great Good" tutorial is a pretty
> nice and light-hearted introduction to FP with Haskell which might
> also help you to understand some of the concepts better:
>
> http://learnyouahaskell.com/



If you don't mind taking a detour into the Haskell world, the book Real
World Haskell also does a very good job of explaining key functional
vocabulary using pragmatic examples (for the most part).  I may never use
Haskell in anger, but I found learning the language and reading this one
book a very good exploration of the functional programming space.

-- 
"Perhaps people don't believe this, but throughout all of the discussions of
entering China our focus has really been what's best for the Chinese people.
It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Name suggestions

2010-03-19 Thread Frank Hale
clojure + native = clotive

On Thu, Mar 18, 2010 at 10:36 AM, Alexandre Patry
 wrote:
>
>>> On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:
>>>

 After just a little more test and polish I plan on calling clj-native
 1.0. But clj-native is a *really* boring name so I want to change it
 before 1.0 and I don't have very good imagination when it comes to
 these things.
 So I need your help.
 It doesn't have to have anything to do with anything, could just be
 something that sounds funny, like sasquatch, that's a funny word.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Clojure Koans?

2010-03-19 Thread Timothy McGuire
On a recent Java Ranch, Dick Wall mentioned that he was working with Clojure
and F# people on functional language Koans that are like the Ruby Koans
at http://github.com/relevance/functional-koans/

the branch for clojure is:
at http://github.com/relevance/functional-koans/tree/clojure

There are 9 koans so far, with the last contributions some time in February.



On Wed, Dec 2, 2009 at 2:39 PM, Matthew Williams <
matthew.d.willi...@gmail.com> wrote:

> The folks over at http://edgecase.com put together a great project for
> people interested in Ruby to really get a grasp of the standard
> library as well as introduce them to the idea of unit testing.  The
> project is up on Github: http://github.com/edgecase/ruby_koans
>
> The basic idea is you run Rake which then guides you through exercises
> taking you throughout almost the entire standard library.  For
> example, a problem might look like the following:
>
> def test_double_quoted_strings_are_strings
>  string = "Hello, World"
>  assert_equal __, string.is_a?(String)
> end
>
> The __ represents the expected the result of the second argument on
> assert_equal.  Once you fill in the correct answer, run rake, and it
> will guide you to the next set of koans.  They exercise almost every
> method for the major data types, blocks, exceptions, etc etc.
>
> It's a really great project.
>
> Could something like this come from the Clojure community?  I've just
> started Stuart's Clojure PragProg book and I'm finding it to be a
> great resource.  But I'm also finding myself struggling a bit on a few
> items that might have a single example or a brief explanation and then
> I'm off searching through docs and trying to come up with some
> practical examples on my own that really drill down how the given form
> should be used, or how recur works, or let, do, etc etc.
>
> Would this be something worth while, especially for those joining the
> community?  I discovered the Ruby Koans with a few years of Ruby under
> my belt and found them to be a really refreshing set of exercises.
> And now that I'm entering a new community, it's something I think I
> would benefit from greatly.
>
> Does anyone have any input on how best to accomplish this?  Or even
> some starter koans?
>
> On a side note, it's been really refreshing working with Clojure.  I
> haven't yet begun implementing anything other than what I'm finding in
> example material, but I'm getting there.  Having been doing OOP for
> such a long time, I'm still slowly taking in the functional approach
> and I'm seeing more and more benefits as the days go by.
>
> Thanks for being such an great community!
>
> -Matthew Williams
> @mwilliams
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Long post with some questions about getting started...

2010-03-19 Thread Nick
I want to learn Clojure and the first idea for a "simple" app that
popped into my head was some sort of roguelike (because I'm a gamer
and this is what I like to do...)  I could go on making hello world
apps and tiny test apps that serve little purpose, but the way I learn
is by setting an end goal and going for it.  I don't intend on making
this in the first shot, but like I said, there's the goal.

I've read quite a bit on Clojure, done some simple stuff like the
"Hello World" apps and such already.  I get the idea of the list
structure (though I'm still VERY green on this.)

A little background: I have an extensive background (10+ years
professional, many more non-pro) in OOP and Procedural Programing
using everything from Javascript/Actionscript to C# and even the gross
VB4-6 in my early years and a little known Aspect Scripting (which
I've totally forgotten by now.)  I've only really dealt with threaded
applications in C# because, let's face it... it's dead simple even
using mutex locking.  Non-professionally I started on an old TRS-80
then moved to a 80386 with GWBASIC/QBASIC and dabbled in C/C++ (but
mainly I've just read tons of books on C/C++...)

So, I'm trying to put all that aside and think Functional for this.
I'm really trying, and it's mind bending to put all that aside... but
I learn by example so here's where I ask some clues.

I've downloaded Netbeans and an addon and played with it a little bit,
but it seems to require a _main entry method and from the various
tutorials around, I see that's not the norm.

I'm having an interesting (to me) question around a using REPL.  Once
it's shut down, where does this code go?  I feel like I'm in the old
TRS-80 volatile coding days where you write some code, and if you shut
down you've lost it all.  Is this the case?  So how do you save your
code in a REPL?  I understand these could be unique per editor so I
understand if you get irate at me for asking such a silly question...

I understand a list from ( to ) has the potential to be a function in
separate threads because I poked my head into a tutorial I should have
probably stayed clear of.  If I create a function that I want to
execute first on start up to check for a file and load it, but if it
doesn't exist, create it and populate some array for world data.
That's fairly straight forward, but in a game environment, this gets
you nowhere but RAM full of data.  About this point I'd then call a
function create a player that would read in data from this world
within a local proximity and act upon it.  There's two ways I can see
going about this.  One is threading it off to act on it's own (which
is what I'd love to do) and the other is appending it to the end of
this creation function (have that function call the player on
completion) but this is where I'm lost.  Is it as simple as calling
said method at the end of the list or is that filling up a stack of
pain that I don't want to deal with when it all crashes?

So I thought, I just need to do it.  Just put it to silicon and start
making something then I stared at the screen...

A part of me would approach this as a client/server model which I'm
not certain is right for functional programming.  You have to have
some communication method, or is the "world data" stored in a global
location that is accessible to this player?  Am I thinking about this
all wrong?  Would the player spawn the world load/creation only when
it was needed?  What if you wanted more than one actor? (would be a
boring game if there were no enemies...)  How does each actor access
this world data?

I realize some of this sounds totally noobish.  Forgive me, but this
is new territory for me.  With OOP and functional languages I could
scope a simple array of an array and reference it within it's scope.
Is all Clojure scoped globally for data or am I supposed to go find
something to handle that?  I would figure with the nature of
functional programming I could have it store data in a simple file
format for the time being.  That might not scale well, or it just
may.  I don't know.

Sorry for the length of this post, the rambling, and the incoherent
thought process.  I realize I'm probably asking too many questions at
once... :-\

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


ANN: clj-facebook, a Clojure client library for Facebook apps

2010-03-19 Thread Don Jackson

I'd like to announce the initial release of clj-facebook, a Facebook client 
library in Clojure.

The code can be found here:

http://github.com/rnewman/clj-facebook

We welcome comments and proposed code improvements.

Don

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 2

2010-03-19 Thread JC Petkovich
You just needed to edit your translation from CL a bit more, there
were some extra brackets in your if statements. The following should
work:

(defspel game-action [command subj obj place & rest]
  `(defspel ~command [subject# object#]
 `(if (and (= *location* '~'~place)
   (= '~subject# '~'~subj)
   (= '~object# '~'~obj)
   (have '~'~subj))
~@'~rest
'(i cant ~'~command like that.

(game-action weld chain bucket attic
 (if (and (have 'bucket) (alter-var-root (var
*chain-welded*) (fn [_] true)))
   '(the chain is now securely welded to the bucket.)
   '(you do not have a bucket.)))

On Thu, Mar 18, 2010 at 4:38 PM, alux  wrote:
> Again, from my translation of the http://www.lisperati.com/casting.html
> tutorial.
>
> I completely lost track at the macro generating macro (defspel game-
> action ..
>
> In short, Barski writes a very simple (and neat) text adventure. To
> avoid wrong assumtions he doesnt talk about macros but SPELs, using
>
> CL (defmacro defspel (&rest rest) `(defmacro ,@rest))
> Clj (defmacro defspel [& rest] `(defmacro ~...@rest))
>
> I translated everything up to the last page 
> http://www.lisperati.com/actions.html,
> then he arrives at
>
> (defspel game-action (command subj obj place &rest rest)
>  `(defspel ,command (subject object)
>     `(cond ((and (eq *location* ',',place)
>                  (eq ',subject ',',subj)
>                  (eq ',object ',',obj)
>                  (have ',',subj))
>             ,@',rest)
>            (t '(i cant ,',command like that.)
>
> Without CL knowledge, I dont really understand whats going on, but
> gave a try (please dont lough to hard :)
>
> (defspel game-action [command subj obj place & rest]
>  `(defspel ~command [subject# object#]
>     `(if ((and (= *location* '~'~place)
>                  (= '~subject# '~'~subj)
>                  (= '~object# '~'~obj)
>                  (have '~'~subj))
>             ~@'~rest)
>            '(i cant ~'~command like that.
>
> use
>
> (game-action weld chain bucket attic
>         (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
> [_] true)))
>                   '(the chain is now securely welded to the bucket.))
>                   '(you do not have a bucket.)))
>
> If I try it, I get
>
> spels=> (weld chain bucket)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.I
> Fn (NO_SOURCE_FILE:0)
>
> And I'm stuck.
>
> My whole try is here: http://paste.lisp.org/+22IH
>
> Many thanks and a good night.
>
> alux
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


zipentry-seq based on clojure.core/resultset-seq

2010-03-19 Thread MakotoSatoh
Hi,

I want a function that takes byte array in zip format and returns
sequence of included ZipEntrys.

I wrote zipentry-seq based on clojure.core/resultset-seq as below.

(entries) returns sequence of included ZipEntrys and many nils, so I
added ad-hoc filter at the last.

Please advice me to make it more better.


(defn zipentry-seq
  [zip-byte-array]
  (let [zip-stream (ZipInputStream. (ByteArrayInputStream. zip-byte-
array))
entries (fn thisfn []
  (when (not= 0 (.available zip-stream))
(cons (.getNextEntry zip-stream) (lazy-seq
(thisfn)]
(filter #(not (nil? %)) (entries


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


ANN: clj-facebook, a Clojure client library for Facebook apps

2010-03-19 Thread Don Jackson
I'd like to announce the initial release of clj-facebook, a Facebook client
library in Clojure.

The code can be found here:

http://github.com/rnewman/clj-facebook

We welcome comments and proposed code improvements.

Don

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


How to use Clojure with Robocode

2010-03-19 Thread ubolonton
Hi,

Has anyone been able to use Clojure with Robocode?
I've followed this http://www.fatvat.co.uk/2009/05/clojure-and-robocode.html
but got the error

Round 1 initializing..
Let the games begin!
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at
net.sf.robocode.host.security.RobotClassLoader.createRobotInstance(RobotClassLoader.java:
272)
at
net.sf.robocode.host.proxies.HostingRobotProxy.loadRobotRound(HostingRobotProxy.java:
201)
at
net.sf.robocode.host.proxies.HostingRobotProxy.run(HostingRobotProxy.java:
242)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.NullPointerException
at clojure.lang.Var.setMeta(Var.java:179)
at clojure.lang.Var.internPrivate(Var.java:96)
at ubolonton.MyRobot.(Unknown Source)
... 10 more

Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Instance predicates for deftyped types

2010-03-19 Thread Per Vognsen
Thanks, I had seen that ::Foo use and was a bit confused. Now it all
makes sense.

It would still be nice to have an auto-generated name?-style predicate
in deftype, I think.

-Per

On Fri, Mar 19, 2010 at 7:44 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> On Mar 19, 12:09 pm, Per Vognsen  wrote:
>
>> It looks like there isn't a way to get at the class behind a deftyped
>> type other than constructing a dummy instance and taking its class,
>> because the generated class has a gensymmed name. I was doing
>> something where I needed to test when something was an instance of a
>> deftype, so I added this to the `(do ...) block in deftype's
>> implementation:
>>
>>        (defn ~(symbol (str name "?")) [x#]
>>          (instance? ~classname x#))
>>
>> It would also be nice if the class itself was exposed under some
>> standardized name, e.g. (symbol (str ~name "-class"))). Any reason
>> this isn't done right now?
>
> I would not rely on "class" but on "type", which will return the type
> tag of the type. Unfortunately the tag does currently not work with
> "instance?".
>
> (defn general-instance?
>  [t o]
>  (isa? (type o) t))
>
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
2010/3/19 alux :
> ;-)
>
> Still, I dont believe.
>
> I get the same difference with
>
> user=> (time (map fib0 (range 100)))
> "Elapsed time: 1.916445 msecs"
>
> more than 5 seconds
>
> (0 1 1 2 3 5 8 13 21 34 ...)
>
> user=> (time (map fib0 (iterate inc 0)))
> "Elapsed time: 0.104203 msecs"
> (0 1 1 2 3 5 8 13 21 34 ...)
>
> Hm.
>
> Regards, alux

Could chunked seqs explain something here ?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Mar 19, 1:39 pm, alux  wrote:

> Still, I dont believe.

You should...

>
> I get the same difference with
>
> user=> (time (map fib0 (range 100)))
> "Elapsed time: 1.916445 msecs"
>
> more than 5 seconds
>
> (0 1 1 2 3 5 8 13 21 34 ...)
>
> user=> (time (map fib0 (iterate inc 0)))
> "Elapsed time: 0.104203 msecs"
> (0 1 1 2 3 5 8 13 21 34 ...)

How does this fit to following?

> user=> (time (map fib0 (iterate inc 1)))
> "Elapsed time: 0.913524 msecs"
> (2 3 5 8 13 21 34 55 89 144 ...)
  ^^^

The example you posted can't be. With the fib0 you posted you get:

(fib0 0) => 1
(fib0 1) => (+ (fib0 0) (fib0 -1)) => (+ 1 1) => 2

So what you posted above can't be true. At least not with the fib0 you
gave in your original post.

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Instance predicates for deftyped types

2010-03-19 Thread Konrad Hinsen
On 19.03.2010, at 13:50, Per Vognsen wrote:

> It would still be nice to have an auto-generated name?-style predicate
> in deftype, I think.

I haven't yet made my mind up about this. I have used such auto-generated 
predicates in my unit library (http://code.google.com/p/clj-units/) for 
dimension testing, but I may take them out again. What I dislike about this 
approach is def-ing a symbol inside a macro that is not spelled out explicitly 
by the user of that macro. This can easily cause namespace pollution of 
invisible origin.

Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 2

2010-03-19 Thread alux

JC Petkovich, thank you. I couldnt see your message before March 19,
6:00 group time, i.e. 13:00 UTC, but thats exactly the solution that
was needed.

Regards, alux

JC Petkovich schrieb:
> You just needed to edit your translation from CL a bit more, there
> were some extra brackets in your if statements. The following should
> work:
>
> (defspel game-action [command subj obj place & rest]
>   `(defspel ~command [subject# object#]
>  `(if (and (= *location* '~'~place)
>(= '~subject# '~'~subj)
>(= '~object# '~'~obj)
>(have '~'~subj))
> ~@'~rest
> '(i cant ~'~command like that.
>
> (game-action weld chain bucket attic
>  (if (and (have 'bucket) (alter-var-root (var
> *chain-welded*) (fn [_] true)))
>'(the chain is now securely welded to the bucket.)
>'(you do not have a bucket.)))
>
> On Thu, Mar 18, 2010 at 4:38 PM, alux  wrote:
> > Again, from my translation of the http://www.lisperati.com/casting.html
> > tutorial.
> >
> > I completely lost track at the macro generating macro (defspel game-
> > action ..
> >
> > In short, Barski writes a very simple (and neat) text adventure. To
> > avoid wrong assumtions he doesnt talk about macros but SPELs, using
> >
> > CL (defmacro defspel (&rest rest) `(defmacro ,@rest))
> > Clj (defmacro defspel [& rest] `(defmacro ~...@rest))
> >
> > I translated everything up to the last page 
> > http://www.lisperati.com/actions.html,
> > then he arrives at
> >
> > (defspel game-action (command subj obj place &rest rest)
> >  `(defspel ,command (subject object)
> >     `(cond ((and (eq *location* ',',place)
> >                  (eq ',subject ',',subj)
> >                  (eq ',object ',',obj)
> >                  (have ',',subj))
> >             ,@',rest)
> >            (t '(i cant ,',command like that.)
> >
> > Without CL knowledge, I dont really understand whats going on, but
> > gave a try (please dont lough to hard :)
> >
> > (defspel game-action [command subj obj place & rest]
> >  `(defspel ~command [subject# object#]
> >     `(if ((and (= *location* '~'~place)
> >                  (= '~subject# '~'~subj)
> >                  (= '~object# '~'~obj)
> >                  (have '~'~subj))
> >             ~@'~rest)
> >            '(i cant ~'~command like that.
> >
> > use
> >
> > (game-action weld chain bucket attic
> >         (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
> > [_] true)))
> >                   '(the chain is now securely welded to the bucket.))
> >                   '(you do not have a bucket.)))
> >
> > If I try it, I get
> >
> > spels=> (weld chain bucket)
> > java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> > clojure.lang.I
> > Fn (NO_SOURCE_FILE:0)
> >
> > And I'm stuck.
> >
> > My whole try is here: http://paste.lisp.org/+22IH
> >
> > Many thanks and a good night.
> >
> > alux
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> >
> > To unsubscribe from this group, send email to 
> > clojure+unsubscribegooglegroups.com or reply to this email with the words 
> > "REMOVE ME" as the subject.
> >

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Laurent PETIT
Where would you place the type hint needed to avoid reflection ?

2010/3/19 LauJensen :
> Konrad,
>
> Im not following where this would be a problem in terms of
> optimization. In the definition for map,
> all that needs to be added is a check for a symbol? and the resulting
> sequence could look and act
> exactly like it would, had you manually added the #(.method %) right?
>
> If the technical obstacle can be overcome, which Im confident that it
> can, then regarding semantics
> this have come up several times, where people intuitively assume that
> it works, which I completely
> understand and think it should, so it wouldn't be adding a layer of
> complexity.
>
> Lau
>
> On 19 Mar., 08:46, Konrad Hinsen  wrote:
>> On 18 Mar 2010, at 16:55, Per Vognsen wrote:
>>
>> > Is there any reason why a .method occurrence in non-operator position
>> > doesn't just do the closure wrapping automagically?
>>
>> There is two reasons I can think of, though of course I can't know if
>> they are the real ones.
>>
>> First, a technical reason: .method is handled as part of macro
>> expansion:
>>
>>         user> (macroexpand-1 '(.hashCode 3))
>>         (. 3 hashCode)
>>
>> The result is a special form for Java interop. Symbols in non-operator
>> positions are not macro-expanded, so some other mechanism would have
>> to be invented to handle them in a special way. It would in fact
>> create a first "special symbol" category, complicating the semantics
>> of the language, so this is not just a technical reason.
>>
>> Second, a semantic reason: Java method calls are resolved statically
>> if possible (you can use reflection warnings to find out where this
>> fails), making them very fast. Creating and calling a closure is a
>> much slower operation. Rich has stated at several occasions that he
>> considers performance in important part of the interface of a
>> function, so making a clear syntactic distinction between a fast and a
>> slow operation would fit well with that point of view.
>>
>> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Instance predicates for deftyped types

2010-03-19 Thread Per Vognsen
It's pretty common in the Lisp world at large. For example, Common
Lisp's (defstruct foo ...) automatically defines a foo-p predicate.

-Per

On Fri, Mar 19, 2010 at 7:53 PM, Konrad Hinsen
 wrote:
> On 19.03.2010, at 13:50, Per Vognsen wrote:
>
>> It would still be nice to have an auto-generated name?-style predicate
>> in deftype, I think.
>
> I haven't yet made my mind up about this. I have used such auto-generated 
> predicates in my unit library (http://code.google.com/p/clj-units/) for 
> dimension testing, but I may take them out again. What I dislike about this 
> approach is def-ing a symbol inside a macro that is not spelled out 
> explicitly by the user of that macro. This can easily cause namespace 
> pollution of invisible origin.
>
> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Meikel,

you are right, I changed horses, uh, definitions inbetween. So the
REPL interaction of my last response should read

Clojure 1.1.0
user=> (set! *print-length* 10)
10
user=> (defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n
2)
#'user/fib0
user=> (time (map fib0 (range 100)))
"Elapsed time: 1.979022 msecs"
(1 2 3 5 8 13 21 34 55 89 ...)
user=> (time (map fib0 (iterate inc 0)))
"Elapsed time: 0.969677 msecs"
(1 2 3 5 8 13 21 34 55 89 ...)
user=>

Despite this, the text I wrote seems still valid to me; note that I
changed the start point for the iterate as response to your mail.
Thats why now both starts with 0 as argument, and 1 as result. But the
range one waits some five sec, the iterate doesnt.

Sorry for the confusion. And thanks for the patience ;-)

Kind regards, alux

PS.: A correct Fibonacci sequence would use (< n 2) instead of (< n
1). Just to mention it.

Meikel Brandmeyer schrieb:
> Hi,
>
> On Mar 19, 1:39 pm, alux  wrote:
>
> > Still, I dont believe.
>
> You should...
>
> >
> > I get the same difference with
> >
> > user=> (time (map fib0 (range 100)))
> > "Elapsed time: 1.916445 msecs"
> >
> > more than 5 seconds
> >
> > (0 1 1 2 3 5 8 13 21 34 ...)
> >
> > user=> (time (map fib0 (iterate inc 0)))
> > "Elapsed time: 0.104203 msecs"
> > (0 1 1 2 3 5 8 13 21 34 ...)
>
> How does this fit to following?
>
> > user=> (time (map fib0 (iterate inc 1)))
> > "Elapsed time: 0.913524 msecs"
> > (2 3 5 8 13 21 34 55 89 144 ...)
>   ^^^
>
> The example you posted can't be. With the fib0 you posted you get:
>
> (fib0 0) => 1
> (fib0 1) => (+ (fib0 0) (fib0 -1)) => (+ 1 1) => 2
>
> So what you posted above can't be true. At least not with the fib0 you
> gave in your original post.
>
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Name suggestions

2010-03-19 Thread Alexandre Patry

Frank Hale wrote:

clojure + native = clotive
  

or clo-jive, like clojure dancing with another language.

Alex

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Translation from Common Lisp 2

2010-03-19 Thread Conrad
Yeah, the Clojure namespacing does make translating symbol references
in my game-action macro a bit cumbersome... But I think Clojure's
straight-forward approach to namespacing is well worth this small
inconvenience :-)

On Mar 19, 8:54 am, alux  wrote:
> JC Petkovich, thank you. I couldnt see your message before March 19,
> 6:00 group time, i.e. 13:00 UTC, but thats exactly the solution that
> was needed.
>
> Regards, alux
>
> JC Petkovich schrieb:
>
>
>
> > You just needed to edit your translation from CL a bit more, there
> > were some extra brackets in your if statements. The following should
> > work:
>
> > (defspel game-action [command subj obj place & rest]
> >   `(defspel ~command [subject# object#]
> >      `(if (and (= *location* '~'~place)
> >                (= '~subject# '~'~subj)
> >                (= '~object# '~'~obj)
> >                (have '~'~subj))
> >         ~@'~rest
> >         '(i cant ~'~command like that.
>
> > (game-action weld chain bucket attic
> >              (if (and (have 'bucket) (alter-var-root (var
> > *chain-welded*) (fn [_] true)))
> >                '(the chain is now securely welded to the bucket.)
> >                '(you do not have a bucket.)))
>
> > On Thu, Mar 18, 2010 at 4:38 PM, alux  wrote:
> > > Again, from my translation of thehttp://www.lisperati.com/casting.html
> > > tutorial.
>
> > > I completely lost track at the macro generating macro (defspel game-
> > > action ..
>
> > > In short, Barski writes a very simple (and neat) text adventure. To
> > > avoid wrong assumtions he doesnt talk about macros but SPELs, using
>
> > > CL (defmacro defspel (&rest rest) `(defmacro ,@rest))
> > > Clj (defmacro defspel [& rest] `(defmacro ~...@rest))
>
> > > I translated everything up to the last 
> > > pagehttp://www.lisperati.com/actions.html,
> > > then he arrives at
>
> > > (defspel game-action (command subj obj place &rest rest)
> > >  `(defspel ,command (subject object)
> > >     `(cond ((and (eq *location* ',',place)
> > >                  (eq ',subject ',',subj)
> > >                  (eq ',object ',',obj)
> > >                  (have ',',subj))
> > >             ,@',rest)
> > >            (t '(i cant ,',command like that.)
>
> > > Without CL knowledge, I dont really understand whats going on, but
> > > gave a try (please dont lough to hard :)
>
> > > (defspel game-action [command subj obj place & rest]
> > >  `(defspel ~command [subject# object#]
> > >     `(if ((and (= *location* '~'~place)
> > >                  (= '~subject# '~'~subj)
> > >                  (= '~object# '~'~obj)
> > >                  (have '~'~subj))
> > >             ~@'~rest)
> > >            '(i cant ~'~command like that.
>
> > > use
>
> > > (game-action weld chain bucket attic
> > >         (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
> > > [_] true)))
> > >                   '(the chain is now securely welded to the bucket.))
> > >                   '(you do not have a bucket.)))
>
> > > If I try it, I get
>
> > > spels=> (weld chain bucket)
> > > java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> > > clojure.lang.I
> > > Fn (NO_SOURCE_FILE:0)
>
> > > And I'm stuck.
>
> > > My whole try is here:http://paste.lisp.org/+22IH
>
> > > Many thanks and a good night.
>
> > > alux
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to clojure@googlegroups.com
> > > Note that posts from new members are moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en
>
> > > To unsubscribe from this group, send email to 
> > > clojure+unsubscribegooglegroups.com or reply to this email with the words 
> > > "REMOVE ME" as the subject.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: How to use Clojure with Robocode

2010-03-19 Thread Jeff Foster
Could you post the source code?

On Mar 19, 7:56 am, ubolonton  wrote:
> Hi,
>
> Has anyone been able to use Clojure with Robocode?
> I've followed thishttp://www.fatvat.co.uk/2009/05/clojure-and-robocode.html
> but got the error
>
> Round 1 initializing..
> Let the games begin!
> java.lang.ExceptionInInitializerError
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>         at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAcce 
> ssorImpl.java:
> 39)
>         at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstru 
> ctorAccessorImpl.java:
> 27)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>         at java.lang.Class.newInstance0(Class.java:355)
>         at java.lang.Class.newInstance(Class.java:308)
>         at
> net.sf.robocode.host.security.RobotClassLoader.createRobotInstance(RobotCla 
> ssLoader.java:
> 272)
>         at
> net.sf.robocode.host.proxies.HostingRobotProxy.loadRobotRound(HostingRobotP 
> roxy.java:
> 201)
>         at
> net.sf.robocode.host.proxies.HostingRobotProxy.run(HostingRobotProxy.java:
> 242)
>         at java.lang.Thread.run(Thread.java:637)
> Caused by: java.lang.NullPointerException
>         at clojure.lang.Var.setMeta(Var.java:179)
>         at clojure.lang.Var.internPrivate(Var.java:96)
>         at ubolonton.MyRobot.(Unknown Source)
>         ... 10 more
>
> Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Chouser
On Fri, Mar 19, 2010 at 4:04 AM, Per Vognsen  wrote:
> On Fri, Mar 19, 2010 at 2:46 PM, Konrad Hinsen
>  wrote:
>> On 18 Mar 2010, at 16:55, Per Vognsen wrote:
>>
>>> Is there any reason why a .method occurrence in non-operator position
>>> doesn't just do the closure wrapping automagically?
>>
>> There is two reasons I can think of, though of course I can't know if they
>> are the real ones.
>>
>> First, a technical reason: .method is handled as part of macro expansion:
>>
>>        user> (macroexpand-1 '(.hashCode 3))
>>        (. 3 hashCode)
>>
>> The result is a special form for Java interop. Symbols in non-operator
>> positions are not macro-expanded, so some other mechanism would have to be
>> invented to handle them in a special way. It would in fact create a first
>> "special symbol" category, complicating the semantics of the language, so
>> this is not just a technical reason.
>
> Interesting. I had tacitly assumed there was already some "special
> symbol" magic going on and so did not know it was a simple case of
> macro expansion with a little reader support.
>
>>
>> Second, a semantic reason: Java method calls are resolved statically if
>> possible (you can use reflection warnings to find out where this fails),
>> making them very fast. Creating and calling a closure is a much slower
>> operation. Rich has stated at several occasions that he considers
>> performance in important part of the interface of a function, so making a
>> clear syntactic distinction between a fast and a slow operation would fit
>> well with that point of view.
>
> I thought of this as well before posting. A few comments:
>
> 1. Creation: You only need to create one closure per function, once
> and for all; the closure does not close over anything in the
> surrounding scope, it's just a wrapper.
> 2. Calling: This is such a straightforward case of inlining that
> HotSpot will eat it for breakfast. Clojure is full of idioms that
> would be death to performance if not for such behavior from HotSpot.
> 3. Type hinting: This is a deeper problem with first-class methods.
> The current manner of type hinting does not work well here. If you
> could write SomeClass.someMethod to refer to a specific class's method
> and perhaps supply further signature hints in the case of same-arity
> overloads, e.g. #^([Integer]) ResultSet.getObject, then this could be
> resolved.

This has been discussed some, including alternate hinting
syntaxes not entirely unlike what you suggest:

http://clojure-log.n01se.net/date/2010-01-21.html#08:34

--Chouser
http://joyofclojure.com/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Laurent,

> Could chunked seqs explain something here ?

sounds possible. If I only knew what this is ;-)

Regards, alux

Laurent PETIT schrieb:
> 2010/3/19 alux :
> > ;-)
> >
> > Still, I dont believe.
> >
> > I get the same difference with
> >
> > user=> (time (map fib0 (range 100)))
> > "Elapsed time: 1.916445 msecs"
> >
> > more than 5 seconds
> >
> > (0 1 1 2 3 5 8 13 21 34 ...)
> >
> > user=> (time (map fib0 (iterate inc 0)))
> > "Elapsed time: 0.104203 msecs"
> > (0 1 1 2 3 5 8 13 21 34 ...)
> >
> > Hm.
> >
> > Regards, alux
>
> Could chunked seqs explain something here ?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
Yes, chunked sequences explain the behaviour, look:

1:1 user=> (set! *print-length* 10)
10
1:2 user=> (defn fib0
  [n]
  (let [fib (fn fib [n] (if (< n 1) 1 (+ (fib (- n 1)) (fib (- n 2)]
(println (str "fib0[" n "]"))
(fib n)))
#'user/fib0
1:7 user=> (time (map fib0 (iterate inc 0)))
"Elapsed time: 0.294021 msecs"
(fib0[0]
fib0[1]
1 fib0[2]
2 fib0[3]
3 fib0[4]
5 fib0[5]
8 fib0[6]
13 fib0[7]
21 fib0[8]
34 fib0[9]
55 fib0[10]
89 fib0[11]
...)
1:8 user=> (time (map fib0 (range 100)))
"Elapsed time: 0.881059 msecs"
(fib0[0]
fib0[1]
fib0[2]
fib0[3]
fib0[4]
fib0[5]
fib0[6]
fib0[7]
fib0[8]
fib0[9]
fib0[10]
fib0[11]
fib0[12]
fib0[13]
fib0[14]
fib0[15]
fib0[16]
fib0[17]
fib0[18]
fib0[19]
fib0[20]
fib0[21]
fib0[22]
fib0[23]
fib0[24]
fib0[25]
fib0[26]
fib0[27]
fib0[28]
fib0[29]
fib0[30]
fib0[31]
1 2 3 5 8 13 21 34 55 89 ...)
1:9 user=>


2010/3/19 alux :
> Meikel,
>
> you are right, I changed horses, uh, definitions inbetween. So the
> REPL interaction of my last response should read
>
> Clojure 1.1.0
> user=> (set! *print-length* 10)
> 10
> user=> (defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n
> 2)
> #'user/fib0
> user=> (time (map fib0 (range 100)))
> "Elapsed time: 1.979022 msecs"
> (1 2 3 5 8 13 21 34 55 89 ...)
> user=> (time (map fib0 (iterate inc 0)))
> "Elapsed time: 0.969677 msecs"
> (1 2 3 5 8 13 21 34 55 89 ...)
> user=>
>
> Despite this, the text I wrote seems still valid to me; note that I
> changed the start point for the iterate as response to your mail.
> Thats why now both starts with 0 as argument, and 1 as result. But the
> range one waits some five sec, the iterate doesnt.
>
> Sorry for the confusion. And thanks for the patience ;-)
>
> Kind regards, alux
>
> PS.: A correct Fibonacci sequence would use (< n 2) instead of (< n
> 1). Just to mention it.
>
> Meikel Brandmeyer schrieb:
>> Hi,
>>
>> On Mar 19, 1:39 pm, alux  wrote:
>>
>> > Still, I dont believe.
>>
>> You should...
>>
>> >
>> > I get the same difference with
>> >
>> > user=> (time (map fib0 (range 100)))
>> > "Elapsed time: 1.916445 msecs"
>> >
>> > more than 5 seconds
>> >
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>> >
>> > user=> (time (map fib0 (iterate inc 0)))
>> > "Elapsed time: 0.104203 msecs"
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>>
>> How does this fit to following?
>>
>> > user=> (time (map fib0 (iterate inc 1)))
>> > "Elapsed time: 0.913524 msecs"
>> > (2 3 5 8 13 21 34 55 89 144 ...)
>>   ^^^
>>
>> The example you posted can't be. With the fib0 you posted you get:
>>
>> (fib0 0) => 1
>> (fib0 1) => (+ (fib0 0) (fib0 -1)) => (+ 1 1) => 2
>>
>> So what you posted above can't be true. At least not with the fib0 you
>> gave in your original post.
>>
>> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread Laurent PETIT
hi, follow links from here:
http://www.infoq.com/news/2009/12/clojure-11-rc1-transients

chunked sequences have their first elements realized in advanced by
packets of 32

Under the hoods, it seems that range uses chunked sequences (
http://github.com/richhickey/clojure/blob/master/src/clj/clojure/core.clj#L2016
) , not iterate (
http://github.com/richhickey/clojure/blob/master/src/clj/clojure/core.clj#L2012
)

HTH,

-- 
Laurent

2010/3/19 alux :
> Laurent,
>
>> Could chunked seqs explain something here ?
>
> sounds possible. If I only knew what this is ;-)
>
> Regards, alux
>
> Laurent PETIT schrieb:
>> 2010/3/19 alux :
>> > ;-)
>> >
>> > Still, I dont believe.
>> >
>> > I get the same difference with
>> >
>> > user=> (time (map fib0 (range 100)))
>> > "Elapsed time: 1.916445 msecs"
>> >
>> > more than 5 seconds
>> >
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>> >
>> > user=> (time (map fib0 (iterate inc 0)))
>> > "Elapsed time: 0.104203 msecs"
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>> >
>> > Hm.
>> >
>> > Regards, alux
>>
>> Could chunked seqs explain something here ?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: REPL behaviour / time / lazyness

2010-03-19 Thread alux
Ah, brilliant, many thanks Laurent!

Interesteresting stuff under the hood ..

Kind regards, alux

Laurent PETIT schrieb:
> hi, follow links from here:
> http://www.infoq.com/news/2009/12/clojure-11-rc1-transients
>
> chunked sequences have their first elements realized in advanced by
> packets of 32
>
> Under the hoods, it seems that range uses chunked sequences (
> http://github.com/richhickey/clojure/blob/master/src/clj/clojure/core.clj#L2016
> ) , not iterate (
> http://github.com/richhickey/clojure/blob/master/src/clj/clojure/core.clj#L2012
> )
>
> HTH,
>
> --
> Laurent
>
> 2010/3/19 alux :
> > Laurent,
> >
> >> Could chunked seqs explain something here ?
> >
> > sounds possible. If I only knew what this is ;-)
> >
> > Regards, alux
> >
> > Laurent PETIT schrieb:
> >> 2010/3/19 alux :
> >> > ;-)
> >> >
> >> > Still, I dont believe.
> >> >
> >> > I get the same difference with
> >> >
> >> > user=> (time (map fib0 (range 100)))
> >> > "Elapsed time: 1.916445 msecs"
> >> >
> >> > more than 5 seconds
> >> >
> >> > (0 1 1 2 3 5 8 13 21 34 ...)
> >> >
> >> > user=> (time (map fib0 (iterate inc 0)))
> >> > "Elapsed time: 0.104203 msecs"
> >> > (0 1 1 2 3 5 8 13 21 34 ...)
> >> >
> >> > Hm.
> >> >
> >> > Regards, alux
> >>
> >> Could chunked seqs explain something here ?
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> >
> > To unsubscribe from this group, send email to 
> > clojure+unsubscribegooglegroups.com or reply to this email with the words 
> > "REMOVE ME" as the subject.
> >

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Name suggestions

2010-03-19 Thread caljunior
brain dump coming up:

inclojenous

c-jure

cclojure

full-circle

c-no-free

brace-yourself

chickey (my favourite)


On 19 mrt, 14:17, Alexandre Patry  wrote:
> Frank Hale wrote:
> > clojure + native = clotive
>
> or clo-jive, like clojure dancing with another language.
>
> Alex

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Long post with some questions about getting started...

2010-03-19 Thread Sean Devlin
Nick,
Welcome to Clojure!

On Mar 18, 5:04 pm, Nick  wrote:
> I want to learn Clojure and the first idea for a "simple" app that
> popped into my head was some sort of roguelike (because I'm a gamer
> and this is what I like to do...)  I could go on making hello world
> apps and tiny test apps that serve little purpose, but the way I learn
> is by setting an end goal and going for it.  I don't intend on making
> this in the first shot, but like I said, there's the goal.
>
> I've read quite a bit on Clojure, done some simple stuff like the
> "Hello World" apps and such already.  I get the idea of the list
> structure (though I'm still VERY green on this.)
>
> A little background: I have an extensive background (10+ years
> professional, many more non-pro) in OOP and Procedural Programing
> using everything from Javascript/Actionscript to C# and even the gross
> VB4-6 in my early years and a little known Aspect Scripting (which
> I've totally forgotten by now.)  I've only really dealt with threaded
> applications in C# because, let's face it... it's dead simple even
> using mutex locking.  Non-professionally I started on an old TRS-80
> then moved to a 80386 with GWBASIC/QBASIC and dabbled in C/C++ (but
> mainly I've just read tons of books on C/C++...)
>
> So, I'm trying to put all that aside and think Functional for this.
> I'm really trying, and it's mind bending to put all that aside... but
> I learn by example so here's where I ask some clues.
>
> I've downloaded Netbeans and an addon and played with it a little bit,
> but it seems to require a _main entry method and from the various
> tutorials around, I see that's not the norm.
>
> I'm having an interesting (to me) question around a using REPL.  Once
> it's shut down, where does this code go?  I feel like I'm in the old
> TRS-80 volatile coding days where you write some code, and if you shut
> down you've lost it all.  Is this the case?  So how do you save your
> code in a REPL?  I understand these could be unique per editor so I
> understand if you get irate at me for asking such a silly question...

To answer your question about the REPL, yes everything is lost when
you close it.  However, this isn't the whole story.  Once you create a
new project w/ Enclojure, you can send code from a file too the REPL
either from a context menu or keyboard shortcut (Alt+E in windows).
It's standard practice to edit your file, and send the code to the
REPL dynamically.  This gets you out of the 1960s and back to 2010.

>
> I understand a list from ( to ) has the potential to be a function in
> separate threads because I poked my head into a tutorial I should have
> probably stayed clear of.  If I create a function that I want to
> execute first on start up to check for a file and load it, but if it
> doesn't exist, create it and populate some array for world data.
> That's fairly straight forward, but in a game environment, this gets
> you nowhere but RAM full of data.  About this point I'd then call a
> function create a player that would read in data from this world
> within a local proximity and act upon it.  There's two ways I can see
> going about this.  One is threading it off to act on it's own (which
> is what I'd love to do) and the other is appending it to the end of
> this creation function (have that function call the player on
> completion) but this is where I'm lost.  Is it as simple as calling
> said method at the end of the list or is that filling up a stack of
> pain that I don't want to deal with when it all crashes?
>
> So I thought, I just need to do it.  Just put it to silicon and start
> making something then I stared at the screen...
>
> A part of me would approach this as a client/server model which I'm
> not certain is right for functional programming.  You have to have
> some communication method, or is the "world data" stored in a global
> location that is accessible to this player?  Am I thinking about this
> all wrong?  Would the player spawn the world load/creation only when
> it was needed?  What if you wanted more than one actor? (would be a
> boring game if there were no enemies...)  How does each actor access
> this world data?
>
> I realize some of this sounds totally noobish.  Forgive me, but this
> is new territory for me.  With OOP and functional languages I could
> scope a simple array of an array and reference it within it's scope.
> Is all Clojure scoped globally for data or am I supposed to go find
> something to handle that?  I would figure with the nature of
> functional programming I could have it store data in a simple file
> format for the time being.  That might not scale well, or it just
> may.  I don't know.
>
> Sorry for the length of this post, the rambling, and the incoherent
> thought process.  I realize I'm probably asking too many questions at
> once... :-\

You're probably asking several questions at once because you're trying
to learn a lot at once.  It's understandable.  It sounds to me like
you would benef

Re: type hint puzzler

2010-03-19 Thread cageface
That was it. I was fixated on the ResultSet object and didn't consider
overloading. Adding the (int) hint sped things up considerably.

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: scoped local memoize

2010-03-19 Thread Jason Wolfe
For recursive one-shot memoized functions, I've been using this:

(defmacro memoized-fn [name args & body]
  `(let [a# (atom {})]
 (fn ~name ~args
   (let [m# @a#
 args# ~args]
 (if-let [[_# v#] (find m# args#)]
 v#
   (let [v# (do ~...@body)]
 (swap! a# assoc args# v#)
 v#))

e.g.,
(memoized-fn fib [x]
  (if (< n 2)
  1
(+ (fib (- n 1)) (fib (- n 2)

If you need every last bit of performance, you can replace the atom-
map combination with a mutable Java HashMap.

-Jason

On Mar 18, 11:17 pm, B Smith-Mannschott  wrote:
> On Fri, Mar 19, 2010 at 06:56, Greg  Fodor  wrote:
>
> > I would like to memoize bar such that the memory used for memoization
> > is GC'ed at the end of the call to foo, and additionally the cache
> > used for memoization is thread local (so no need for heavyweight
> > synchronization tools like atoms, etc.) In Ruby, I would implement
> > this as a simple local hash with the ||= operator through each
> > iteration of a loop inside foo that calls bar.
>
> ;; the "trick" I found is to explicitly deref the var binding the
> ;; function to be memoized. This way fib's recursive calls will use
> ;; the memoized binding established in
> ;; use-fib-memoized-thread-locally.
>
> (defn fib [n]
>   (if (> 2 n) n
>       (+ (@#'fib (dec n))
>          (@#'fib (dec (dec n))
>
> (defn use-fib-memoized-thread-locally [n]
>   (binding [fib (memoize fib)]
>     (fib n)))
>
> ;; user> (time (fib 32))
> ;; "Elapsed time: 1755.796366 msecs"  ;; SLOW
> ;; 2178309
> ;;
> ;; user> (time (use-fib-memoized-thread-locally 32))
> ;; "Elapsed time: 1.514927 msecs"     ;; FAST
> ;; 2178309
> ;;
> ;; user> (time (fib 32))
> ;; "Elapsed time: 2024.836838 msecs"  ;; SLOW, again
> ;; 2178309
>
> // Ben

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Name suggestions

2010-03-19 Thread David Andrews
ffinagle

(Merriam-Webster says: to obtain by indirect or involved means, to
obtain by trickery, to use devious or dishonest methods to achieve
one's ends)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: scoped local memoize

2010-03-19 Thread Greg Fodor
Excellent -- thanks all. The binding approach works very well.

On Mar 19, 11:40 am, Jason Wolfe  wrote:
> For recursive one-shot memoized functions, I've been using this:
>
> (defmacro memoized-fn [name args & body]
>   `(let [a# (atom {})]
>      (fn ~name ~args
>        (let [m# @a#
>              args# ~args]
>          (if-let [[_# v#] (find m# args#)]
>              v#
>            (let [v# (do ~...@body)]
>              (swap! a# assoc args# v#)
>              v#))
>
> e.g.,
> (memoized-fn fib [x]
>   (if (< n 2)
>       1
>     (+ (fib (- n 1)) (fib (- n 2)
>
> If you need every last bit of performance, you can replace the atom-
> map combination with a mutable Java HashMap.
>
> -Jason
>
> On Mar 18, 11:17 pm, B Smith-Mannschott  wrote:
>
> > On Fri, Mar 19, 2010 at 06:56, Greg  Fodor  wrote:
>
> > > I would like to memoize bar such that the memory used for memoization
> > > is GC'ed at the end of the call to foo, and additionally the cache
> > > used for memoization is thread local (so no need for heavyweight
> > > synchronization tools like atoms, etc.) In Ruby, I would implement
> > > this as a simple local hash with the ||= operator through each
> > > iteration of a loop inside foo that calls bar.
>
> > ;; the "trick" I found is to explicitly deref the var binding the
> > ;; function to be memoized. This way fib's recursive calls will use
> > ;; the memoized binding established in
> > ;; use-fib-memoized-thread-locally.
>
> > (defn fib [n]
> >   (if (> 2 n) n
> >       (+ (@#'fib (dec n))
> >          (@#'fib (dec (dec n))
>
> > (defn use-fib-memoized-thread-locally [n]
> >   (binding [fib (memoize fib)]
> >     (fib n)))
>
> > ;; user> (time (fib 32))
> > ;; "Elapsed time: 1755.796366 msecs"  ;; SLOW
> > ;; 2178309
> > ;;
> > ;; user> (time (use-fib-memoized-thread-locally 32))
> > ;; "Elapsed time: 1.514927 msecs"     ;; FAST
> > ;; 2178309
> > ;;
> > ;; user> (time (fib 32))
> > ;; "Elapsed time: 2024.836838 msecs"  ;; SLOW, again
> > ;; 2178309
>
> > // Ben

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Sequential vs. "divide and conquer" algorithm

2010-03-19 Thread Andrzej
I've been toying with various implementations of reduce-like
functions, trying to do something "smarter" than a simple iteration
over a collection of data. This hasn't worked out very well, my
implementation is a lot (~50x) slower than a simple loop. Could anyone
point out any bottlenecks in this algorithm and advise me on possible
ways of improving it?

;-- simple (sequential) implementation

(defn- sum_seq_int [val vec]
  (if (empty? vec)
val
(recur (+ val (first vec)) (rest vec

(defn sum_seq [vec]
  (sum_seq_int 0 vec))

;-- "divide&conquer" approach

(defn- split [vec]
  (let [c (count vec)
c2 (/ c 2)]
(list (subvec vec 0 c2) (subvec vec c2 c

(defn- sum_tree_int [val vec1 vec2]
  (cond (and (empty? vec1) (= (count vec2) 1)) (+ val (first vec2))
(and (empty? vec2) (= (count vec1) 1)) (+ val (first vec1))
:else
(let [s1 (split vec1)
  s2 (split vec2)]
  (recur (sum_tree_int val (first s1) (second s1)) (first s2) (second 
s2)

(defn sum_tree [vec]
  (let [s (split vec)]
(sum_tree_int 0 (first s) (second s

;-- some tests
(def l1 (range 1 10))
(def l2 (range 1 1000))
(def l3 (range 1 10))

(time (sum_seq (vec l1)))
"Elapsed time: 0.040508 msecs"
45
(time (sum_seq (vec l2)))
"Elapsed time: 0.297523 msecs"
499500
(time (sum_seq (vec l3)))
"Elapsed time: 29.381109 msecs"
45

(time (sum_tree (vec l1)))
"Elapsed time: 0.181308 msecs"
45
(time (sum_tree (vec l2)))
"Elapsed time: 13.529094 msecs"
499500
(time (sum_tree (vec l3)))
"Elapsed time: 1387.68363 msecs"
45

What is the most likely cause of the slowdown?
1. split function,
2. non-tail-recursive function call,
3. general overhead.

As for (1), how to split the collection so that no data copying is
required and resulting subvectors are more or less balanced? Or, how
to query the underlying data structure whether, or where, such a
"convenient" position exists?

Andrzej

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread Tim Daly

The call I coded works if you only pass a string with no spaces.

However, if the string has spaces there is no result.
If you break the string into String[] then clojure cannot match the
appropriate exec(String[]) method in Runtime. I do not know how
to convince clojure to call this method.

alux wrote:

The call to a static method is special, try

(.exec (Runtime/getRuntime) "ls")

Regards, alux

TimDaly schrieb:
  

(defn cmdresult [cmdstr]
  (let [args (into [] (seq (.split cmdstr " ")))]
  (BufferedReader.
(InputStreamReader.
  (. (. (. Runtime (getRuntime)) (exec args))
(getInputStream))

(defn readLine [cmdresult] (. cmdresult (readLine)))

(def a (cmdresult "ls *.o"))

This fails claiming:
No matching method found: exec for class java.lang.Runtime

If I replace the Runtime line with:
   (. (. (. Runtime (getRuntime)) (exec "ls")) (getInputStream))
it works and gives me the result of the "ls" system call.

If I replace the Runtime line with
  (. (. (. Runtime (getRuntime)) (exec "ls *.o"))
(getInputStream))
it fails even though it has a string argument.

Suggestions?

Tim Daly



  


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure-mode-like syntax highlighting for the SLIME REPL

2010-03-19 Thread Phil Hagelberg
On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk
 wrote:
> there was a Stack Overflow question recently re: syntax highlighting
> Clojure REPLs. This got me thinking that since I was going to tweak
> SLIME REPL font-lock for quite some time now (I find the default a bit
> too aggressive), I might as well do it now and have it use
> clojure-mode's font-lock settings too.
>
> Here's what I came up with:
> http://gist.github.com/337280
>
> I've got some questions in connection with this. Firstly, I'd love to
> know whether this could be done in a simpler way. If not, then I
> wonder if clojure-mode could move the font-lock setup from the
> clojure-mode function itself to something like my
> clojure-font-lock-setup function and  then just call that from
> clojure-mode? That way a usable syntax highlighting SLIME REPL would
> become a one hook affair.

Awesome. Yeah, that sounds great. Could you submit an issue to
clojure-mode to do this?

http://github.com/technomancy/clojure-mode/issues

A patch would be even better, of course.

> Then there's one thing I didn't try to tackle for now (because it
> would actually require me to write font-lock code, which is something
> that scares me to death), namely prompt highlighting ("namespace>"
> appears in plain text for now). Is there a simple way to add this on
> top of clojure-mode font-lock settings?

This would belong in swank-clojure actually. clojure-mode doesn't with
slime at all by itself; it's just for highlighting, indentation, etc.
(though it can spawn simplistic repl subprocesses.)

-Phil

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Sequential vs. "divide and conquer" algorithm

2010-03-19 Thread Sean Devlin
What type of improvement are you expecting to see?

1.  A linear improvement based on throwing more cores at the problem?
In this case you would need to use pmap to compute items in parallel.
Your implementation appears to be single threaded.
2.  An algorithmic improvement, like going from a DFT to an FFT?  In
this case, is there any theoretical reason the algorithm does less
work?  Are you making a time/memory trade off?

This would make it easier to provide suggestions.
Sean

On Mar 19, 12:53 pm, Andrzej  wrote:
> I've been toying with various implementations of reduce-like
> functions, trying to do something "smarter" than a simple iteration
> over a collection of data. This hasn't worked out very well, my
> implementation is a lot (~50x) slower than a simple loop. Could anyone
> point out any bottlenecks in this algorithm and advise me on possible
> ways of improving it?
>
> ;-- simple (sequential) implementation
>
> (defn- sum_seq_int [val vec]
>   (if (empty? vec)
>     val
>     (recur (+ val (first vec)) (rest vec
>
> (defn sum_seq [vec]
>   (sum_seq_int 0 vec))
>
> ;-- "divide&conquer" approach
>
> (defn- split [vec]
>   (let [c (count vec)
>         c2 (/ c 2)]
>     (list (subvec vec 0 c2) (subvec vec c2 c
>
> (defn- sum_tree_int [val vec1 vec2]
>   (cond (and (empty? vec1) (= (count vec2) 1)) (+ val (first vec2))
>         (and (empty? vec2) (= (count vec1) 1)) (+ val (first vec1))
>         :else
>         (let [s1 (split vec1)
>               s2 (split vec2)]
>           (recur (sum_tree_int val (first s1) (second s1)) (first s2) (second 
> s2)
>
> (defn sum_tree [vec]
>   (let [s (split vec)]
>     (sum_tree_int 0 (first s) (second s
>
> ;-- some tests
> (def l1 (range 1 10))
> (def l2 (range 1 1000))
> (def l3 (range 1 10))
>
> (time (sum_seq (vec l1)))
> "Elapsed time: 0.040508 msecs"
> 45
> (time (sum_seq (vec l2)))
> "Elapsed time: 0.297523 msecs"
> 499500
> (time (sum_seq (vec l3)))
> "Elapsed time: 29.381109 msecs"
> 45
>
> (time (sum_tree (vec l1)))
> "Elapsed time: 0.181308 msecs"
> 45
> (time (sum_tree (vec l2)))
> "Elapsed time: 13.529094 msecs"
> 499500
> (time (sum_tree (vec l3)))
> "Elapsed time: 1387.68363 msecs"
> 45
>
> What is the most likely cause of the slowdown?
> 1. split function,
> 2. non-tail-recursive function call,
> 3. general overhead.
>
> As for (1), how to split the collection so that no data copying is
> required and resulting subvectors are more or less balanced? Or, how
> to query the underlying data structure whether, or where, such a
> "convenient" position exists?
>
> Andrzej

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


map-filter, is this in the API?

2010-03-19 Thread Greg Fodor
Very simple function:

(defn map-filter [f coll]
  (map f (filter f (coll)))

Is there an API function for this that I am missing? For example, it
is useful for pulling out all values in a list of maps of a certain
key that is optional:

Clojure=> (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d}
{:a :b :c :d :k :other}])
(:found :other)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Ensure

2010-03-19 Thread Jim Blomo
On Mon, Mar 15, 2010 at 3:34 PM, Raoul Duke  wrote:
> On Mon, Mar 15, 2010 at 1:13 AM, Christophe Grand  
> wrote:
>> It hasn't blocked in the sense of "wait and continue": it retries the
>> transaction after growing the history of the ref (refs have an adaptive
>> history):
>
> i'm confused about being able to set :max-history, does that not run
> the risk of breaking the correctness of things?

No, my understanding is that correctness is guaranteed by the retry.
The adaptive history is an optimization so that the retry doesn't need
to happen.  As Christophe demonstrated, the first transaction
essentially ran with a :max-history of 0 and the transaction had to
retry.  The next time around, the ref had adequate history to store
its previous state so that a retry was not needed.

Jim

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread alux
Sorry, I'm a bit in a hurry ;-)
You give a vector, it needs an array. Try something like:

spels=> (make-array (.getClass "") 2 )
#
spels=> (def arr (make-array (.getClass "") 2 ))
#'spels/arr
spels=> (aset arr 0 "write")
"write"
spels=> (aset arr 1 "c:\\config.sys")
"c:\\config.sys"
spels=> (.exec (Runtime/getRuntime) arr)

Greezs, alux

Tim Daly schrieb:
> The call I coded works if you only pass a string with no spaces.
>
> However, if the string has spaces there is no result.
> If you break the string into String[] then clojure cannot match the
> appropriate exec(String[]) method in Runtime. I do not know how
> to convince clojure to call this method.
>
> alux wrote:
> > The call to a static method is special, try
> >
> > (.exec (Runtime/getRuntime) "ls")
> >
> > Regards, alux
> >
> > TimDaly schrieb:
> >
> >> (defn cmdresult [cmdstr]
> >>   (let [args (into [] (seq (.split cmdstr " ")))]
> >>   (BufferedReader.
> >> (InputStreamReader.
> >>   (. (. (. Runtime (getRuntime)) (exec args))
> >> (getInputStream))
> >>
> >> (defn readLine [cmdresult] (. cmdresult (readLine)))
> >>
> >> (def a (cmdresult "ls *.o"))
> >>
> >> This fails claiming:
> >> No matching method found: exec for class java.lang.Runtime
> >>
> >> If I replace the Runtime line with:
> >>(. (. (. Runtime (getRuntime)) (exec "ls")) (getInputStream))
> >> it works and gives me the result of the "ls" system call.
> >>
> >> If I replace the Runtime line with
> >>   (. (. (. Runtime (getRuntime)) (exec "ls *.o"))
> >> (getInputStream))
> >> it fails even though it has a string argument.
> >>
> >> Suggestions?
> >>
> >> Tim Daly
> >>
> >
> >

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread Michael Gardner
On Mar 19, 2010, at 6:07 AM, TimDaly wrote:

> (defn cmdresult [cmdstr]
>  (let [args (into [] (seq (.split cmdstr " ")))]
>  (BufferedReader.
>(InputStreamReader.
>  (. (. (. Runtime (getRuntime)) (exec args))
> (getInputStream))

Why do (into [])? .exec expects a String[], exactly what .split gives you.

I wrote something similar recently (included below, in case you're interested). 
You could easily wrap it with a .split to get similar functionality, though 
personally I prefer passing the args as a list because that way you can deal 
with paths with spaces in them.

-Michael

(defn cmd [command & args]
"Runs command with args and returns its stdout, stderr, and exit status."
(let [process (.start (ProcessBuilder. (into-array (cons command args]
(.waitFor process)
(hash-map
:output
(line-seq
(java.io.BufferedReader.
(java.io.InputStreamReader.
(.getInputStream process
:error
(line-seq
(java.io.BufferedReader.
(java.io.InputStreamReader.
(.getErrorStream process
:status
(.exitValue process

(defn do-cmd [command & args]
"Runs command with args and returns its stdout as a seq of lines. Throws 
exception on failure."
(let [command (apply cmd command args)]
(if (zero? (:status command))
(:output command)
(throw
(Exception.
(str "Command failed: "
(apply str
(interpose "\n"
(:error command)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: map-filter, is this in the API?

2010-03-19 Thread Sean Devlin
Nope.  (map f (filter f ...)) is currently the way to go.

On Mar 19, 1:54 pm, Greg  Fodor  wrote:
> Very simple function:
>
> (defn map-filter [f coll]
>   (map f (filter f (coll)))
>
> Is there an API function for this that I am missing? For example, it
> is useful for pulling out all values in a list of maps of a certain
> key that is optional:
>
> Clojure=> (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d}
> {:a :b :c :d :k :other}])
> (:found :other)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: map-filter, is this in the API?

2010-03-19 Thread Michael Gardner
On Mar 19, 2010, at 12:54 PM, Greg Fodor wrote:

> Very simple function:
> 
> (defn map-filter [f coll]
>  (map f (filter f (coll)))

You have an extra parenthesis before coll.

> Is there an API function for this that I am missing? For example, it
> is useful for pulling out all values in a list of maps of a certain
> key that is optional:
> 
> Clojure=> (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d}
> {:a :b :c :d :k :other}])
> (:found :other)

I don't think so. But note that you can do the filter after the map, to avoid 
applying f twice per element:

(defn map-filter-2 [f coll]
(filter identity (map f coll)))

-Michael

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Sequential vs. "divide and conquer" algorithm

2010-03-19 Thread Andrzej
On Sat, Mar 20, 2010 at 2:15 AM, Sean Devlin  wrote:
> What type of improvement are you expecting to see?
>
> 1.  A linear improvement based on throwing more cores at the problem?

Yes.

> In this case you would need to use pmap to compute items in parallel.

I haven't looked at pmap yet. Thanks for the clue, it might prove more
useful indeed.

> Your implementation appears to be single threaded.

Yes, that's just a test. I guess I should have also chosen a more
realistic worker function.

As all clojure's persistent data collections are built on top of tree
structures I thought this kind of destructuring could be both
straightforward to implement and efficient. I wonder if a built-in
"partition" function, aware of the internal representation of the
collection data, could help here.

> 2.  An algorithmic improvement, like going from a DFT to an FFT?  In
> this case, is there any theoretical reason the algorithm does less
> work?  Are you making a time/memory trade off?

No, although balancing the operations could potentially help with some
second order effects (e.g. numerical errors).

Thanks,

Andrzej

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Long post with some questions about getting started...

2010-03-19 Thread Terje Norderhaug

On Mar 18, 2010, at 2:04 PM, Nick wrote:

I'm having an interesting (to me) question around a using REPL.  Once
it's shut down, where does this code go?  I feel like I'm in the old
TRS-80 volatile coding days where you write some code, and if you shut
down you've lost it all.  Is this the case?  So how do you save your
code in a REPL?  I understand these could be unique per editor so I
understand if you get irate at me for asking such a silly question...


I mostly use the repl for executing tests, preferring to write and  
evaluate Clojure definitions from a lisp editor. For example, in the  
MCLIDE lisp editor, I evaluate lisp code in the editor by placing the  
cursor at the opening or closing parenthesis of an expression then  
hit the Enter key. Alternatively, I use a menu shortcut to (re) 
evaluate all definitions in the file I am editing.


-- Terje Norderhaug
  te...@in-progress.com




--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread Patrik Fredriksson
Also, have a look at http://richhickey.github.com/clojure-contrib/shell-api.html

/Patrik

On Mar 19, 7:00 pm, Michael Gardner  wrote:
> On Mar 19, 2010, at 6:07 AM, TimDaly wrote:
>
> > (defn cmdresult [cmdstr]
> >  (let [args (into [] (seq (.split cmdstr " ")))]
> >  (BufferedReader.
> >    (InputStreamReader.
> >      (. (. (. Runtime (getRuntime)) (exec args))
> > (getInputStream))
>
> Why do (into [])? .exec expects a String[], exactly what .split gives you.
>
> I wrote something similar recently (included below, in case you're 
> interested). You could easily wrap it with a .split to get similar 
> functionality, though personally I prefer passing the args as a list because 
> that way you can deal with paths with spaces in them.
>
> -Michael
>
> (defn cmd [command & args]
>     "Runs command with args and returns its stdout, stderr, and exit status."
>     (let [process (.start (ProcessBuilder. (into-array (cons command args]
>         (.waitFor process)
>         (hash-map
>             :output
>                 (line-seq
>                     (java.io.BufferedReader.
>                         (java.io.InputStreamReader.
>                             (.getInputStream process
>             :error
>                 (line-seq
>                     (java.io.BufferedReader.
>                         (java.io.InputStreamReader.
>                             (.getErrorStream process
>             :status
>                 (.exitValue process
>
> (defn do-cmd [command & args]
>     "Runs command with args and returns its stdout as a seq of lines. Throws 
> exception on failure."
>     (let [command (apply cmd command args)]
>         (if (zero? (:status command))
>             (:output command)
>             (throw
>                 (Exception.
>                     (str "Command failed: "
>                         (apply str
>                             (interpose "\n"
>                                 (:error command)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread Meikel Brandmeyer
Hi,

On Fri, Mar 19, 2010 at 11:00:34AM -0700, alux wrote:

> spels=> (make-array (.getClass "") 2 )
> #
> spels=> (def arr (make-array (.getClass "") 2 ))
> #'spels/arr
> spels=> (aset arr 0 "write")
> "write"
> spels=> (aset arr 1 "c:\\config.sys")
> "c:\\config.sys"
> spels=> (.exec (Runtime/getRuntime) arr)

It's easier to use into-array:
(.exec (Runtime/getRuntime) (into-array ["write" "c:\\config.sys"]))

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: getRuntime exec call?

2010-03-19 Thread alux
;-)

I'm still at letter b in clojure.core. Grin. Regards, a.

Meikel Brandmeyer schrieb:
> Hi,
>
> On Fri, Mar 19, 2010 at 11:00:34AM -0700, alux wrote:
>
> > spels=> (make-array (.getClass "") 2 )
> > #
> > spels=> (def arr (make-array (.getClass "") 2 ))
> > #'spels/arr
> > spels=> (aset arr 0 "write")
> > "write"
> > spels=> (aset arr 1 "c:\\config.sys")
> > "c:\\config.sys"
> > spels=> (.exec (Runtime/getRuntime) arr)
>
> It's easier to use into-array:
> (.exec (Runtime/getRuntime) (into-array ["write" "c:\\config.sys"]))
>
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Java method call irritation

2010-03-19 Thread Stuart Sierra
On Mar 18, 11:55 am, Per Vognsen  wrote:
> Is there any reason why a .method occurrence in non-operator position
> doesn't just do the closure wrapping automagically?

It's been discussed as a possibility; it may be added to Clojure in
the future.

-SS

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Name suggestions

2010-03-19 Thread Stuart Sierra
On Mar 17, 3:08 am, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.

Personally, I much prefer library names that are descriptive rather
than creative.  Give your kids cute names, not your libraries.

-SS

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


clojure.walk

2010-03-19 Thread cej38
This post has two parts.

Part 1.

I know that the API is trying to hit the sweet spot on the brevity vs.
information curve, but there are several areas where more information
is needed; one of these is clojure.walk.

Let's say that I have some nested set of vectors:
(def nestV [ [0 [0] ] [0 0] ])
and I want to apply
#(+ % 3)
to each element and get out a nested set of vectors with the same
shape as nestV
[ [3 [3] ] [3 3]].

The overview to clojure.walk says the following: "It takes any data
structure (list, vector, map, set, seq), calls a function on every
element, and uses the return value of the function in place of the
original."  This sounds like I will find a function within this
namespace that will do what I want.  I tried prewalk and postwalk,
which, from the their usage "examples" would appear to be what I want.

But when I try to test them I find the following:
user=> (prewalk #(+ 3 %) nestV)
#
user=> (postwalk #(+ 3 %) nestV)
#

The problem with the usage "examples" is that they don't actually show
what the outcome will be.  Further, there is no documentation other
than the API on clojure.walk.


Part 2

Is there a function in the API that allows me to do the type of
calculation I described above?

user=> (some-function  #(+ % 3)  nestV)
(((3(3))(3 3))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Long post with some questions about getting started...

2010-03-19 Thread Mike Meyer
On Fri, 19 Mar 2010 07:21:50 -0700 (PDT)
Sean Devlin  wrote:
> > I'm having an interesting (to me) question around a using REPL.  Once
> > it's shut down, where does this code go?  I feel like I'm in the old
> > TRS-80 volatile coding days where you write some code, and if you shut
> > down you've lost it all.  Is this the case?  So how do you save your
> > code in a REPL?  I understand these could be unique per editor so I
> > understand if you get irate at me for asking such a silly question...
> 
> To answer your question about the REPL, yes everything is lost when
> you close it.  However, this isn't the whole story.  Once you create a
> new project w/ Enclojure, you can send code from a file too the REPL
> either from a context menu or keyboard shortcut (Alt+E in windows).
> It's standard practice to edit your file, and send the code to the
> REPL dynamically.  This gets you out of the 1960s and back to 2010.

Most clojure-aware environments will have similar functionality:
SLIME+SWANK, Eclipse, etc. It's not clear this really gets you out of
the 60s, though - it's been standard practice for (file-based *) LISP
development for as long as I can remember. Nuts, it worked with
Scheme2C and mg on the Amiga in the 80s.

  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure.walk

2010-03-19 Thread Kevin Downey
I'm not overly familiar with clojure.walk, but I think you'll find the
output of (prewalk #(doto % prn) [[3 [3]] [3 3]]) very illuminating.

On Fri, Mar 19, 2010 at 2:13 PM, cej38  wrote:
> This post has two parts.
>
> Part 1.
>
> I know that the API is trying to hit the sweet spot on the brevity vs.
> information curve, but there are several areas where more information
> is needed; one of these is clojure.walk.
>
> Let's say that I have some nested set of vectors:
> (def nestV [ [0 [0] ] [0 0] ])
> and I want to apply
> #(+ % 3)
> to each element and get out a nested set of vectors with the same
> shape as nestV
> [ [3 [3] ] [3 3]].
>
> The overview to clojure.walk says the following: "It takes any data
> structure (list, vector, map, set, seq), calls a function on every
> element, and uses the return value of the function in place of the
> original."  This sounds like I will find a function within this
> namespace that will do what I want.  I tried prewalk and postwalk,
> which, from the their usage "examples" would appear to be what I want.
>
> But when I try to test them I find the following:
> user=> (prewalk #(+ 3 %) nestV)
> # clojure.lang.PersistentVector (NO_SOURCE_FILE:0)>
> user=> (postwalk #(+ 3 %) nestV)
> # java.lang.ClassCastException: clojure.lang.PersistentVector
> (NO_SOURCE_FILE:0)>
>
> The problem with the usage "examples" is that they don't actually show
> what the outcome will be.  Further, there is no documentation other
> than the API on clojure.walk.
>
>
> Part 2
>
> Is there a function in the API that allows me to do the type of
> calculation I described above?
>
> user=> (some-function  #(+ % 3)  nestV)
> (((3(3))(3 3))
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>



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

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Tim Johnson
FYI: I'm using slackware 13.0, 32-bit
slack has much to redeem it, but there is no apt-get, synaptic and
aptitude.
Thus when I unzip clojure-1.1.0.zip, the closest I can find to
installation instructions are at readme.txt.
Looks like a very simple process, except that I am unfamiliar with
`ant'. Looks like I need to install it.

So what am I looking for? 
Is it apache-ant, or some other system?
And where do I download it?

Note: slack has very good build tools for applications with C as the
source, so if ant is written in C, source would be fine

Thanks
-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: overrding function from other namespace

2010-03-19 Thread Kevin Downey
why are you def'ing your functions in the mock namespace? why are you
juggling namespaces at all?

On Wed, Mar 17, 2010 at 3:12 PM, Martin Hauner  wrote:
> Hi,
>
> I trying to use clojure.contrib.mock. It says to override the function
> report-problem to
> integrate it into other test framework like clojure.test.
>
> I've got this working, but the namespace switching looks a bit ugly.
> Is there a better
> way to handle this? Maybe something like
>
> (ns clojure.contrib.mock
>  (defn... the override)
>  )
>
> which avoids the extra code to switch back to the original namespace?
>
>
> (ns apfloattest
>  (:use
>    apfloat
>    clojure.test
>    clojure.contrib.mock))
>
>
> (ns clojure.contrib.mock
>  (:use
>    clojure.test))
>
> ; delegate mock reporting to clojure.test
>  (defn report-problem
>    ([function expected actual message]
>      (is (= expected actual)
>        (str message " Function name: " function
>
> (ns apfloattest)
>
>
> (deftest test-sqrtf
>  (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5)))
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>



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

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


clojure naming convention for accessors vs. local variables

2010-03-19 Thread strattonbrazil
If am creating accessors to access structures, how should they be
named?

(defstruct employer :employee)
(defstruct employee :employer)
(def employee-name (accessor employee :employer))
(def employer-name (accessor employer :employee))

In a situation where one struct is pointing to the other, is that the
best accessor name?  Since structs are lower case do they clash with
variables and accessors ever?  I could easily see myself doing

(def employee (...))

Here, I assume it won't have any problems, but does it become
problematic later?  Especially since it seems that accessors can be in
either order.

(defstruct vert :id :edgeId)
(defstruct edge :id :vertId)
(def vert (accessor edge :vert))
(def edge (accessor vert :edge))

I know this could be easily resolved by changing the accessor
definitions to get-vert and get-edge, but I was hoping it wouldn't be
necessary.  Once again, I'm bound to have a variable somewhere in my
code called vert and edge.  Java and Scala don't seem to have this
problem.  Especially using Scala's builtin getter setter feature,
which has strick ordering like

edge.vert // returns the vert for this edge
vert.edge // returns the edge for this vert

Is there a better naming convention to follow?  get-vert and get-
edge?  Should structures ever be uppercase to distinguish them?  That
doesn't seem to be the lisp convention.  In these cases it seems the
struct name would
never be a problem, but it seems I'm stuck between making a convenient
accessor name and easily stomping over if making a convenient variable
name.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure-mode-like syntax highlighting for the SLIME REPL

2010-03-19 Thread Michał Marczyk
On 19 March 2010 18:12, Phil Hagelberg  wrote:
> On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk
> Awesome. Yeah, that sounds great. Could you submit an issue to
> clojure-mode to do this?
>
> http://github.com/technomancy/clojure-mode/issues
>
> A patch would be even better, of course.

Sure thing, I'll send you a patch / pull request sometime this weekend. :-)

>> Then there's one thing I didn't try to tackle for now (because it
>> would actually require me to write font-lock code, which is something
>> that scares me to death), namely prompt highlighting ("namespace>"
>> appears in plain text for now). Is there a simple way to add this on
>> top of clojure-mode font-lock settings?
>
> This would belong in swank-clojure actually. clojure-mode doesn't with
> slime at all by itself; it's just for highlighting, indentation, etc.
> (though it can spawn simplistic repl subprocesses.)

Yes, I realise that's not something to put in clojure-mode. What I
meant is that I haven't yet investigated how slime-repl &
swank-clojure (?) go about putting those custom text properties on
things captured on the standard output of the Lisp process (so things
like (doc foo) or the output of (println :foo) have their own subdued
colour). Basically I'd like to try to use whatever mechanism is in
place for distinguishing printouts from return values and combine that
with clojure-mode highlighting for the perfect Clojure-oriented SLIME
REPL experience. ;-)

Hopefully I'll be able to do that in the next few days; I'll post it
for your consideration as soon as I have it ready.

(Note that as far as font-lock is concerned, I hardly know what I'm
doing. Perhaps someone who knows what they're doing will post the
elisp incantation to accomplish the above before I get started on it.
:-))

All the best,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure-mode-like syntax highlighting for the SLIME REPL

2010-03-19 Thread Michał Marczyk
On 19 March 2010 12:58, Rick Moynihan  wrote:
> Very cute!  I'd love to see this integrated into clojure-mode!

Glad you like it! As mentioned above, I'll try to polish it a bit further.

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Michał Marczyk
On 20 March 2010 00:32, Tim Johnson  wrote:
> So what am I looking for?
> Is it apache-ant, or some other system?
> And where do I download it?

Yes, it's Apache Ant:

http://ant.apache.org/

> Note: slack has very good build tools for applications with C as the
> source, so if ant is written in C, source would be fine

It's written in Java. You should be able to get a jar, from the
project page or perhaps a Maven repo (e.g.
http://repo1.maven.org/maven2/ant/ant/1.6.5/).

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Tim Johnson
* Micha?? Marczyk  [100319 15:56]:
> On 20 March 2010 00:32, Tim Johnson  wrote:
> > So what am I looking for?
> > Is it apache-ant, or some other system?
> > And where do I download it?
> 
> Yes, it's Apache Ant:
> 
> http://ant.apache.org/
> 
 Thanks. I got it.
 Installed it as per instructions at
 http://ant.apache.org/manual/index.html
Now i have the following error messages:
## =>
t...@bart:~$ echo $PATH
/usr/local/bin/ant/bin:/usr/local/bin/ant:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/java/bin:/usr/lib/kde4/libexec:/usr/lib/qt/bin:/usr/share/texmf/bin:.
t...@bart:~$ ant
Exception in thread "main" java.lang.NoClassDefFoundError: 
org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: 
org.apache.tools.ant.launch.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: org.apache.tools.ant.launch.Launcher.  Program 
will exit.

## => More paths: 
t...@bart:~$ echo $ANT_HOME
/usr/local/bin/ant/bin
$JAVA_HOME
/usr/lib/java

-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Michał Marczyk
I would guess that you need the ant-launcher jar too:

http://repo1.maven.org/maven2/ant/ant-launcher/1.6.5/

If you find there might be something else missing, check out the whole
ant group:

http://repo1.maven.org/maven2/ant/

HTH.

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Tim Johnson
* Micha?? Marczyk  [100319 16:46]:
> I would guess that you need the ant-launcher jar too:
> 
> http://repo1.maven.org/maven2/ant/ant-launcher/1.6.5/
> 
> If you find there might be something else missing, check out the whole
> ant group:
> 
> http://repo1.maven.org/maven2/ant/
 I'm looking at that URL now. 
 ---
 where is the .jar file to be installed?
   (Feel free to point me to documentation)
 ---
 Example - on my machine the java binary is at:
 /usr/lib/java/bin/java
 thanks

-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Long post with some questions about getting started...

2010-03-19 Thread Terje Norderhaug

On Mar 19, 2010, at 4:17 PM, Mike Meyer wrote:

On Fri, 19 Mar 2010 07:21:50 -0700 (PDT)
Sean Devlin  wrote:
I'm having an interesting (to me) question around a using REPL.   
Once

it's shut down, where does this code go?  I feel like I'm in the old
TRS-80 volatile coding days where you write some code, and if you  
shut

down you've lost it all.  Is this the case?  So how do you save your
code in a REPL?  I understand these could be unique per editor so I
understand if you get irate at me for asking such a silly  
question...


To answer your question about the REPL, yes everything is lost when
you close it.  However, this isn't the whole story.  Once you  
create a

new project w/ Enclojure, you can send code from a file too the REPL
either from a context menu or keyboard shortcut (Alt+E in windows).
It's standard practice to edit your file, and send the code to the
REPL dynamically.  This gets you out of the 1960s and back to 2010.


Most clojure-aware environments will have similar functionality:
SLIME+SWANK, Eclipse, etc. It's not clear this really gets you out of
the 60s, though - it's been standard practice for (file-based *) LISP
development for as long as I can remember. Nuts, it worked with
Scheme2C and mg on the Amiga in the 80s.

*) InterLISP and some others were more like SmallTalk, or MS BASIC, in
   that you edited code at the REPL and saved the entire
   workspace. That did add power - I've never seen a file-based LISP
   whose error handler would let me fix the code on the fly and
   continue execution.


Possibly I am misunderstanding "I've never seen a file-based LISP  
whose error handler would let me fix the code on the fly and continue  
execution" but that sounds like common practice in the REPL break  
loop for many lisps.


-- Terje Norderhaug
  te...@in-progress.com




--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure naming convention for accessors vs. local variables

2010-03-19 Thread ataggart
As the doc for 'accessor notes, you should really eschew this stuff
altogether, and be more idiomatic by just using the keyword.  If you
absolutely know that you need that "(slightly) more efficient" access,
then naming the struct with an uppercase first letter works, and isn't
too uncommon; besides this is a special-case performance issue, right?


On Mar 19, 4:36 pm, strattonbrazil  wrote:
> If am creating accessors to access structures, how should they be
> named?
>
> (defstruct employer :employee)
> (defstruct employee :employer)
> (def employee-name (accessor employee :employer))
> (def employer-name (accessor employer :employee))
>
> In a situation where one struct is pointing to the other, is that the
> best accessor name?  Since structs are lower case do they clash with
> variables and accessors ever?  I could easily see myself doing
>
> (def employee (...))
>
> Here, I assume it won't have any problems, but does it become
> problematic later?  Especially since it seems that accessors can be in
> either order.
>
> (defstruct vert :id :edgeId)
> (defstruct edge :id :vertId)
> (def vert (accessor edge :vert))
> (def edge (accessor vert :edge))
>
> I know this could be easily resolved by changing the accessor
> definitions to get-vert and get-edge, but I was hoping it wouldn't be
> necessary.  Once again, I'm bound to have a variable somewhere in my
> code called vert and edge.  Java and Scala don't seem to have this
> problem.  Especially using Scala's builtin getter setter feature,
> which has strick ordering like
>
> edge.vert // returns the vert for this edge
> vert.edge // returns the edge for this vert
>
> Is there a better naming convention to follow?  get-vert and get-
> edge?  Should structures ever be uppercase to distinguish them?  That
> doesn't seem to be the lisp convention.  In these cases it seems the
> struct name would
> never be a problem, but it seems I'm stuck between making a convenient
> accessor name and easily stomping over if making a convenient variable
> name.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: clojure.walk

2010-03-19 Thread cej38
Kevin, thank you for your example.

Ok here is what I get:
(prewalk #(doto % prn) [[3 [3]] [3 3]])
[[3 [3]] [3 3]]
[3 [3]]
3
[3]
3
[3 3]
3
3
[[3 [3]] [3 3]]

Thus, it appears that an "element" of my nested vectors isn't just the
values within the vectors, but also stands for the inner vectors as
well.  I agree that this is a (maybe THE) proper way of reading the
quoted API text from my earlier post. But this goes to the first part
of my earlier post, given this small example I have a much better idea
of what is going on.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: overrding function from other namespace

2010-03-19 Thread ataggart
I'd imagine you should be using with-bindings:

user=> (ns foo)
nil
foo=> (defn bar [x] (inc x))
#'foo/bar
foo=> (ns user)
nil
user=> (foo/bar 5)
6
user=> (with-bindings {#'foo/bar #(dec %)} (foo/bar 5))
4


On Mar 17, 3:12 pm, Martin Hauner  wrote:
> Hi,
>
> I trying to use clojure.contrib.mock. It says to override the function
> report-problem to
> integrate it into other test framework like clojure.test.
>
> I've got this working, but the namespace switching looks a bit ugly.
> Is there a better
> way to handle this? Maybe something like
>
> (ns clojure.contrib.mock
>   (defn... the override)
>   )
>
> which avoids the extra code to switch back to the original namespace?
>
> (ns apfloattest
>   (:use
>     apfloat
>     clojure.test
>     clojure.contrib.mock))
>
> (ns clojure.contrib.mock
>   (:use
>     clojure.test))
>
> ; delegate mock reporting to clojure.test
>   (defn report-problem
>     ([function expected actual message]
>       (is (= expected actual)
>         (str message " Function name: " function
>
> (ns apfloattest)
>
> (deftest test-sqrtf
>   (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5)))
>
> --
> 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Simple functional programming lexicon?

2010-03-19 Thread Michał Marczyk
On 18 March 2010 20:56, Ben Armstrong  wrote:
> On 18/03/10 06:57 AM, Michael Kohl wrote:
>> There's a really nice article series on monads in Clojure:
>> http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
> Oh, wow!  Lucidly written.  And it gives me something, maybe-m, that I can't
> believe I got along without before.  I'm eager now to continue with part 2

Agreed. :-)

Well, I almost gave in to an urge to go on musing about FP in general,
but I decided to suppress it for now and to post instead my own short
bibliography of monad-related Web resources. Clojure-based stuff comes
first, though I'm also including two Haskell links of particular
interest. Michael has already mentioned Konrad's tutorial, but it is
still included below so that I can use this posting as a
self-contained reference.

Clearly it is true that there is no need to learn about monads to
programme in Clojure (and to be productive and have fun while doing
so), but they do make for a very interesting approach to structuring
computations, so if one is already curious about them, then one cannot
go wrong with some monadic food for thought. ;-) (The full immersion
programme is run in Haskell, of course, but the Clojure experience is
very enlightening too.)

All the best,
Michał

Monads: A Bibliography
=

First, the above mentioned tutorial by Konrad Hinsen:

[A Monad Tutorial For Clojure Programmers][1]

The following articles by Jim Duey are also very good (and they do
take a somewhat different approach to Konrad's tutorial, so it's worth
while to read both series):

[Monads in Clojure][2]
[Higher Level Monads][3]
[Why Use Monads][4]
[The Continuation Monad in Clojure][5]
[Sessions for Compojure][6]

There's also a very good Haskell resource on the most frequently used monads:

[All About Monads][7]

The example code is in Haskell, but each monad's section includes some
motivating discussion.

Then there are [Philip Wadler's monad-related papers][8]. IIRC,
"Monads for functional programming" is a bit of a tutorial paper, so
that may be worth skimming.

And just for the pleasure of reading through the numerous displays of
breathtaking FP brilliance collected therein, take a look at [Oleg
Kiselyov's site][9]. The section labelled "Computation" has a
subsection devoted to monads.

[1]: 
http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
[2]: http://intensivesystems.net/tutorials/monads_101.html
[3]: http://intensivesystems.net/tutorials/monads_201.html
[4]: http://intensivesystems.net/tutorials/why_monads.html
[5]: http://intensivesystems.net/tutorials/cont_m.html
[6]: http://intensivesystems.net/tutorials/web_sessions.html
[7]: http://www.haskell.org/all_about_monads/html/index.html
[8]: http://homepages.inf.ed.ac.uk/wadler/topics/monads.html
[9]: http://okmij.org/ftp/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Installation issues on slack 13.0 (ant?)

2010-03-19 Thread Michał Marczyk
Actually that Maven repo suggestion strikes me as misguided now,
seeing how your purpose is to have a usable ant command and not access
ant as a library... You'll probably be better of with the latest ant
distribution from their webpage.

The installation docs are here:

http://ant.apache.org/manual/index.html

This page does include instructions on where to put things.

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


lazy-xml returns 503 from w3.org

2010-03-19 Thread Wilson MacGyver
Hi,

In trying to use clojure.cotrib.lazy-xml to parse a xml file. I get

java.io.IOException: Server returned HTTP response code: 503 for URL:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

because w3c blocks access to that dtd now. Is there any work around?

Thanks,

-- 
Omnem crede diem tibi diluxisse supremum.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Simple functional programming lexicon?

2010-03-19 Thread Per Vognsen
They provide elegant solutions to a great many problems, some quite
simple. Here's how I would compute subobjects (subseqs, subsets),
partitions and permutations monadically:

(def true-or-false (constantly (either true false)))

;; computes subseqs in the seq monad and subsets in the set monad
(defn subs [s]
  (m-filter true-or-false s)))

(defn partitions [s]
  (m-partition-by true-or-false s))

(def permutations [s]
  (when (seq s)
(>> (permutations (rest s))
  [[left right] (m-split-with true-or-false %)]
  (concat left [(first s)] right

You could respond that most of the heavy lifting is done by the
monadic transliterations of commonplace seq functions like filter,
partition-by and split-with. You would be right; that is the whole
point.

Anyway, you certainly don't need to know any of this stuff to code
Clojure, and I do agree that is a strength of the language compared
to, say, Haskell.

-Per

On Thu, Mar 18, 2010 at 3:13 AM, David Nolen  wrote:
> On Wed, Mar 17, 2010 at 4:09 PM, Konrad Hinsen 
> wrote:
>>
>> On 17 Mar 2010, at 20:54, David Nolen wrote:
>>
>>> But seriously, in my personal opinion Monads are relatively useless in
>>> the context of Clojure.
>>
>> I'd say that in any impure functional language, monads are useful in the
>> context of specific applications or algorithmic approaches. When working
>> with continuations, or when writing complex parsers, monads are useful. It's
>> just Haskell that has a language-specific relation to monads, because it
>> needs them for fundamental tasks such as I/O.
>
> James, and Konrad sorry if I sounded overly dismissive of Monads ;) Yes for
> parsers, continuations, other tricky problems they provide a very elegant
> solution.
>
> David
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


Re: Long post with some questions about getting started...

2010-03-19 Thread Mike Meyer
On Fri, 19 Mar 2010 18:26:24 -0700
Terje Norderhaug  wrote:
> >
> > *) InterLISP and some others were more like SmallTalk, or MS BASIC, in
> >that you edited code at the REPL and saved the entire
> >workspace. That did add power - I've never seen a file-based LISP
> >whose error handler would let me fix the code on the fly and
> >continue execution.
> 
> Possibly I am misunderstanding

So to clarify: by "file-based LISP" I mean one where the code is
stored in text files. If it's read in and parsed, you can still get to
the S-expressions, but there's generally no easy way to get them back
into the text file; the REPL is just a REPL. The alternative is
residential systems (InterLISP is the one I'm most familiar with),
where the source code lives in workspaces, which are basically virtual
machines running lisp code. To save your work, you saved the memory
image of the vm; ascii output of the source was for reading, not
editing.

The file-based systems I'm used to would let you examine the code in a
break, and chose a return value for any arbitrary function on the
stack. You generally couldn't edit the code that was being
executed. You could reload functions in a break, but that generally
didn't replace bindings that were instantiated on the stack. The
workspace versions let you edit the code in the workspace, changing it
in situ. You could even save the workspace at that point.

> "I've never seen a file-based LISP  
> whose error handler would let me fix the code on the fly and continue  
> execution" but that sounds like common practice in the REPL break  
> loop for many lisps.

More likely is that I'm just out of date. I obviously haven't seen
every LISP around, and in particular quit paying close attention to
LISP systems in the early 90s. Clojure brought me back to that world.

If that's the case, I have to wonder how many of them grew features
comparable to masterscope, the programmers assistant, or even DWIM?

 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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


  1   2   >