Multicore-programming workshop in Paris

2008-12-08 Thread Konrad Hinsen

I just received the following announcement. I think a presentation on  
Clojure could fit in well, so if someone geographically close and  
competent is interested...

Konrad.


Begin forwarded message:

> Resent-From: [EMAIL PROTECTED]
> From: Jean Roman <[EMAIL PROTECTED]>
> Date: December 5, 2008 11:39:19 CEST
> To: [EMAIL PROTECTED]
> Cc: Jean Roman <[EMAIL PROTECTED]>
> Subject: [calcul]  Journée "multicoeurs" : déclarations d'intention  
> demandées
> Reply-To: [EMAIL PROTECTED]
>
> Cher collègue,
>
> Vous êtes cordialement invité à participer et/ou présenter une  
> communication aux journées transverses "multicœur" des 4-5  
> février.  Pour plus d'infos sur ces journées, voir ci-dessous.
>
> Afin d'avancer dans l'organisation, je vous prie de bien vouloir  
> envoyer TRÈS RAPIDEMENT à l'adresse  [EMAIL PROTECTED]> un courriel pour préciser :
>
> - votre intention de participer à ces journées
> - éventuellement votre proposition de communication (avec un titre,  
> et si possible un résumé)
>
> Ces journées rassembleront l'ensemble des communautés intéressées  
> par les nouvelles architectures, les réseaux d'interconnexion, les  
> modèles de mémoire faibles, les systèmes et les logiciels de base,  
> la tolérance aux pannes et l'auto-configuration, les langages et  
> méthodes de programmation, la conception et la preuve des  
> programmes parallèles, les mémoires transactionnelles et les  
> techniques de calcul spéculatif, la portabilité des performances et  
> la localité, l'analyse et la prédiction de performances, et les  
> expériences applicatives des nouvelles architectures multi-cœur.
>
> Quatre exposés invités marqueront ces journées, par Dimitri  
> Komatitsch, Maurice Herlihy, Koen De Bosschere et John Reppy.
>
> Les journées sont organisées par l'INRIA (co-organisation par le  
> GDR ASR en discussion).  Voir l'annonce ci-dessous ou sur  pagesperso-systeme.lip6.fr/Marc.Shapiro/multicoeurs-2009-02/>.
>
> Cordialement,
>
>   M. Shapiro
>
> PS Prière de faire suivre aux collègues et sur les listes d'envoi  
> concernés.
>
> --
>
>
>   Appel à communications
>   Journées « Informatique Massivement Multiprocesseur et 
> Multicœur »
>
>   Paris, 4-5 février 2009
>
> La révolution du parallélisme est en cours. Les processeurs  
> modernes comptent plusieurs cœurs d'exécution ; les processeurs à  
> plusieurs centaines ou milliers de cœurs sont en vue. En même  
> temps, l'hétérogénéité, les hiérachies mémoire et les réseaux  
> d'interconnexion sont de plus en plus complexes.
> Ces nouvelles architectures posent de nombreux problèmes. Combien  
> de cœurs, où placer les mémoires, comment les interconnecter ?  
> Quelle tolérance aux pannes, quel modèle de programmation, quel  
> langage, pour profiter des avantages du parallélisme et pallier ses  
> inconvénients ? Comment former les programmeurs d'application au  
> non-déterminisme, au contrôle de concurrence, à la communication  
> asynchrone, à l'information incomplète, aux accès mémoire non  
> uniformes, à la tolérance aux pannes, etc. ? Comment assurer la  
> portabilité des performances des programmes entre modèles ou  
> générations de machine ?
>
> La démocratisation des architectures multi-cœur confère une  
> pertinence accrue à ces problèmes anciens. Les journées ont pour  
> objet de faire le point de la recherche, des résultats récents, et  
> des perspectives matérielles et logicielles. Vous êtes invité à  
> proposer une communication, en particulier sur les thèmes suivants  
> (liste non exhaustive) :
>
>   • Architectures processeur, mémoire, et d'interconnexion
>   • Modèles de mémoire relâchés
>   • Multi-cœur et systèmes enfouis ou temps réel
>   • Système d'exploitation pour le multi-cœur, scheduling, gestion  
> de la température et de la consommation électrique
>   • Auto-configuration, tolérance aux fautes
>   • Langages, modèles et outils de programmation pour le multi-cœur
>   • Conception correcte et preuve de programmes hautement parallèles
>   • Mémoires transactionnelles, programmation spéculative,  
> abstractions de haut niveau
>   • Localité et portabilité des performances
>   • Analyse et prédiction de performance
>   • Expériences applicatives sur multi-cœur
>
> Thèmes envisagés pour les scéances de discussion :
>   • Multi-cœur et applications : quelles «killer apps», quel impact  
> des architectures multi-cœur hétérogènes sur les applications ?
>   • Multi-cœur et langage : quels paradigmes, quelles mécanismes de  
> programmation pour le parallélisme, le parallélisme pour les  
> masses, analyse statique
> Exposés invités :
>   • Dimitri Komatitsch, Université de Pau (France), Porting a high- 
> order finite-element earthquake modeling application to NVIDIA  
> graphics cards using CU

Re: linux, named pipe (fifo) and (while ...)

2008-12-08 Thread Samantha Atkins


On Dec 7, 2008, at 4:12 PM, prhlava wrote:

>
>
>> You're asking for the pipe to be repeatedly opened, one  
>> uninterrupted glob of bytes read and processed and then the pipe  
>> closed. Is that really what you intend?
>
> Yes, that was my intention, maybe a rethink is in order...
>
>> As written, this suggest a kind of "daemon" that monitors the pipe,
>> waiting for successive writers, each of which must write everything
>> they want processed by the far side in a single write call and
>> furthermore that transmission must not exceed the operating system's
>> pipe high-water mark. All this seems a bit fragile to me.
>>
>> But more practically, you should _say_ what you want your code to
>> accomplish.
>
> Store e-mail messages in a database (I am porting a program that
> already does this, as an exercise) + making it work through pipe (as
> java start-up is longish) => therefore I will have submitter and
> "daemon" receiver...

Why not just stream it into a JDBC Blob to your database?   Is there  
some reason the mail to be stored needs to be read remotely to the  
machine storing messages to the database BTW?

- samantha


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-08 Thread prhlava


Hello Randall,

> If your application is client/server, you really should just go with an
> ordinary TCP connection (or, conceivably, a UDP port), define a proper
> protocol and do the whole thing properly.

This makes sense (if done right, the submitter can be invoked several
times in parallel and submit
more than one e-mail in parallel to the daemon - and this is needed).

> Realistically, I'd start by looking at the ordinary Servlet /
> HttpServlet mechanism. You get so much from existing servlet containers
> (Tomcat, Jetty, GlassFish, etc.) that it's very hard to justify
> starting from scratch.

Will see if I learn how to deploy clojure application in a Tomcat
container...

> Named pipes have peculiar semantics and, of course, do not cross machine
> boundaries (unless you're running in one of the now-rare distributed
> Unix kernels—I say this as a one-time employee of Locus Computing
> Corporation...). I can't say named pipes really useful for much other
> than their use by shells for their <( command ) syntax.

So it looks that named pipe does not cut it here.

Thanks for all the info, and I can proceed in other way(s) now...

But would you not expect that the working code still works when
enclosed in the "while" construct?

Kind regards,

Vlad

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Thanks for Clojure

2008-12-08 Thread Rich Hickey



On Dec 6, 11:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:

> I've moved pretty much all my spare-time projects over to clojure and
> it's been a pleasure so far. It's a nice piece of work. It seemed
> appropriate to say thanks for it. So thanks!

You're quite welcome!

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-08 Thread prhlava


Hello Samantha,

> Why not just stream it into a JDBC Blob to your database?

The "daemon" does more than just storing it in the database (it is
basicaly a postfix mail filter something like spamassassin in
principle, but does different things with the e-mails).

>   Is there  some reason the mail to be stored needs to be read remotely to the
> machine storing messages to the database BTW?

It goes to a database server - so potentialy it could be also read
(from database) on the machine doing the storing...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Thanks for Clojure

2008-12-08 Thread [EMAIL PROTECTED]

+1 on all the thanks.  I haven't had this much fun learning a new
language since school!  You da' man Rich!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Emacs / Slime questions

2008-12-08 Thread Shawn Hoover
On Sun, Dec 7, 2008 at 10:03 PM, Mark Engelberg <[EMAIL PROTECTED]>wrote:

>
> Thanks for all the info.  I've searched my whole hard drive for a
> .emacs file, and can't find one.  Can someone tell me where Clojure
> Box stores this file, or whether it's called something entirely
> different?
>

Clojure Box's startup is controlled by default.el in the emacs\site-start
directory under the installation. You can put your own initialization in
.emacs, but you have to create it. Type C-x C-f and enter ~/.emacs. Edit the
file and save it with C-x C-s. The ~ in the file name will most likely
expand to the application data directory under your user profile.

Shawn

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: reduction

2008-12-08 Thread Rich Hickey



On Dec 7, 4:10 pm, Christophe Grand <[EMAIL PROTECTED]> wrote:
> Rich Hickey a écrit :> I think the problem is that in the original and 
> subsequent versions,
> > work was being done in the current case that needn't be (checking the
> > status of coll), and that we need more laziness than lazy-cons gives
> > us (we need to delay evaluation of one argument to the recursive
> > call). delay/force offer laziness a la carte
>
> Thanks Rich! I wasn't aware that (force x) returns x if x is not a
> Delay, this is good to know. (I assume that having seq to automatically
> force its argument would be a perf killer.)

It's less the perf than that it is a different model, e.g. (delay nil)
is logical true. Using delays internally is one thing, but were they
to leak out, it would break the seq/no-seq(nil) model, and instead
require all use of seqs to force or be wrapped in macros that do the
forcing. I'm not saying that's wrong, but I thought it would be more
cumbersome than the current model which abstracts CL's cons cells.

In practice, we've ended up with more calls to seq than I envisioned,
mostly to allow fns to work with anything seq-able, so must seq on
entry, but there are still plenty of places where it is convenient not
to have to call seq, and directly test the sequence in conditionals,
and few where not having seqs be universally (potentially) delayed is
a hindrance.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Non-NS-qualified hierarchies

2008-12-08 Thread Rich Hickey



On Dec 7, 9:01 am, Mibu <[EMAIL PROTECTED]> wrote:
> Is it possible to remove the asserts in derive that restrict the
> parent and child to namespace-qualified names?
>
> It would be much more useful if the asserts are moved to the global-
> hierarchy case ([child parent]) and the "private" hierarchies ([h
> child parent]) can do as they wish.

Added to todo[1] - patch welcome

[1] http://richhickey.backpackit.com/pub/1597914

Rich


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: List comprehension: :when AND :while for the same binding?

2008-12-08 Thread Rich Hickey



On Dec 6, 7:52 pm, André Thieme <[EMAIL PROTECTED]> wrote:
> (for [x (range 1 20) :when (> x 8) :while (< 0 (rem x 13))] x) ==>
> java.lang.Exception: Unsupported binding form: :while
>
> But:
> (for [x (range 1 20) :when (> x 8)] x) ==>
> (9 10 11 12 13 14 15 16 17 18 19)
>
> And:
> (for [x (range 1 20) :while (< 0 (rem x 13))] x) ==>
> (1 2 3 4 5 6 7 8 9 10 11 12)
>
> Is it intended that there can be at most one condition per binding?

That's how it is currently implemented, but I'm for allowing both.

Added to todo[1] - patch welcome

[1] http://richhickey.backpackit.com/pub/1597914

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Implementing .toString from Clojure

2008-12-08 Thread Jeff Rose

I've got a Clojure library based around a custom data structure stored 
in a struct.  When printing I'd like to override the default string 
output for structs, but I'm not sure how to implement  the .toString 
method used by (str ...) from Clojure.  Anyone know how to do this?

It would be cool if all the Java methods behind Clojure were implemented 
using multi-methods that dispatch on the type of the first argument, and 
then probably use some proxy on the Java side to be able to call into 
Clojure.

-Jeff

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Thanks for Clojure

2008-12-08 Thread Geoffrey Teale
2008/12/8 [EMAIL PROTECTED] <[EMAIL PROTECTED]>

>
> +1 on all the thanks.  I haven't had this much fun learning a new
> language since school!  You da' man Rich!
>

I can see this is going to get gratuitous, but another thanks from me.

I spent a good part of the weekend changing over some Qt-Jambi based code to
use the new (:gen-class) stuff - and whilst it was a lot of work I had an
immense amount of fun.   I guess it's a question of presenting me with the
right kind of problems, but still, it's an awful lot of fun.

-- 
Geoffrey Teale
Freelance Software and Technology Consultant
Munich, Germany

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Non-NS-qualified hierarchies

2008-12-08 Thread J. McConnell
On Mon, Dec 8, 2008 at 9:05 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> On Dec 7, 9:01 am, Mibu <[EMAIL PROTECTED]> wrote:
>> Is it possible to remove the asserts in derive that restrict the
>> parent and child to namespace-qualified names?
>>
>> It would be much more useful if the asserts are moved to the global-
>> hierarchy case ([child parent]) and the "private" hierarchies ([h
>> child parent]) can do as they wish.
>
> Added to todo[1] - patch welcome

I believe this should do it.

- J.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

Index: src/clj/clojure/core.clj
===
--- src/clj/clojure/core.clj	(revision 1147)
+++ src/clj/clojure/core.clj	(working copy)
@@ -3045,13 +3045,14 @@
   child can be either a namespace-qualified symbol or keyword or a
   class. h must be a hierarchy obtained from make-hierarchy, if not
   supplied defaults to, and modifies, the global hierarchy."
-  ([tag parent] (alter-var-root #'global-hierarchy derive tag parent) nil)
-  ([h tag parent]
+  ([tag parent]
(assert (not= tag parent))
(assert (or (class? tag) (and (instance? clojure.lang.Named tag) (namespace tag
(assert (instance? clojure.lang.Named parent))
(assert (namespace parent))
 
+   (alter-var-root #'global-hierarchy derive tag parent) nil)
+  ([h tag parent]
(let [tp (:parents h)
  td (:descendants h)
  ta (:ancestors h)


Calling superclass methods from implemented methods

2008-12-08 Thread Matt Revelle

I'm working on a patch to add support for calling the superclass'  
implementation of a method when overriding a method in Clojure with  
ns/:genclass.  This looks like it requires a modification of the  
InstanceMethodExpr class in clojure.lang.Compiler.  The proposed  
syntax would be: (. super/MethodFoo this args).  One issue is that  
using super/MethodFoo to refer to the superclass' method means that  
(.super/MethodFoo this args) wouldn't work without more Parser changes.

I'm close to finishing this, but would like to get feedback before  
spending more time.  Thoughts?

-Matt

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Thanks for Clojure

2008-12-08 Thread bnb


I had been dabbling in Common Lisp for awhile and finally purchased
LispWorks.  Four days later(11-18-08) I discovered Clojure and was
captured.  Since then I have spent over 90% of my time in learning
Clojure...Enclojure...Netbeans...Emacs...Clojure
Box...Java...Ant...etc.

Thanks Rich.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: List comprehension: :when AND :while for the same binding?

2008-12-08 Thread Chouser

On Mon, Dec 8, 2008 at 9:06 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> On Dec 6, 7:52 pm, André Thieme <[EMAIL PROTECTED]> wrote:
>> (for [x (range 1 20) :when (> x 8) :while (< 0 (rem x 13))] x) ==>
>> java.lang.Exception: Unsupported binding form: :while
>>
>> But:
>> (for [x (range 1 20) :when (> x 8)] x) ==>
>> (9 10 11 12 13 14 15 16 17 18 19)
>>
>> And:
>> (for [x (range 1 20) :while (< 0 (rem x 13))] x) ==>
>> (1 2 3 4 5 6 7 8 9 10 11 12)
>>
>> Is it intended that there can be at most one condition per binding?
>
> That's how it is currently implemented, but I'm for allowing both.

doseq currently supports both.  If both appear on the same binding,
the :while is always test first regardless of the order in which they
appear in the doseq.  The thinking is that if the :while is false,
there's no need to check the :when.

Is this Good, and should 'for' work the same way?

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



parens in use function

2008-12-08 Thread Mark Volkmann

I have some questions about the following:

(use '[clojure.contrib.str-utils :only (str-join)])

Why is the vector quoted? Is that because we need to quote everything
inside the vector? If so, what does it mean to quote the keyword
:only?

Why is the parameter to the use function a vector?

Why can't the third item in the vector, (str-join), be specified with
the symbol str-join instead of a list?

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Calling superclass methods from implemented methods

2008-12-08 Thread Geoffrey Teale
2008/12/8 Matt Revelle <[EMAIL PROTECTED]>

>
> I'm working on a patch to add support for calling the superclass'
> implementation of a method when overriding a method in Clojure with
> ns/:genclass.  This looks like it requires a modification of the
> InstanceMethodExpr class in clojure.lang.Compiler.  The proposed
> syntax would be: (. super/MethodFoo this args).  One issue is that
> using super/MethodFoo to refer to the superclass' method means that
> (.super/MethodFoo this args) wouldn't work without more Parser changes.
>
> I'm close to finishing this, but would like to get feedback before
> spending more time.  Thoughts?
>

Interesting.   I was actually looking for this functionality the other day.
The form you describe is almost exactly what I would expect.

I have found that the new (:gen-class) post AOT leads quite naturally to a
OOP style of programming when interacting Qt-Jambi.   I'm torn as to whether
this is a good or a bad thing (it may be neither, just a reality).
Realising this certainly made doing this kind of work more intuitive - and
(super) would actually solve some problems for me.

-- 
Geoffrey Teale
Freelance Software and Technology Consultant
Munich, Germany

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: List comprehension: :when AND :while for the same binding?

2008-12-08 Thread Rich Hickey



On Dec 8, 10:08 am, Chouser <[EMAIL PROTECTED]> wrote:
> On Mon, Dec 8, 2008 at 9:06 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> > On Dec 6, 7:52 pm, André Thieme <[EMAIL PROTECTED]> wrote:
> >> (for [x (range 1 20) :when (> x 8) :while (< 0 (rem x 13))] x) ==>
> >> java.lang.Exception: Unsupported binding form: :while
>
> >> But:
> >> (for [x (range 1 20) :when (> x 8)] x) ==>
> >> (9 10 11 12 13 14 15 16 17 18 19)
>
> >> And:
> >> (for [x (range 1 20) :while (< 0 (rem x 13))] x) ==>
> >> (1 2 3 4 5 6 7 8 9 10 11 12)
>
> >> Is it intended that there can be at most one condition per binding?
>
> > That's how it is currently implemented, but I'm for allowing both.
>
> doseq currently supports both.  If both appear on the same binding,
> the :while is always test first regardless of the order in which they
> appear in the doseq.  The thinking is that if the :while is false,
> there's no need to check the :when.
>
> Is this Good, and should 'for' work the same way?
>

Yes.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: parens in use function

2008-12-08 Thread Meikel Brandmeyer

Hi,

On 8 Dez., 16:32, "Mark Volkmann" <[EMAIL PROTECTED]> wrote:
> I have some questions about the following:
>
> (use '[clojure.contrib.str-utils :only (str-join)])
>
> Why is the vector quoted? Is that because we need to quote everything
> inside the vector?

You don't have to quote the vector:

(use ['clojure.contrib.str-utils :only '(str-join)])

So yes: quoting the vector quotes everything inside.

> If so, what does it mean to quote the keyword :only?

Nothing. ':only is the equivalent to :only. If you quote everything
else
you can leave the :only alone.

> Why is the parameter to the use function a vector?

It's not necessarily a vector:

(use 'clojure.contrib.str-utils)
(use '(clojure.contrib str-utils def))
(use '(clojure.contrib str-utils [def :only (defvar defstruct-)]))

The vector is used to associate parameters like
:only or :as to a given namespace.

> Why can't the third item in the vector, (str-join), be specified with
> the symbol str-join instead of a list?

It is possible to specify multiple arguments here (see above
example). Providing a non-list argument as a synonym for
a list containing this single argument is maybe possible. I'm
not familiar with the implementation, though. So I don't know
how easy it is to include this.

Another point I'd like to raise (when we are talking about use
and require): Shouldn't require check, whether a namespace
already exists instead of keeping its own list of loaded
namespaces?

Sincerely
Meikel


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



_Programming Clojure_ sample code on github, with unit tests

2008-12-08 Thread Stuart Halloway

Hi all,

I have placed the sample code for _Programming Clojure_ on github, at 
http://github.com/stuarthalloway/programming-clojure 
. Most of the code samples now have unit tests, using Stuart Sierra's  
test-is.

If you see an erratum in the book that you suspect was caused by  
changes to Clojure, you can check this repository to see if it is  
already fixed. Currently the tests all pass with Clojure r1146 and  
Clojure-contrib r285.

Also, if you are porting an existing test suite to use the newer test- 
is (circa r283), you can view the diff at [1] to see the kinds of  
changes you would need to make.

Cheers,
Stuart

[1] 
http://github.com/stuarthalloway/programming-clojure/commit/d6f85a67be24fd9ada5d4df233a491ba56732ae1

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Calling superclass methods from implemented methods

2008-12-08 Thread Rich Hickey



On Dec 8, 9:30 am, Matt Revelle <[EMAIL PROTECTED]> wrote:
> I'm working on a patch to add support for calling the superclass'
> implementation of a method when overriding a method in Clojure with
> ns/:genclass.  This looks like it requires a modification of the
> InstanceMethodExpr class in clojure.lang.Compiler.  The proposed
> syntax would be: (. super/MethodFoo this args).  One issue is that
> using super/MethodFoo to refer to the superclass' method means that
> (.super/MethodFoo this args) wouldn't work without more Parser changes.
>
> I'm close to finishing this, but would like to get feedback before
> spending more time.  Thoughts?
>

I would set aside the syntax and first describe the mechanism. Are you
going to generate a super-calling version of every method? Are you
going to try to emit code to generate invokespecial in the
implementing fn? The latter won't work as there is no type
relationship.

It might be easier to just enhance the :exposes to handle methods as
well, or add a  :supers section.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Misplaced doc strings in clojure.contrib.seq-utils

2008-12-08 Thread Perry Trolard

In clojure.contrib.seq-utils, partition-by & group-by have docstrings
following their arglists, so (doc parition-by) prints

-
clojure.contrib.seq-utils/partition-by
([f coll])
  nil
nil

I'd submit a patch, but I'm sure it's easier if Stuart Sierra or
another of the contrib committers just swith 'em around.

Best,
Perry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: parens in use function

2008-12-08 Thread Mark Volkmann

On Mon, Dec 8, 2008 at 9:45 AM, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> On 8 Dez., 16:32, "Mark Volkmann" <[EMAIL PROTECTED]> wrote:
>> I have some questions about the following:
>>
>> (use '[clojure.contrib.str-utils :only (str-join)])
>>
>> Why is the vector quoted? Is that because we need to quote everything
>> inside the vector?
>
> You don't have to quote the vector:
>
> (use ['clojure.contrib.str-utils :only '(str-join)])
>
> So yes: quoting the vector quotes everything inside.
>
>> If so, what does it mean to quote the keyword :only?
>
> Nothing. ':only is the equivalent to :only. If you quote everything
> else
> you can leave the :only alone.
>
>> Why is the parameter to the use function a vector?
>
> It's not necessarily a vector:
>
> (use 'clojure.contrib.str-utils)
> (use '(clojure.contrib str-utils def))
> (use '(clojure.contrib str-utils [def :only (defvar defstruct-)]))

It seems that this part

[def :only (defvar defstruct-)]

must be a vector and not a list.

I'm finding it a little difficult to remember all the allowed
permutations. Hopefully over time this will become second nature for
me, but I'm not there yet.

> The vector is used to associate parameters like
> :only or :as to a given namespace.
>
>> Why can't the third item in the vector, (str-join), be specified with
>> the symbol str-join instead of a list?
>
> It is possible to specify multiple arguments here (see above
> example). Providing a non-list argument as a synonym for
> a list containing this single argument is maybe possible. I'm
> not familiar with the implementation, though. So I don't know
> how easy it is to include this.

I'd really like it if that were supported. It seems that most examples
I see of using :only have a single function in the list that follows.
Supporting this would be in keeping with the Clojure tendency to
eliminate unnecessary parens.

> Another point I'd like to raise (when we are talking about use
> and require): Shouldn't require check, whether a namespace
> already exists instead of keeping its own list of loaded
> namespaces?

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Calling superclass methods from implemented methods

2008-12-08 Thread Matt Revelle

The original plan was to use the super keyword to signal that  
invokespecial should be used.  Now that you mention the lack of type  
relationship, that problem is obvious.  I suppose adding a :supers is  
what I'll do.

-Matt

On Dec 8, 2008, at 10:59 AM, Rich Hickey wrote:

>
>
>
> On Dec 8, 9:30 am, Matt Revelle <[EMAIL PROTECTED]> wrote:
>> I'm working on a patch to add support for calling the superclass'
>> implementation of a method when overriding a method in Clojure with
>> ns/:genclass.  This looks like it requires a modification of the
>> InstanceMethodExpr class in clojure.lang.Compiler.  The proposed
>> syntax would be: (. super/MethodFoo this args).  One issue is that
>> using super/MethodFoo to refer to the superclass' method means that
>> (.super/MethodFoo this args) wouldn't work without more Parser  
>> changes.
>>
>> I'm close to finishing this, but would like to get feedback before
>> spending more time.  Thoughts?
>>
>
> I would set aside the syntax and first describe the mechanism. Are you
> going to generate a super-calling version of every method? Are you
> going to try to emit code to generate invokespecial in the
> implementing fn? The latter won't work as there is no type
> relationship.
>
> It might be easier to just enhance the :exposes to handle methods as
> well, or add a  :supers section.
>
> Rich
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: parens in use function

2008-12-08 Thread Meikel Brandmeyer

Hi,

On 8 Dez., 17:03, "Mark Volkmann" <[EMAIL PROTECTED]> wrote:
> I'm finding it a little difficult to remember all the allowed
> permutations. Hopefully over time this will become second nature for
> me, but I'm not there yet.

I'm sticking mostly with the way in your example. I structure my
:use and :require parameters for ns normally in using multiple lines.

(ns foo.bar
  (:use
clojure.contrib.def
[clojure.contrib.str-utils :only (str-join)]))

Adding another namespace from clojure.contrib is as easy as
copying a line and changing the last part. Since this kind of
code isn't touched very often, I can live with that. So I don't
use the (name.space a b c) version very often.

Sincerely
Meikel


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Math as multimethods

2008-12-08 Thread Mark Fredrickson

>
>> Alternatively, could I provide a "multi-
>> math" lib to redefine the core math functions?
>
> Type classes would be king.

Do you mean this in the Haskell sense? (I'm not too familiar with  
those) Or something more like Java's types? I was thinking about how  
to solve this problem more generally and was considering an interface,  
but nothing obvious came to mind. Java's lack of operator overloading  
makes this more difficult I think.

> But at least you can use your definition :
>
> (ns test.test
>  (:refer-clojure :exclude [+ -]))
>
> (defn +
>  [a b]
>  33)
>
> (+ 1 2) ;= 33

Thanks for the suggestion, this will give me a chance to play around  
with multi-method and see what I think.

Cheers,
-Mark


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running clojure-contrib.jar

2008-12-08 Thread janus

Hi All,

It is working now. I found that I followed the instruction provided by
the author blindly, it was not meant for the windows box(vista) I am
using. The problem is on path separation, the book used forward slash
instead of backward slash.
The solution:
SET CLASSPATH=\clojure\clojure\clojure.jar;\clojure\clojure\clojure-
contrib.jar;\clojure\clojure\code
java  clojure.lang.Repl


This is book what I found in the book(for windows users):
SET CLASSPATH=/jars/clojure.jar;\
/jars/clojure-contrib.jar;\
/path/to/book/code
java clojure.lang.Repl


However, I still get error when I try to do (require
'example.introduction)
Error Message: Cloud not locate Clojure resource on classpath: example/
introduction/introduction.clj


Thanks so your help in the past.

Emeka
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: My Clojure Emacs Setup (I'll show mine if you show yours)

2008-12-08 Thread Kyle R. Burton

I was wondering, since Emacs knows the file name (or at least the
buffer name) and line number it's sending a form from, and Clojure
represents that as meta-data (I think), could C-x C-e send that along
somehow wrapped in a form that sets these particular values for the
form that was shipped over?  Some kind of equivalent to #line and
#file (form C/C++/Perl)?

Is that possible?

Kyle

On Sun, Dec 7, 2008 at 12:07 AM, Bill Clementson <[EMAIL PROTECTED]> wrote:
>
> On Fri, Dec 5, 2008 at 5:23 PM, Mon Key <[EMAIL PROTECTED]> wrote:
>>
>> Nice blog entry :)
>
> Thanks! :)
>
>> My setup tends to mirror yours esp. as I've culled most of it from
>> your blog over the years...
>> Most of my startup scripts are modified versions of those you've
>> shared elsewhere.
>
> Glad you've found my posts useful.
>
> - Bill
>
> >
>



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



Re: parens in use function

2008-12-08 Thread Mark Volkmann

On Mon, Dec 8, 2008 at 10:12 AM, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> On 8 Dez., 17:03, "Mark Volkmann" <[EMAIL PROTECTED]> wrote:
>> I'm finding it a little difficult to remember all the allowed
>> permutations. Hopefully over time this will become second nature for
>> me, but I'm not there yet.
>
> I'm sticking mostly with the way in your example. I structure my
> :use and :require parameters for ns normally in using multiple lines.
>
> (ns foo.bar
>  (:use
>clojure.contrib.def
>[clojure.contrib.str-utils :only (str-join)]))

Ah ... this reminds me of another question I had. Why is the "use"
function specified with the keyword ":use" when it's inside an ns
function, but not when it is outside an ns function?

> Adding another namespace from clojure.contrib is as easy as
> copying a line and changing the last part. Since this kind of
> code isn't touched very often, I can live with that. So I don't
> use the (name.space a b c) version very often.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running clojure-contrib.jar

2008-12-08 Thread Randall R Schulz

On Monday 08 December 2008 08:17, janus wrote:
> ...
>
>
> However, I still get error when I try to do
> (require 'example.introduction) 
> Error Message: Cloud not locate Clojure resource on classpath:
> example/introduction/introduction.clj

Then you haven't given or have given an incorrect path name for the book 
code.

By the way, which version of Clojure are you running? Doesn't that 
diagnostic come from the old implementation of (require ...)?

As mentioned in the Programming Clojure book (PDF), its examples require 
the SVN version of Cloure, not the "release" version (the latter having 
time-stamps in their names, the latest being 2008/09/16 or Sep. 16).


> Thanks so your help in the past.
>
> Emeka


Randall Schulz

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running clojure-contrib.jar

2008-12-08 Thread Stuart Halloway

Hi Emeka,

Two problems here:

(1) You are using an old version of Clojure. You will need to build  
Clojure and Clojure-contrib from SVN in order to work through the book  
examples.

(2) It is examples (plural) not example (singular).

Also, what version of the book are you working from? The most recent  
is Beta 3.

Regards,
Stuart

>
> Hi All,
>
> It is working now. I found that I followed the instruction provided by
> the author blindly, it was not meant for the windows box(vista) I am
> using. The problem is on path separation, the book used forward slash
> instead of backward slash.
> The solution:
> SET CLASSPATH=\clojure\clojure\clojure.jar;\clojure\clojure\clojure-
> contrib.jar;\clojure\clojure\code
> java  clojure.lang.Repl
>
>
> This is book what I found in the book(for windows users):
> SET CLASSPATH=/jars/clojure.jar;\
> /jars/clojure-contrib.jar;\
> /path/to/book/code
> java clojure.lang.Repl
>
>
> However, I still get error when I try to do (require
> 'example.introduction)
> Error Message: Cloud not locate Clojure resource on classpath:  
> example/
> introduction/introduction.clj
>
>
> Thanks so your help in the past.
>
> Emeka
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: BUG: resultset-seq breaks on duplicate column names

2008-12-08 Thread Michael Reid

Has anybody else hit this?

I just did. Its not tricky to alter resultset-seq to return maps with
qualified keys:

(defn resultset-seq
 "Creates and returns a lazy sequence of structmaps corresponding to
  the rows in the java.sql.ResultSet rs"
  [#^java.sql.ResultSet rs]
(let [rsmeta (. rs (getMetaData))
  idxs (range 1 (inc (. rsmeta (getColumnCount
  keys (map (comp keyword (memfn toLowerCase))
-(map (fn [i] (. rsmeta (getColumnName i))) idxs))
+   (map (fn [i] (str (. rsmeta (getTableName i)) "."
(. rsmeta (getColumnName i idxs))
  row-struct (apply create-struct keys)
  row-values (fn [] (map (fn [#^Integer i] (. rs (getObject i))) idxs))
  rows (fn thisfn []
   (when (. rs (next))
 (lazy-cons (apply struct row-struct (row-values))
(thisfn]
  (rows)))

Of course now all keys come back as qualified, breaking anything that
relied on the old behaviour. It also wouldn't be too hard to make this
return qualified keys only when there are duplicate column names, as
demonstrated by Allen.

Another thought I had would be to pass a flag to specify if you want
qualified keys which defaults to false--this way you get the old
behaviour unless you ask for/need qualified keys.

Rich, would you consider a patch to make resultset-seq more robust to
handle cases with duplicate column names?

/mike.

On Sat, Oct 11, 2008 at 12:21 PM, Allen Rohner <[EMAIL PROTECTED]> wrote:
>
> If you create a SQL query that returns duplicate names, resultset-seq
> throws an exception: "java.lang.RuntimeException:
> java.lang.IllegalArgumentException: Too many arguments to struct
> constructor"
>
> i.e.
>
> (let [rs (query "select description,description from table")]
>   (resultset-seq rs)
>
> The following patch adds a method duplicate-col-names? which returns
> true if the resultset contains duplicate column names, and modifies
> resultset-seq to throw an exception if there are duplicate column
> names.
>
> As an aside, now that clojure has real libraries, it seems that
> boot.clj is not the best place for the resultset code.
>
> Allen
>
> Index: src/clj/clojure/boot.clj
> ===
> --- src/clj/clojure/boot.clj(revision 1060)
> +++ src/clj/clojure/boot.clj(working copy)
> @@ -1901,10 +1901,26 @@
> (clojure.lang.LineNumberingPushbackReader.))]
> (load-reader rdr)))
>
> +(defn set
> +  "Returns a set of the distinct elements of coll."
> +  [coll] (apply hash-set coll))
> +
> +(defn duplicate-col-names? [#^java.sql.ResultSet rs]
> +  "returns true if the columns in the result set contain duplicate
> names"
> +  (let [rsmeta (. rs (getMetaData))
> +   idxs (range 1 (inc (. rsmeta (getColumnCount
> +   keys (map (comp keyword (memfn toLowerCase))
> + (map (fn [i] (. rsmeta (getColumnName i))) idxs))
> +   unique-keys (set keys)]
> +(not (= (count keys) (count unique-keys)
> +
> +
>  (defn resultset-seq
>   "Creates and returns a lazy sequence of structmaps corresponding to
>   the rows in the java.sql.ResultSet rs"
>   [#^java.sql.ResultSet rs]
> +  (when (duplicate-col-names? rs)
> +(throw (Exception. "resultset-seq does not handle queries with
> duplicate column names")))
> (let [rsmeta (. rs (getMetaData))
>   idxs (range 1 (inc (. rsmeta (getColumnCount
>   keys (map (comp keyword (memfn toLowerCase))
> @@ -1916,10 +1932,6 @@
> (lazy-cons (apply struct row-struct (row-values)) 
> (thisfn]
>   (rows)))
>
> -(defn set
> -  "Returns a set of the distinct elements of coll."
> -  [coll] (apply hash-set coll))
> -
>  (defn #^{:private true}
>   filter-key [keyfn pred amap]
> (loop [ret {} es (seq amap)]
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running clojure-contrib.jar

2008-12-08 Thread janus

Stuart
> (1) You are using an old version of Clojure. You will need to build  
> Clojure and Clojure-contrib from SVN in order to work through the book  
> examples.
When I tried (require 'clojure.contrib.str-utils)
I got 'nil' which shows that all is well. I downloaded the most recent
binary version
> (2) It is examples (plural) not example (singular).
It was typo.
>
> Also, what version of the book are you working from? The most recent  
> is Beta 3.
>
 I use the most recent. File name shcloj-b3_0.pdf


Emeka


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running clojure-contrib.jar

2008-12-08 Thread Michael Wood

On Mon, Dec 8, 2008 at 7:31 PM, janus <[EMAIL PROTECTED]> wrote:
>
> Stuart
>> (1) You are using an old version of Clojure. You will need to build
>> Clojure and Clojure-contrib from SVN in order to work through the book
>> examples.
> When I tried (require 'clojure.contrib.str-utils)
> I got 'nil' which shows that all is well. I downloaded the most recent
> binary version

The most recent binary version is a few months old.  Lots has changed
since then.  You will need to checkout the source code from Subversion
and compile it.  As long as you have the JDK and a Subversion client
this is very easy to do.

>> (2) It is examples (plural) not example (singular).
> It was typo.
>>
>> Also, what version of the book are you working from? The most recent
>> is Beta 3.
>>
>  I use the most recent. File name shcloj-b3_0.pdf

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Blogs | Yahoo Pipes | Clojure Pipe

2008-12-08 Thread Phil Hagelberg


Dan Larkin <[EMAIL PROTECTED]> writes:
> It's been mentioned before but I'd like to see a planet.clojure.org à
> la the planet planet powered sites (http://www.planetplanet.org/).

I do a lot of work with feeds; I've been toying with the idea of porting
Planet to Clojure. We use the Rome feed parsing library at work via
JRuby, but I've done a bit to hook it up to Clojure and it seems to work
fine.

The problem is, as Bill mentioned above, not many folks blog exclusively
about Clojure, and not all blog software supports feeds on a per-tag
basis. But that doesn't mean we shouldn't set something like this up;
sometimes it's nice to get a bigger slice of the community.

Anyway, I'll post here again when I've got something working. If anyone
wants to help with coding "Planet Clojure", let me know. Not that it's a
hard task, but this is my first Clojure code.

-Phil
http://technomancy.us

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



java build it HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava


Hello again,

I am trying to use java built in HttpServer and it looks that the
handle method of HttpHandler interface does not get called at all (but
the server "works" - returns a blank page, which is expected as I do
not write anything in the handle method).

The following example is minimal implementation (cut down version of
the original code), what I do not understad is why the "handle" method
of HttpHandler interface does not get called at all. (I would expect
the server to print "exchange" object to the shell window on every
request handled.)

; imports omitted

(def port )

(def handler (proxy [HttpHandler] []
   (handle [#^HttpExchange exchange]
   (println exchange

(let [server (. HttpServer create (new InetSocketAddress port) 0)]
  (. server createContext "/" handler)
  (. server setExecutor (. Executors newCachedThreadPool))
  (. server start)
  (print "server listening on port: ")(println port)
  )

Is the proxy route wrong for this and I should use gen-class instead?

Kind regards,

Vlad

PS: The HttpHandler is an interface with one method called "handle".
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java build it HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava

Oops,

The subject should have read:

java built in HTTP server, proxy and HttpHandler interface...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Java vararg functions called from Clojure

2008-12-08 Thread Tom Emerson

Calling Java vararg functions seems to be less transparent in Clojure interop:

(String/format "%03d" 5)

java.lang.ClassCastException: java.lang.Integer cannot be cast to
[Ljava.lang.Object; (NO_SOURCE_FILE:0)
  [Thrown class clojure.lang.Compiler$CompilerException]

while

(String/format "%03d" (to-array '(5)))

works as you would expect.

I just wanted to make sure I wasn't missing something. Perhaps
something along the lines of

(defn format-string
  [fmt & args]
  (String/format fmt (to-array args)))

would be useful in string-utils.

-tree

-- 
Tom Emerson
[EMAIL PROTECTED]
http://www.dreamersrealm.net/~tree

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Math as multimethods

2008-12-08 Thread ppierre

On 8 déc, 17:14, Mark Fredrickson <[EMAIL PROTECTED]>
wrote:
> >> Alternatively, could I provide a "multi-
> >> math" lib to redefine the core math functions?
>
> > Type classes would be king.
>
> Do you mean this in the Haskell sense?
Yes :  http://www.haskell.org/tutorial/classes.html
Haskell make a dispatch on type at runtime.

> > (ns test.test
> >  (:refer-clojure :exclude [+ -]))
>
> > (defn +
> >  [a b]
> >  33)
>
> > (+ 1 2) ;= 33
>
> Thanks for the suggestion,

You can "overload" core function :
(binding [clojure.core/compare (constantly 1)]
 (sort [1 5 2 6])) ;(6 2 5 1)

But it wouldn't work  if the function is inline.
(binding [clojure.core/= (constantly false)]
  [(= 1)
   (= 1 1)
   (not= 1 1)
  ])  ; [false true false]

> this will give me a chance to play around  
> with multi-method and see what I think.

I'm not sure, but :
defmethod macro simply call addMethod on clojure.lang.MultiFn object.
So you can add method from an other namespace.

Basically, you would build something like type class.
But it wouldn't play nice with core operator.

pierre
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Java vararg functions called from Clojure

2008-12-08 Thread Stephen C. Gilardi


On Dec 8, 2008, at 1:34 PM, Tom Emerson wrote:


I just wanted to make sure I wasn't missing something. Perhaps
something along the lines of

(defn format-string
 [fmt & args]
 (String/format fmt (to-array args)))


Hi Tom,

Good call on it being a convenient function to have around. It's  
available as clojure.core/format. There's also printf along the same  
lines.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Java vararg functions called from Clojure

2008-12-08 Thread Randall R Schulz

On Monday 08 December 2008 10:53, Stephen C. Gilardi wrote:
> On Dec 8, 2008, at 1:34 PM, Tom Emerson wrote:
> > I just wanted to make sure I wasn't missing something. Perhaps
> > something along the lines of
> >
> > (defn format-string
> >  [fmt & args]
> >  (String/format fmt (to-array args)))
>
> Hi Tom,
>
> Good call on it being a convenient function to have around. It's
> available as clojure.core/format. There's also printf along the same
> lines.

Correct me if I'm wrong or insufficiently aware of the relevant issues, 
but is it not the case that such a helper function has an easier job 
for Format since it wants an array of Object. In other contexts, you 
have to know what the type of the array elements are to construct an 
acceptable varargs array.

So would it not be the case that to be generic a varargs array-builder 
would have to use reflection on the target method?


> --Steve


Randall Schulz

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Extending Clojure's STM with external transactions

2008-12-08 Thread Dave Griffith

Okay, hacking complete.  I've got a patch that extends the Clojure STM
so that it will make appropriate callouts to an external transaction
manager that cause the STMs transaction to be atomic/consistent/
isolated with respect to an external transaction, using a "dosync-
external" macro.  Note that this is not the same as XA support.  The
Clojure STM is in charge of the transaction as a whole, not the
external transaction manager.  (Among other things, this means that
transactions can not span multiple transaction managers.  You'll get
an exception if you try.) The external transaction manager must
implement the clojure.lang.ITransactionManager interface, which means
that to use any given external transaction manager you will need to
implement a small adapter to that interface, and instantiate it
appropriately.

This code is highly experimental, and should not be used for
production purposes.  Contents may have settled during shipping. All
models over 18.

Where should I send the patch?

--Dave Griffith
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: List comprehension: :when AND :while for the same binding?

2008-12-08 Thread Chouser

On Mon, Dec 8, 2008 at 10:42 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> On Dec 8, 10:08 am, Chouser <[EMAIL PROTECTED]> wrote:
>>
>> doseq currently supports both.  If both appear on the same binding,
>> the :while is always test first regardless of the order in which they
>> appear in the doseq.  The thinking is that if the :while is false,
>> there's no need to check the :when.
>>
>> Is this Good, and should 'for' work the same way?
>>
>
> Yes.

I'll take a look at this tonight, unless someone beats me to it.

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Java vararg functions called from Clojure

2008-12-08 Thread Tom Emerson

On Mon, Dec 8, 2008 at 1:53 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
> Good call on it being a convenient function to have around. It's available
> as clojure.core/format. There's also printf along the same lines.

Steve, that is probably the most politely worded, "Read the API docs
you git!" I've come across. Thanks for pointing the obvious to me. :)

-tree

-- 
Tom Emerson
[EMAIL PROTECTED]
http://www.dreamersrealm.net/~tree

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Patch to add doc string support to defmulti [Was: (doc)strings after param in defn]

2008-12-08 Thread J. McConnell
On Fri, Dec 5, 2008 at 9:22 AM, Randall R Schulz <[EMAIL PROTECTED]> wrote:
>
> On Thursday 04 December 2008 23:23, Meikel Brandmeyer wrote:
>> Hi,
>>
>> On 5 Dez., 00:38, Randall R Schulz <[EMAIL PROTECTED]> wrote:
>>
>> > And am I mistaken in my reading of the API docs for (defmulti ...)
>> > and (defmethod ...) or is there no accommodation in either for
>> > doc-strings? Surely that's not the case, right?
>>
>> You can always use:
>>
>>   (defmulti #^{:arglists '([a b] [a b c]) :doc "bla"} foo identity)
>
> Why all the circumlocutions to bring a multimethod up to the level of
> documentation support of a plain function?

Attached is a patch that adds doc-string and metadata support to
defmulti. It does not generate arglists metadata automatically like
defn does since the arglists are not supplied in the defmulti form as
they are in defn. One possibility would be to see if the dispatch
function has an :arglists entry in its metadata and use that if it
does, but I did not include that here since it opens up the
possibility that the :arglists and :doc entries could get out of sync.

Below is a sample usage of the new doc-string support. I'd be
interested to hear people's thoughts.

Regards,

- J.

kant[~/src/clojure]$ iclj
1:1 user=> (defmulti fib "Calculates the nth value of the fib sequence"
 {:arglists '([n])}
 int)
#'user/fib
1:3 user=> (defmethod fib 0 [_] 0)
#
1:4 user=> (defmethod fib 1 [_] 1)
#
1:5 user=> (defmethod fib :default [n] (+ (fib (- n 2)) (fib (- n 1
#
1:6 user=> (map fib (range 10))
(0 1 1 2 3 5 8 13 21 34)
1:7 user=> (doc fib)
-
user/fib
([n])
 Calculates the nth value of the fib sequence
nil
1:8 user=> (meta (var fib))
{:line 1, :file "repl-1", :doc "Calculates the nth value of the fib
sequence", :arglists ([n]), :tag clojure.lang.MultiFn, :name fib, :ns
#}

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

Index: src/clj/clojure/core.clj
===
--- src/clj/clojure/core.clj	(revision 1147)
+++ src/clj/clojure/core.clj	(working copy)
@@ -175,26 +175,37 @@
(recur (conj ret (first s)) (rest s))
(seq ret)
 
-(def 
+(def
+  #^{:private true
+ :arglists '([fdecl])
+ :doc "Extracts optional doc string and attr-maps from function
+  declarations. Returns a vector containing the attr-map and the
+  rest of the function declaration."}
+  extract-attrs (fn extract-attrs [fdecl]
+  (let [m (if (string? (first fdecl))
+{:doc (first fdecl)}
+{})
+fdecl (if (string? (first fdecl))
+(rest fdecl)
+fdecl)
+m (if (map? (first fdecl))
+(conj m (first fdecl))
+m)
+fdecl (if (map? (first fdecl))
+(rest fdecl)
+fdecl)]
+[m fdecl])))
 
+(def
  #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
 name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
 to the var metadata"
 :arglists '([name doc-string? attr-map? [params*] body]
 [name doc-string? attr-map? ([params*] body)+ attr-map?])}
  defn (fn defn [name & fdecl]
-(let [m (if (string? (first fdecl))
-  {:doc (first fdecl)}
-  {})
-  fdecl (if (string? (first fdecl))
-  (rest fdecl)
-  fdecl)
-  m (if (map? (first fdecl))
-  (conj m (first fdecl))
-  m)
-  fdecl (if (map? (first fdecl))
-  (rest fdecl)
-  fdecl)
+(let [fdecl (extract-attrs fdecl)
+  m (first fdecl)
+  fdecl (second fdecl)
   fdecl (if (vector? (first fdecl))
   (list fdecl)
   fdecl)
@@ -986,16 +997,28 @@
   ([x form & more] `(-> (-> ~x ~form) [EMAIL PROTECTED])))
 
 ;;multimethods
-(defmacro defmulti
+(defmacro
+  defmulti
   "Creates a new multimethod with the associated dispatch function. If
   default-dispatch-val is supplied it becomes the default dispatch
   value of the multimethod, otherwise the default dispatch value
   is :default."
-  ([name dispatch-fn] `(defmulti ~name ~dispatch-fn :default))
-  ([name dispatch-fn default-val]
-   `(def ~(with-meta name (assoc ^name :tag 'clo

Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread J. McConnell

On Sun, Dec 7, 2008 at 10:51 AM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
> 1. More "is" predicates, including regular expressions and "thrown-
> with-msg?"

Great! Will the planned thrown-with-msg? support regex matching? I
used something like that in clojure.contrib.test-clojure.evaluation,
which was pretty handy.

Regards,

- J.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Lazy sequences without caching?

2008-12-08 Thread Stephan Mühlstrasser

Hi,

for one of the problems from Project Euler I implemented a "triangle
numbers" lazy sequence after the blueprint of the fibonacci numbers
sequence in clojure.contrib.lazy-seqs:. When taking large numbers of
items from this  equence, I get an out-of-memory exception:

user=> (def triangle-numbers
(let [rest-fn
(fn rest-fn [current cumulated]
(let [next (+ current cumulated)]
  (lazy-cons next (rest-fn (inc current) next]
(rest-fn 1 0)))
#'user/triangle-numbers
user=> (nth triangle-numbers 100)
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
at java.math.BigInteger.add(BigInteger.java:1068)
at java.math.BigInteger.add(BigInteger.java:1041)
at clojure.lang.Numbers$BigIntegerOps.add(Numbers.java:793)
at clojure.lang.Numbers.add(Numbers.java:127)
at user.fn__2290$rest_fn__2292.invoke(Unknown Source)
at user.fn__2290$rest_fn__2292$fn__2294.invoke(Unknown Source)
at clojure.lang.LazyCons.rest(LazyCons.java:60)
at clojure.lang.RT.nth(RT.java:702)
at clojure.nth__440.invoke(boot.clj:830)
at user.eval__2303.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:3891)
at clojure.lang.Repl.main(Repl.java:75)

If I understand it correctly this is the effect of the caching of the
lazy sequence. Is there a way to suppress the  caching? Are there
alternatives in Clojure for representing and processing very large
sequences?

Thanks
Stephan

P.S.: I read the recent thread "memory issue with nth", but it is not
clear to me whether this is the same problem.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread Frantisek Sodomka

> 2. "each=" and "all-true" are gone, replaced by the new macro "are",
> which works with any predicate:
> (are =
>   2 (+ 1 1)
>   4 (+ 2 2))
>
> -Stuart Sierra

Hello and thanks for additions!

Happy to see additions and work done on tests :-)

I just wonder - how do you define "all-true" using "are"? Since "are"  
always makes pairs for predicate, it might not be possible.

(defn logically-true? [x]
   (if x true false))

(are logically-true?
   43
   "abc"
   true
   (not false)
   (not nil))

My guess: Fails because logically-true? accepts only 1 argument and (not  
nil) never gets tested even if predicate accepts 2 arguments ("are"  
doesn't test for odd number of params).

Possible solution: Add another number-of-arguments parameter to "are":

(are 2 =
   (+ 1 2) 3
   (+ 1 -1) 0 )

(are 1 logically-true?
   43
   "abc"
   true
   (not false)
   (not nil))

Also [syntactic sugar]:
   (are 1 pred? ...) could be (are-all pred? ...)
   (are 2 pred? ...) could be (are-pairs pred? ...)


Thanks for considering these ideas, Frantisek

PS: Still writing tests - latest are 'and', 'or', 'first', 'rest',  
'ffirst'.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Math as multimethods

2008-12-08 Thread Michael Reid

I've been toying with something similar. The approach I took was to
define multi-methods for the various operators:

(defmulti add class)
(defmulti sub class)
(defmulti mul class)
(defmulti div class)
 ...

Then I of course write the implementations for various different
types. Then, because the multi-method names don't look nice, I wrote a
macro which transformed the regular operators into calls on the
multi-methods, i.e.:

 (macroexpand-1 '(extended-math (* 3 A))) --> (mul 3 A)

Its still not as clean as a having the operators defined as
multi-methods from the get-go, but you don't have to muck with
overriding the core names.

One reason to leave the core operators alone is performance.
Multi-method dispatch is far more expensive than a regular dispatch. I
don't have this in front of me to get some real numbers, but when I
tested, the same operations with the multi-methods were about 10x
slower than the direct dispatch.

/mike.

On Mon, Dec 8, 2008 at 1:50 PM, ppierre <[EMAIL PROTECTED]> wrote:
>
> On 8 déc, 17:14, Mark Fredrickson <[EMAIL PROTECTED]>
> wrote:
>> >> Alternatively, could I provide a "multi-
>> >> math" lib to redefine the core math functions?
>>
>> > Type classes would be king.
>>
>> Do you mean this in the Haskell sense?
> Yes :  http://www.haskell.org/tutorial/classes.html
> Haskell make a dispatch on type at runtime.
>
>> > (ns test.test
>> >  (:refer-clojure :exclude [+ -]))
>>
>> > (defn +
>> >  [a b]
>> >  33)
>>
>> > (+ 1 2) ;= 33
>>
>> Thanks for the suggestion,
>
> You can "overload" core function :
> (binding [clojure.core/compare (constantly 1)]
>  (sort [1 5 2 6])) ;(6 2 5 1)
>
> But it wouldn't work  if the function is inline.
> (binding [clojure.core/= (constantly false)]
>  [(= 1)
>   (= 1 1)
>   (not= 1 1)
>  ])  ; [false true false]
>
>> this will give me a chance to play around
>> with multi-method and see what I think.
>
> I'm not sure, but :
> defmethod macro simply call addMethod on clojure.lang.MultiFn object.
> So you can add method from an other namespace.
>
> Basically, you would build something like type class.
> But it wouldn't play nice with core operator.
>
> pierre
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava


Well, it turns out that the following works, but it only prints the
"exchange" to stdout,
if the code is cut and pasted to the REPL but _not_ if run as .clj
script)...

(import
 '(java.io IOException)
 '(java.io OutputStream)
 '(java.util Iterator)
 '(java.util List)
 '(java.util Set)
 '(com.sun.net.httpserver Headers)
 '(com.sun.net.httpserver HttpExchange)
 '(com.sun.net.httpserver HttpHandler)
 '(java.net InetSocketAddress)
 '(java.util.concurrent Executors)
 '(com.sun.net.httpserver HttpServer)
 )

(def port )

(let [server (. HttpServer create (new InetSocketAddress port) 0)
  handler (proxy [HttpHandler] []
(handle [#^HttpExchange exchange]
(println exchange) ; this does not get printed if run 
as script
(but it does if all of the code is pasted to the REPL)
(. exchange close)
))
  ]
  (. server createContext "/" handler)
  (. server setExecutor (. Executors newCachedThreadPool))
  (. server start)
  (print "server listening on port: ")(println port)
  )

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch to add doc string support to defmulti [Was: (doc)strings after param in defn]

2008-12-08 Thread Chouser

On Mon, Dec 8, 2008 at 3:40 PM, J. McConnell <[EMAIL PROTECTED]> wrote:
>
> Attached is a patch that adds doc-string and metadata support to
> defmulti. It does not generate arglists metadata automatically like
> defn does since the arglists are not supplied in the defmulti form as
> they are in defn. One possibility would be to see if the dispatch
> function has an :arglists entry in its metadata and use that if it
> does, but I did not include that here since it opens up the
> possibility that the :arglists and :doc entries could get out of sync.
>
> Below is a sample usage of the new doc-string support. I'd be
> interested to hear people's thoughts.

This is a breaking change for some (granted rather unsual) cases:

(defmulti foo {:a 1 :b 2})
(defmethod foo 1 [_] "got a1")
(defmethod foo 2 [_] "got b2")

Before patch:

user=> (foo :a)
"got a1"
user=> (foo :b)
"got b2"

After patch:

user=> (foo :a)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user=> (foo :b)
java.lang.NullPointerException (NO_SOURCE_FILE:0)

You can see what happened to our dispatch map:

user=> ^#'foo
{:tag clojure.lang.MultiFn, :name foo, :file "NO_SOURCE_FILE", :ns
#, :line 1, :b 2, :a 1}

I'm not offering an opinion here on whether or not it's a good patch,
just wanted to point out it changes currently defined behavior.

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Is it possible to tell programatically if I'm in a transactional context?

2008-12-08 Thread Dave Griffith

I gave a small talk on Clojure this afternoon to my team.  It went
well, and got the expected oohs and ahhs with respect to the potential
of software transactional memory.  One question asked, though, was
about I/O in software transactions.  It was clear to everyone why I/O
needed to be prohibitted in transactions, but questions were raised as
to whether there was any way to actually prevent it.  Looking through
the API, I couldn't find any way of detecting when execution was
occuring in a transactional context or not.

--Dave Griffith
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-08 Thread Kyle R. Burton

On Mon, Dec 8, 2008 at 5:18 PM, prhlava <[EMAIL PROTECTED]> wrote:
>
>
> Well, it turns out that the following works, but it only prints the
> "exchange" to stdout,
> if the code is cut and pasted to the REPL but _not_ if run as .clj
> script)...

I have gotten your example to work with a bit of reading and
modification (and thank you, I was after an example http server, this
got me going):

(import
 '(java.io IOException OutputStream)
 '(java.util Iterator List Set)
 '(com.sun.net.httpserver Headers HttpExchange HttpHandler)
 '(java.net InetSocketAddress)
 '(java.util.concurrent Executors)
 '(com.sun.net.httpserver HttpServer))

(defn handle-http-exchange [#^HttpExchange exchange]
  (try
   (do
 (let [hdrs (.getResponseHeaders exchange)]
   (.add hdrs "Content-type: " "text/plain"))
 (.sendResponseHeaders exchange 200 0)
 (let [out (java.io.PrintStream. (.getResponseBody exchange))]
   (.println out (str "Time time is: " (java.util.Date.)))
   (.close out)))
   (catch Throwable ex
 (println (str "Error: " ex)

(defn start-server [port]
  (let [server (. HttpServer create (new InetSocketAddress port) 0)
handler (proxy [HttpHandler] []
  (handle [#^HttpExchange exchange]
  (handle-http-exchange exchange)))]
(. server createContext "/" handler)
(. server setExecutor (. Executors newCachedThreadPool))
(. server start)
(print "server listening on port: ")
(println port)
server))

(def server (start-server 8080))

;; (.stop server 0)


Regards,

Kyle R. Burton

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Is it possible to tell programatically if I'm in a transactional context?

2008-12-08 Thread Stuart Halloway

Hi Dave,

It looks like LockingTransaction.getRunning would need to be made  
public. What do you plan to do with it?

As a workaround:

  (defn in-tx? [] (try (ensure (ref true)) (catch  
IllegalStateException e false)))

Stuart

>
> I gave a small talk on Clojure this afternoon to my team.  It went
> well, and got the expected oohs and ahhs with respect to the potential
> of software transactional memory.  One question asked, though, was
> about I/O in software transactions.  It was clear to everyone why I/O
> needed to be prohibitted in transactions, but questions were raised as
> to whether there was any way to actually prevent it.  Looking through
> the API, I couldn't find any way of detecting when execution was
> occuring in a transactional context or not.
>
> --Dave Griffith
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-08 Thread Kyle R. Burton

> I have gotten your example to work with a bit of reading and
> modification (and thank you, I was after an example http server, this
> got me going):


A bit more hacking and it's possible to add/replace handlers after the
server has been started:

(import
 '(java.io IOException OutputStream)
 '(java.util Iterator List Set)
 '(com.sun.net.httpserver Headers HttpExchange HttpHandler)
 '(java.net InetSocketAddress)
 '(java.util.concurrent Executors)
 '(com.sun.net.httpserver HttpServer))

(defmacro with-response-print-stream [http-exchange var resp-code
content-type & body]
  (let [ex-var (gensym)
hdrs-var (gensym)]
`(try
  (do
(let [~hdrs-var (.getResponseHeaders ~http-exchange)]
  (.add ~hdrs-var "Content-type: " ~content-type))
(.sendResponseHeaders ~http-exchange ~resp-code 0)
(let [~var (java.io.PrintStream. (.getResponseBody
~http-exchange))]
  [EMAIL PROTECTED]
  (.close ~var)))
  (catch Throwable ~ex-var
(println (str "Error: " ~ex-var))

(defn start-server [port]
  (let [server (. HttpServer create (new InetSocketAddress port) 0)]
(.setExecutor server (. Executors newCachedThreadPool))
(.start server)
server))

(defn server-add-handler [#^HttpServer server context handler-fn]
  (let [handler (proxy [HttpHandler] []
  (handle [#^HttpExchange exchange]
  (handler-fn exchange)))]
(try
 (.removeContext server context)
 (catch Throwable ex
 :was-not-present))
(.createContext server context handler))
  nil)

(def server (start-server 8080))

(server-add-handler
 server
 "/"
 (fn [#^HttpExchange exchange]
   (with-response-print-stream exchange out 200 "text/html"
 (.println out (str "bold and italic"))
 (.println out (str "You should try: this, or that ")

(server-add-handler
 server
 "/stuff"
 (fn [#^HttpExchange exchange]
   (with-response-print-stream exchange out 200 "text/plain"
 (.println out (str "You are in the /stuff context, asking for: "
(.getRequestURI exchange))

(server-add-handler
 server
 "/time"
 (fn [#^HttpExchange exchange]
   (with-response-print-stream exchange out 200 "text/plain"
 (.println out (str "The time (at now) is: "
(java.util.Date.))

;; (.stop server 0)


I'm new to clojure so I'm sure this isn't good form, but it it useful
to me already.



Kyle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Lazy sequences without caching?

2008-12-08 Thread harrison clarke
you're keeping the head of the sequence, and thus all the elements between
the head and nth.

it's because you're using def, basically.

if you make a function to return the sequence, and pass the result directly
to nth, without let-binding it or anything, it should work.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Java vararg functions called from Clojure

2008-12-08 Thread Stephen C. Gilardi


On Dec 8, 2008, at 2:05 PM, Randall R Schulz wrote:

Correct me if I'm wrong or insufficiently aware of the relevant  
issues,

but is it not the case that such a helper function has an easier job
for Format since it wants an array of Object. In other contexts, you
have to know what the type of the array elements are to construct an
acceptable varargs array.


I was addressing "format" itself. In the case of any (manually  
written) Clojure wrapper for a Java variadic method, you would know  
the required type and could ensure it using:


(into-array the-type args).


So would it not be the case that to be generic a varargs array-builder
would have to use reflection on the target method?


Reflection to determine the array type seems necessary to accomplish  
that.


Another issue is how to distinguish a single argument at the varargs  
position between:


an array being passed as a single varargs argument itself, and
an array being passed containing the varargs arguments.

Java looks for a type match to the array type that corresponds to the  
varargs param type (e.g., Foo... -> Foo[]) to distinguish. I think  
Clojure could do the same.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: List comprehension: :when AND :while for the same binding?

2008-12-08 Thread Chouser
On Mon, Dec 8, 2008 at 10:42 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> On Dec 8, 10:08 am, Chouser <[EMAIL PROTECTED]> wrote:
>>
>> doseq currently supports both.  If both appear on the same binding,
>> the :while is always test first regardless of the order in which they
>> appear in the doseq.  The thinking is that if the :while is false,
>> there's no need to check the :when.
>>
>> Is this Good, and should 'for' work the same way?
>>
>
> Yes.

The attached patch adds support for :when and :while on the binding
expression in 'for'.  The macro now parses its arguments using code
almost identical to 'doseq'.  I've changed some local names in 'for'
and 'doseq' where they are similar to each other, so that both have
what I believe to be more descriptive names.

If these extra renaming changes are undesirable, I can certainly
create a smaller patch.

I've also attached a set of tests that I used.  All but
While-and-When-Same-Binding behaved identically before and after my
changes to 'for'.

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

commit f21c3a14b2c5167bd643ab010851c602e5073c33
Author: Chouser <[EMAIL PROTECTED]>
Date:   Mon Dec 8 15:51:18 2008 -0500

Support :while and :when on same binding expressions in 'for'

diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 24c9d01..e84ec15 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -1473,20 +1473,22 @@
   bindings and filtering as provided by \"for\".  Does not retain
   the head of the sequence. Returns nil."
   [seq-exprs & body]
-  (let [binds (reduce (fn [binds p]
-(if (instance? clojure.lang.Keyword (first p))
-  (conj (pop binds) (apply assoc (peek binds) p))
-  (conj binds {:name (first p) :init (second p)})))
+  (let [groups (reduce (fn [groups p]
+(if (keyword? (first p))
+  (conj (pop groups) (apply assoc (peek groups) p))
+  (conj groups {:bind (first p) :seq (second p)})))
   [] (partition 2 seq-exprs))
-emit (fn emit [bind & binds]
-   `(loop [sq# (seq ~(:init bind))]
+emit (fn emit [group & more-groups]
+   `(loop [sq# (seq ~(:seq group))]
   (when sq#
-(let [~(:name bind) (first sq#)]
-  (when ~(or (:while bind) true)
-(when ~(or (:when bind) true)
-  ~(if binds (apply emit binds) `(do [EMAIL PROTECTED])))
+(let [~(:bind group) (first sq#)]
+  (when ~(or (:while group) true)
+(when ~(or (:when group) true)
+  ~(if more-groups
+ (apply emit more-groups)
+ `(do [EMAIL PROTECTED])))
 (recur (rest sq#)))]
-(apply emit binds)))
+(apply emit groups)))
 
 (defn dorun
   "When lazy sequences are produced via functions that have side
@@ -2385,8 +2387,6 @@
 		  (lazy-cat [EMAIL PROTECTED])))]
   (iter# ~coll
   
-
-
 (defmacro for
  "List comprehension. Takes a vector of one or more
  binding-form/collection-expr pairs, each followed by an optional filtering
@@ -2397,31 +2397,27 @@
 
  (take 100 (for [x (range 1) y (range 100) :while (< y x)]  [x y]))"
  ([seq-exprs expr]
-  (let [pargs (fn [xs]
-(loop [ret []
-   [b e & [w f & wr :as r] :as xs] (seq xs)]
-  (if xs
-(cond 
- (= w :when) (recur (conj ret {:b b :e e :f f :w :when}) wr)
- (= w :while) (recur (conj ret {:b b :e e :f f :w :while}) wr)
- :else (recur (conj ret {:b b :e e :f true :w :while}) r))
-(seq ret
-emit (fn emit [[{b :b f :f w :w} & [{ys :e} :as rses]]]
+  (let [to-groups (fn [seq-exprs]
+(reduce (fn [groups [k v]]
+  (if (keyword? k)
+(conj (pop groups) (assoc (peek groups) k v))
+(conj groups {:bind k :seq v})))
+[] (partition 2 seq-exprs)))
+emit (fn emit [[group & [{next-seq :seq} :as more-groups]]]
 		  (let [giter (gensym "iter__") gxs (gensym "s__")]
 		`(fn ~giter [~gxs]
-			 (when-first [~b ~gxs]
-   (if ~f
-			~(if rses
-			   `(let [iterys# ~(emit rses)
-  fs# (iterys# ~ys

Re: Working combination of .emacs, Aquamacs, swank-clojure, clojure-mode?

2008-12-08 Thread mosi

Hi Bill,
thank you for helping the beginners like me with the setup of emacs,
slime and clojure.
I tried first the official method described elsewhere on this forum -
ubuntu linux instructions.
Unsuccessful.
Following your instructions, the same issue, my linux emacs22 gets to
this point:

(add-classpath "file:install/swank-clojure/")
(require (quote swank))
(swank/ignore-protocol-version "2008-11-23")
(swank/start-server "/tmp/slime.10616" :encoding "iso-latin-1-unix")
Clojure
user=> nil
user=> nil
user=> "2008-11-23"
user=> Connection opened on local port  58654
58654
user=>

And waits for connection. The socket (or a file?) /tmp/slime. does
not exist. Connection time-out causes an error - waiting for slime
session to connect to swank server.
My impression is: the swank server never started. Probably swank-
clojure broken? I have the latest git version as of 07.12.2008.
Any ideas?
thanks a lot.
mosi


On Nov 18, 2:43 am, "Bill Clementson" <[EMAIL PROTECTED]> wrote:
> Hi Raffael,
>
> On Mon, Nov 17, 2008 at 4:21 PM, Raffael Cavallaro
>
> <[EMAIL PROTECTED]> wrote:
> > As the mention of Aquamacs in the title suggests, I'm on Mac OS X.
> > I've read Bill Clementson's Blog on setting up clojure, and I'm not
> > exactly a neophyte - I've been using slime with sbcl, openmcl, and
> > other lisps for years.
>
> > Nevertheless, even starting with an absolutely blank .emacs and
> > freshly downloaded copies of Aquamacs, clojure, swank-clojure, and
> > clojure-mode, the instructions in Bill's blog do not yield a working
> > clojure under slime.
>
> Unfortunately (or, fortunately, depending on your perspective),
> Clojure is a moving target and an emacs/slime configuration that
> worked one month ago will not necessarily work today.
>
> > I've managed to get M-x run-lisp to work with the more basic of the
> > two clojure modes out there, so Bill's shell script in and of itself
> > is not the problem at all (it also works fine from a terminal window).
> > However, I've never gotten slime to work, so somehow it doesn't play
> > nice with swank-clojure and/or clojure-mode and/or slime.
>
> > Is there anyone who would be willing to post an *actual* .emacs (not
> > "add this line...,"  .emacs files involve clobbering globals, so order
> > really does matter), and links to the *actual* versions of clojure,
> > slime, swank-clojure, and clojure-mode that together, produce a
> > functioning clojure under slime/Aquamacs?
>
> > As a side note, I might suggest that links to a combination of ever-
> > changing git repositories might not be the very best idea on a page
> > entitled "Getting Started." IOW, it might be a good idea to take a
> > known working combination of the above, zip them up and link to that
> > instead.
>
> Rather than ask someone to assemble a package and post it for you, it
> is usually nicer (and a better learning experience) if you list
> exactly what you did, and post the minimal config scripts that you
> tried out and which illustrate what didn't work for you. However,
> since I recently upgraded to the latest Clojure, I'll share what
> worked for me:
>
> 0. Delete (or move away) any old versions of the following (e.g. don't
> assume that something you downloaded a couple of days ago is ok to
> use)
> 1. Download latest Clojure from 
> svn:http://sourceforge.net/svn/?group_id=137961
> 2. Download latest clojure-mode & swank-clojure from 
> git:http://github.com/jochu/
> 3. Download latest slime from cvs:http://common-lisp.net/project/slime/
> 4. Download latest clojure-contrib from 
> svn:http://sourceforge.net/svn/?group_id=223136
> 5. Use ant to build clojure and clojure-contrib
> 6. Create a shell script (called "clojure") to launch clojure and put
> it in your PATH :
>
> #!/bin/sh -e
> java -server -cp /Users/bc/lisp/clojure/clojure/trunk/clojure.jar:\
> /Users/bc/lisp/clojure/clojure-contrib/trunk/clojure-contrib.jar:\
>      clojure.lang.Repl
>
> 7.  Put the following minimal setup in your .emacs file (adjusting the
> paths as necessary):
>
> (setq load-path (append (list "/Users/bc/lisp/clbuild/source/slime"
>                               "/Users/bc/lisp/clbuild/source/slime/contrib"
>                               "/Users/bc/lisp/clojure/clojure-mode"
>                               "/Users/bc/lisp/clojure/swank-clojure")
>                         load-path))
>
> (setq swank-clojure-binary "clojure")
>
> (require 'clojure-auto)
> (require 'swank-clojure-autoload)
>
> (defun run-clojure ()
>   "Starts clojure in Slime"
>   (interactive)
>   (slime 'clojure))
>
> (global-set-key [f5] 'run-clojure)
> (global-set-key [(control f11)] 'slime-selector)
>
> (add-hook 'slime-connected-hook 'slime-redirect-inferior-output)
>
> 8. Restart Aquamacs and press F5 - you should get a repl
>
> The above worked for me when I re-installed Clojure (with the latest
> AOT changes) a couple of days ago. If you have any problems with the
> above, post a reply with any errors you encountered as well as any
> d

Re: Is it possible to tell programatically if I'm in a transactional context?

2008-12-08 Thread Dave Griffith

The basic use case is as a guard for I/O, to prevent them from from
filling the disk/spamming the network accidentally in case of
transaction live-lock.  Probably a bit more paranoia than is idiomatic
in the dynamically-typed world, but there are domains where that's
necessary.  The workaround is perfectly fine, although it looks like
exposing a method in LockingTransaction would be more performant.

--Dave Griffith

On Dec 8, 6:07 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Hi Dave,
>
> It looks like LockingTransaction.getRunning would need to be made  
> public. What do you plan to do with it?
>
> As a workaround:
>
>   (defn in-tx? [] (try (ensure (ref true)) (catch  
> IllegalStateException e false)))
>
> Stuart
>
>
>
> > I gave a small talk on Clojure this afternoon to my team.  It went
> > well, and got the expected oohs and ahhs with respect to the potential
> > of software transactional memory.  One question asked, though, was
> > about I/O in software transactions.  It was clear to everyone why I/O
> > needed to be prohibitted in transactions, but questions were raised as
> > to whether there was any way to actually prevent it.  Looking through
> > the API, I couldn't find any way of detecting when execution was
> > occuring in a transactional context or not.
>
> > --Dave Griffith
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Mark Engelberg

Has anyone made progress on this bug?

The simplest form of the bug was this:
(defn splode [n]
   (doseq [i (filter #(= % 20) (map inc (range n)))]))

This blows the heap, but it shouldn't.

I find this deeply troubling, because if this doesn't work, it
undermines my faith in the implementation of lazy sequences, which are
quite ubiquitous in Clojure.  map and filter are written in the most
natural way in boot.clj, so if they don't work properly, it means that
anything written with lazy-cons is suspect.

I have an idea to try, but I'm not set up to build the java sources on
my computer, so maybe someone else can run with it:

Right now, LazyCons.java takes one function which includes both the
knowledge of how to create the first and the rest.
Perhaps LazyCons.java needs to be implemented so that the constructor
take two separate functions, one that generates the first, and one
that generates the rest.  This way, as soon as the first is generated,
it can be cached, and the first-generating-function can be set to
null.  Similarly, when the rest is generated, it will be cached, and
its generating function can be set to null.  So if the problem is
being caused by the first-generating-function keeping something alive
that needs to be garbage collected, this would solve it, by releasing
it as soon as possible.

The lazy-cons macro in boot.clj wouldl also need to be changed to call
the new LazyCons constructor with two functions, rather than just one.

Of course, if the problem is that the rest-generating-function is
holding onto something, this will not solve the problem.

--Mark

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch to add doc string support to defmulti [Was: (doc)strings after param in defn]

2008-12-08 Thread J. McConnell
On Mon, Dec 8, 2008 at 5:35 PM, Chouser <[EMAIL PROTECTED]> wrote:
>
> On Mon, Dec 8, 2008 at 3:40 PM, J. McConnell <[EMAIL PROTECTED]> wrote:
> >
> This is a breaking change for some (granted rather unsual) cases:
>
> (defmulti foo {:a 1 :b 2})
> (defmethod foo 1 [_] "got a1")
> (defmethod foo 2 [_] "got b2")

Or, worse yet:

(defmulti foo {:a {:b "B"}} {:c "C"})

Which would become ambiguous after this patch. Good catch, Chouser.

> I'm not offering an opinion here on whether or not it's a good patch,
> just wanted to point out it changes currently defined behavior.

Thanks for pointing that out. I did this mostly as a learning
experience, because it seemed like something that would be useful.
However, it's not something I have a need for at the moment, so I've
mostly gotten out of it what I was looking for :)

Before giving up on it, one approach that might work for now would be
to allow a doc-string, but not the attr-map. Since a string isn't a
valid parameter for the dispatch function, there would be no
possibility for ambiguity and I believe it is completely backwards
compatible. I've attached a patch that implements this. Sample usage:

1:7 user=> (defmulti #^{:arglists '([n])} fib "docs for fib" int)
#'user/fib
1:8 user=> (doc fib)
-
user/fib
([n])
  docs for fib
nil

Thoughts welcome. I'll be happy to implement any suggested changes.
If, on the other hand, there is no further interest in this, I'll let
it go since I don't have a need for it at the moment, anyhow. However,
it does seem like it would be nice if defmulti had similar doc support
to defn and defmacro.

Regards,

- J.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

Index: src/clj/clojure/core.clj
===
--- src/clj/clojure/core.clj	(revision 1147)
+++ src/clj/clojure/core.clj	(working copy)
@@ -991,11 +991,19 @@
   default-dispatch-val is supplied it becomes the default dispatch
   value of the multimethod, otherwise the default dispatch value
   is :default."
-  ([name dispatch-fn] `(defmulti ~name ~dispatch-fn :default))
-  ([name dispatch-fn default-val]
-   `(def ~(with-meta name (assoc ^name :tag 'clojure.lang.MultiFn)) 
- (new clojure.lang.MultiFn ~dispatch-fn ~default-val
+  ([name & fdecl]
+   (let [docs (if (string? (first fdecl)) {:doc (first fdecl)})
+ dispatch-fn (if docs (second fdecl) (first fdecl))
+ default-val (or (if docs (second (rest fdecl)) (second fdecl))
+ :default)]
+   `(def ~(with-meta name (conj (assoc ^name :tag 'clojure.lang.MultiFn) docs)) 
+ (new clojure.lang.MultiFn ~dispatch-fn ~default-val)
 
+(.setMeta (var defmulti)
+  (conj (meta (var defmulti)) 
+{:arglists '([name doc-string? dispatch-fn]
+ [name doc-string? dispatch-fn default-val])}))
+
 (defmacro defmethod
   "Creates and installs a new method of multimethod associated with dispatch-value. "
   [multifn dispatch-val & fn-tail]


Re: Working combination of .emacs, Aquamacs, swank-clojure, clojure-mode?

2008-12-08 Thread Bill Clementson

On Mon, Dec 8, 2008 at 4:29 PM, mosi <[EMAIL PROTECTED]> wrote:
> thank you for helping the beginners like me with the setup of emacs,
> slime and clojure.
> I tried first the official method described elsewhere on this forum -
> ubuntu linux instructions.
> Unsuccessful.
> Following your instructions, the same issue, my linux emacs22 gets to
> this point:
>
> (add-classpath "file:install/swank-clojure/")
> (require (quote swank))
> (swank/ignore-protocol-version "2008-11-23")
> (swank/start-server "/tmp/slime.10616" :encoding "iso-latin-1-unix")
> Clojure
> user=> nil
> user=> nil
> user=> "2008-11-23"
> user=> Connection opened on local port  58654
> 58654
> user=>
>
> And waits for connection. The socket (or a file?) /tmp/slime. does
> not exist. Connection time-out causes an error - waiting for slime
> session to connect to swank server.
> My impression is: the swank server never started. Probably swank-
> clojure broken? I have the latest git version as of 07.12.2008.
> Any ideas?
> thanks a lot.
> mosi

You said that you followed my instructions; however, the protocol
version that prints out in the inferior-lisp buffer is "2008-11-23".
In my version of SLIME (which is several days old) the protocol
version that prints out in the inferior-lisp buffer is "2008-12-02".
If you have a swank-clojure from 07.12.2008, I suspect (at least) your
SLIME install is older than that. Therefore, I would suggest that you
repeat steps 1-5 (from my original email) to make certain you really
have compatible versions of each package.

- Bill

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Paul Mooser

Is there a place we should file an official bug, so that Rich and the
rest of the clojure people are aware of it? I imagine that they may
have read this thread, but I'm not sure if there is an "official"
process to make sure these things get addressed.

As I said in a previous reply, it's not clear (to me, at least!) how
it matters if the function is holding on to the rest, since one first
and rest have been evaluated for a lazy cons cell, it sets "f" (the
function) to null. I realize that the sequence that represents rest at
that time might have a derivative version of the original sequence
(presumably one link further down the list!), but it has been my
assumption that it would not hold on to the whole thing forever, just
as long as it needs to, which seems correct.

If someone understands exactly what it is that is holding on to a
reference to the whole sequence, once we have a first match, can
someone explain the exact mechanism that is causing it, and why
nulling out "f" has no effect?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread MikeM

I share your concern about the LazyCons problem - hopefully Rich and
others are looking into this.

I have continued to experiment to see if I can gain some understanding
that might help with a solution.

The following is something I thought of today, and I'd like to see if
others get the same result:

(defmacro my-lzy-cons
"lazy cons by proxy"
[fbody rbody] `(proxy [clojure.lang.ISeq] []
  (first [] ~fbody)
  (rest [] ~rbody)
  (seq  [] ~'this)))


(defn my-map
"not fully a replacement for map, but enough to test splode"
[f coll] (when (seq coll)
(my-lzy-cons (f (first coll)) (my-map f (rest coll)

(defn my-splode [n]
   (doseq [i (filter #(= % 20) (my-map inc (range n)))]))

my-splode does not blow the heap for me with (my-splode 1000);
(splode 1000) does.

my-lzy-cons appears to be slow compared to LazyCons, so this probably
isn't a solution, but perhaps this will give someone some insight to
help improve LazyCons.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Stephen C. Gilardi


On Dec 8, 2008, at 7:45 PM, Mark Engelberg wrote:


I have an idea to try, but I'm not set up to build the java sources on
my computer, so maybe someone else can run with it:


This looked very promising to me. For one thing, I remembered that the  
root of the big chain of LazyCons objects in memory (as displayed by  
the YourKit profiler) was "f".


I gave it a try, though, and it didn't solve the problem.

I encourage someone else to try it as well. I'll continue to play with  
it later tonight.


My attempt is included below.

--Steve

Index: LazyCons.java
===
--- LazyCons.java   (revision 1147)
+++ LazyCons.java   (working copy)
@@ -15,11 +15,13 @@
 final public class LazyCons extends ASeq{
 final private static ISeq sentinel = new Cons(null, null);
 IFn f;
+IFn r;
 Object _first;
 ISeq _rest;

-public LazyCons(IFn f){
+public LazyCons(IFn f, IFn r){
this.f = f;
+   this.r = r;
this._first = sentinel;
this._rest = sentinel;
 }
@@ -43,6 +45,7 @@
{
throw new RuntimeException(ex);
}
+f = null;
}
return _first;
 }
@@ -57,13 +60,13 @@
//force sequential evaluation
if(_first == sentinel)
first();
-   _rest = RT.seq(f.invoke(null));
+   _rest = RT.seq(r.invoke());
}
catch(Exception ex)
{
throw new RuntimeException(ex);
}
-   f = null;
+   r = null;
}
return _rest;
 }


Index: core.clj
===
--- core.clj(revision 1147)
+++ core.clj(working copy)
@@ -410,7 +410,7 @@
   same node of the seq evaluates first/rest-expr once - the values  
they yield are

   cached."
  [first-expr & rest-expr]
- (list 'new 'clojure.lang.LazyCons (list `fn (list [] first-expr)  
(list* [(gensym)] rest-expr
+ (list 'new 'clojure.lang.LazyCons (list `fn [] first-expr) (list*  
`fn [] rest-expr)))


 ;(defmacro lazy-seq
 ;  "Expands to code which produces a seq object whose first is the



smime.p7s
Description: S/MIME cryptographic signature


Re: Math as multimethods

2008-12-08 Thread ppierre

On 8 déc, 23:13, "Michael Reid" <[EMAIL PROTECTED]> wrote:
> Then I of course write the implementations for various different
> types. Then, because the multi-method names don't look nice, I wrote a
> macro which transformed the regular operators into calls on the
> multi-methods, i.e.:
>
>  (macroexpand-1 '(extended-math (* 3 A))) --> (mul 3 A)
>
> Its still not as clean as a having the operators defined as
> multi-methods from the get-go, but you don't have to muck with
> overriding the core names.

I was trying to do it with namespace but :

ns scratch
(:refer-clojure :exclude [+ - * /])
(:use clojure.contrib.def))

(defalias * clojure.core/*)
(* 2 5)  ;  10

(defalias / clojure.core//)
;; #

Didn't find why it work in core.clj ???

> One reason to leave the core operators alone is performance.
> Multi-method dispatch is far more expensive than a regular dispatch. I
> don't have this in front of me to get some real numbers, but when I
> tested, the same operations with the multi-methods were about 10x
> slower than the direct dispatch.

Yes, but it give you some nice abstractions :
sort fallback to Comparable interface.
If not you would use sort-by and provide a function.

An other example :
public interface IPersistentVector extends Associative, Sequential,
IPersistentStack, Reversible
seq & co make Clojure nice and efficient.

But I didn't see a simple way to do it in Clojure (it self).

May be :

(gen-type
  :name AType
  :extends [Types...]
  :methods [aMethode names...])

(gen-instance
  :name AnInstance
  :extends [AType Types...])

(defmethod aMethode [#^AnInstance param]
  (print (param any:)))

(def aVar (AnInstance. {any: "Data"}))

(aMethode (aVar))

Some day, I would try to do it.

pierre
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Stephen C. Gilardi


On Dec 8, 2008, at 8:40 PM, Stephen C. Gilardi wrote:

This looked very promising to me. For one thing, I remembered that  
the root of the big chain of LazyCons objects in memory (as  
displayed by the YourKit profiler) was "f".


Now it's "r" and is listed as a "stack local".

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: A newbie question on Agents and ants

2008-12-08 Thread MattyDub

This talk was very informative, and I was glad for it.  There were
several informative things in the talk that I haven't seen documented
anywhere (like the explanation of the thread pools backing (send ...)
vs (send-off ...)).  But is there anyplace I could read this
information?  Is there anyplace I could read where *agent* is
documented, for example?  Other than buying Stuart's book? ;)  In
general, I prefer reading to watching videos - it's just a lot faster.
   Thanks again,
-Matt

On Dec 7, 8:07 am, "Michael Wood" <[EMAIL PROTECTED]> wrote:
> On Sun, Dec 7, 2008 at 6:04 PM, Dave Newton <[EMAIL PROTECTED]> wrote:
>
> > --- On Sun, 12/7/08, Michael Wood wrote:
> >> Is there an explanation that's a little smaller than 607MB?
>
> > The slides and the code?
>
> :)
>
> Ah, sorry.  Didn't see the slides link.
>
> --
> Michael Wood <[EMAIL PROTECTED]>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Stephen C. Gilardi
I think I finally see the problem. The "rest expression" in filter's  
call to lazy-cons has a reference to "coll" in it. That's all it takes  
for coll to be retained during the entire calculation of the rest.


(defn filter
  "Returns a lazy seq of the items in coll for which
  (pred item) returns true. pred must be free of side-effects."
  [pred coll]
(when (seq coll)
  (if (pred (first coll))
(lazy-cons (first coll) (filter pred (rest coll)))
(recur pred (rest coll)

The stye of fix that occurs to me involves peeling off coll from  
(frest coll) and (rrest coll) before continuing the lazy evaluation.


Posting so someone else can beat me to the answer. :-)

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Running out of memory when using filter?

2008-12-08 Thread Mark Engelberg

On Mon, Dec 8, 2008 at 5:56 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
> I think I finally see the problem. The "rest expression" in filter's call to
> lazy-cons has a reference to "coll" in it. That's all it takes for coll to
> be retained during the entire calculation of the rest.
>

Well, I had already tried this, eagerly evaluating the first and rest,
and it didn't help:

(defn map2
  [f coll]
  (when (seq coll)
(let [fcoll (first coll) rcoll (rest coll) ffcoll (f fcoll)]
  (lazy-cons ffcoll (map2 f rcoll)

(defn filter2
  "Returns a lazy seq of the items in coll for which
  (pred item) returns true. pred must be free of side-effects."
  [pred coll]
(when (seq coll)
  (let [fcoll (first coll) rcoll (rest coll)]
(if (pred fcoll)
  (lazy-cons fcoll (filter2 pred rcoll))
  (recur pred rcoll)

(defn splode [n]
  (doseq [document (filter2 #(= % 20) (map2 inc (range n)))]))

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Mark Engelberg

On Mon, Dec 8, 2008 at 5:56 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
> I think I finally see the problem. The "rest expression" in filter's call to
> lazy-cons has a reference to "coll" in it. That's all it takes for coll to
> be retained during the entire calculation of the rest.
>

Well, I had already tried this, eagerly evaluating the first and rest,
and it didn't help:

(defn map2
  [f coll]
  (when (seq coll)
(let [fcoll (first coll) rcoll (rest coll) ffcoll (f fcoll)]
  (lazy-cons ffcoll (map2 f rcoll)

(defn filter2
  "Returns a lazy seq of the items in coll for which
  (pred item) returns true. pred must be free of side-effects."
  [pred coll]
(when (seq coll)
  (let [fcoll (first coll) rcoll (rest coll)]
(if (pred fcoll)
  (lazy-cons fcoll (filter2 pred rcoll))
  (recur pred rcoll)

(defn splode [n]
  (doseq [document (filter2 #(= % 20) (map2 inc (range n)))]))

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread Stuart Sierra

On Dec 8, 5:06 pm, "Frantisek Sodomka" <[EMAIL PROTECTED]>
wrote:
> I just wonder - how do you define "all-true" using "are"? Since "are"  
> always makes pairs for predicate, it might not be possible.

Hi Frantisek,

The short answer is, you don't. :)  Just use "is" for now.  I'll
consider making (is (and ...)) a recognized form, though.

I'm not certain about "are" yet, but I figured I had to offer at least
a little sugar.  Maybe what it really needs is template-style
argument, like Rich has suggested for condp:

(are (pred %1 %2)
   a1 b1
   a2 b2)

-Stuart Sierra
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread Stuart Sierra

On Dec 8, 3:53 pm, "J. McConnell" <[EMAIL PROTECTED]> wrote:
> Great! Will the planned thrown-with-msg? support regex matching? I
> used something like that in clojure.contrib.test-clojure.evaluation,
> which was pretty handy.

Yes, that's where I got the idea.

-Stuart Sierra
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread J. McConnell

On Mon, Dec 8, 2008 at 9:24 PM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
> On Dec 8, 3:53 pm, "J. McConnell" <[EMAIL PROTECTED]> wrote:
>> Great! Will the planned thrown-with-msg? support regex matching? I
>> used something like that in clojure.contrib.test-clojure.evaluation,
>> which was pretty handy.
>
> Yes, that's where I got the idea.

Perfect, thanks! Looking forward to it.

- J.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



clojure-contrib documentation

2008-12-08 Thread Mark Volkmann

Is there a primary website that provides documentation and examples of
using the various libraries in clojure-contrib? My googling efforts
have come up empty so far. I'm particularly interested in learning
more about test-is at the moment.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running out of memory when using filter?

2008-12-08 Thread Rich Hickey


On Dec 8, 2008, at 8:56 PM, Stephen C. Gilardi wrote:

> I think I finally see the problem. The "rest expression" in filter's  
> call to lazy-cons has a reference to "coll" in it. That's all it  
> takes for coll to be retained during the entire calculation of the  
> rest.
>
> (defn filter
>  "Returns a lazy seq of the items in coll for which
>  (pred item) returns true. pred must be free of side-effects."
>  [pred coll]
>(when (seq coll)
>  (if (pred (first coll))
>(lazy-cons (first coll) (filter pred (rest coll)))
>(recur pred (rest coll)
>
> The stye of fix that occurs to me involves peeling off coll from  
> (frest coll) and (rrest coll) before continuing the lazy evaluation.
>
> Posting so someone else can beat me to the answer. :-)
>

I'm sorry I haven't chimed in sooner. I fully understand this. Yes,  
it's the closure over coll in the rest portion, which means that after  
finding some match, a subsequent call to rest that needs to skip a lot  
will create a window over the interval where the seq will be realized.

Eagerly evaluating (rest coll) won't work - the result will still be  
in the closure while the recursion occurs. The only solutions involve  
mutation in filter. Here's one way:

(defn filter
   [pred coll]
 (let [sa (atom (seq coll))
   step (fn step []
   (when-let [s @sa]
 (let [x (first s)]
   (if (pred x)
 (lazy-cons x (do (swap! sa rest) (step)))
 (do (swap! sa rest)
 (recur))]
   (step)))

But it's not pretty. Fortunately, this segues with work I have been  
doing on I/O and generators/streams. This will let you write things  
like:

(defn filter-stream
   "Returns a stream of the items in strm for which
   (pred item) returns true. pred must be free of side-effects."
   [pred strm]
   (stream
#(let [x (next! strm)]
   (if (or (eos? x) (pred x)) x (recur)

(defn filter
"Returns a lazy seq of the items in coll for which
   (pred item) returns true. pred must be free of side-effects."
  [pred coll]
   (stream-seq (filter-stream pred (stream coll

I'm still not done with this yet, so anyone who is stuck can use the  
former version.

Rich


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread .Bill Smith

I agree that the ability to nest tests is important, but I'm not sure
encoding the nesting information in the test name is necessarily the
right way to go.  Perhaps an intermediate step would be to define a
"test container" that, when executed, runs all the tests it contains.
With that foundation, you could define functions that create and
populate the test container according to various criteria.

What is the purpose of a nested test context in RSpec?  Can a test
belong to more than one nested test context?

Bill

On Dec 7, 4:20 pm, samppi <[EMAIL PROTECTED]> wrote:
> I would wholeheartedly love if tests could be nested. Even if it was
> as simple as appending a phrase to each nested test:

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread samppi

RSpec's contexts are for grouping tests—or defining specifications—for
a Ruby class:

describe Account do
  it "should be able to withdraw money and reflect it in its balance"
do
...
  end
end

...creates a test basically called "Account should be able to withdraw
money and reflect it in its balance" in a spec for a class called
Account.

It does indeed create a "test container", though—that's what I meant
in the first place. You can do all sorts of stuff with them, but its
title is appended to each of its tests' titles whenever it's displayed
in test results, etc. What I meant is that a test context container be
created. I don't really care as much about the prefixing of test names
itself, but it would make sense and it's what RSpec does.

On Dec 8, 8:31 pm, ".Bill Smith" <[EMAIL PROTECTED]> wrote:
> I agree that the ability to nest tests is important, but I'm not sure
> encoding the nesting information in the test name is necessarily the
> right way to go.  Perhaps an intermediate step would be to define a
> "test container" that, when executed, runs all the tests it contains.
> With that foundation, you could define functions that create and
> populate the test container according to various criteria.
>
> What is the purpose of a nested test context in RSpec?  Can a test
> belong to more than one nested test context?
>
> Bill
>
> On Dec 7, 4:20 pm, samppi <[EMAIL PROTECTED]> wrote:
>
> > I would wholeheartedly love if tests could be nested. Even if it was
> > as simple as appending a phrase to each nested test:
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Calling superclass methods from implemented methods

2008-12-08 Thread Matt Revelle
The attached patch adds :super-methods option to generate-class as a  
map, {local-name [name [param-types] return-type], ...}.  The  
mechanics work as Rich suggested in an earlier message, a method is  
created that has the same type signature as the exposed method - it  
loads the arguments, invokes the method, and returns the result.

An example can be viewed here:
http://gist.github.com/33787

I haven't done extensive testing, but seems to work.

-Matt


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



genclass_expose-super-methods.diff
Description: Binary data



On Dec 8, 2008, at 10:59 AM, Rich Hickey wrote:

>
>
>
> On Dec 8, 9:30 am, Matt Revelle <[EMAIL PROTECTED]> wrote:
>> I'm working on a patch to add support for calling the superclass'
>> implementation of a method when overriding a method in Clojure with
>> ns/:genclass.  This looks like it requires a modification of the
>> InstanceMethodExpr class in clojure.lang.Compiler.  The proposed
>> syntax would be: (. super/MethodFoo this args).  One issue is that
>> using super/MethodFoo to refer to the superclass' method means that
>> (.super/MethodFoo this args) wouldn't work without more Parser  
>> changes.
>>
>> I'm close to finishing this, but would like to get feedback before
>> spending more time.  Thoughts?
>>
>
> I would set aside the syntax and first describe the mechanism. Are you
> going to generate a super-calling version of every method? Are you
> going to try to emit code to generate invokespecial in the
> implementing fn? The latter won't work as there is no type
> relationship.
>
> It might be easier to just enhance the :exposes to handle methods as
> well, or add a  :supers section.
>
> Rich
>
> --~--~-~--~~~---~--~~
> You received this message because you are subscribed to the Google  
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> To unsubscribe from this group, send email to [EMAIL PROTECTED]
> For more options, visit this group at 
> http://groups.google.com/group/clojure?hl=en
> -~--~~~~--~~--~--~---
>



Re: License of/permission for Clojure's logo

2008-12-08 Thread samppi

I've uploaded the logo's glyph and added it to Clojure's article.

However, I'm wondering, Mr. Hickey—have you considered releasing the
language's logo under a free license? The language itself is under the
Common Public License; releasing its logo under another free license
is a logical step. If you do so, sites like Wikipedia and bloggers
talking about Clojure would be free to use and spread the logo. (I'm
bringing this up because Wikipedia itself doesn't like non-free images
on it because it says its materials can be used freely by anyone.)

On Dec 4, 5:23 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Dec 3, 11:30 pm, samppi <[EMAIL PROTECTED]> wrote:
>
> > I want to put the Clojure 
> > logo:http://clojure.googlegroups.com/web/Clojure-logo.png?gda=y8lqvUIAAABo...
>
> > ...on Wikipedia's article on Clojure. What is the license of Clojure's
> > logo--is it a free image? Or can Mr. Hickley give me permission to use
> > it on Wikipedia?
>
> You can use the logo on the wikipedia article on Clojure, but only if
> you spell my name correctly :)
>
> Rich
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.test-is: first major rewrite

2008-12-08 Thread Dan Larkin

Hey this looks great!

On Dec 7, 2008, at 10:51 AM, Stuart Sierra wrote:

>
> Hi folks,
...
>
> 2. "each=" and "all-true" are gone, replaced by the new macro "are",
> which works with any predicate:
>(are =
>  2 (+ 1 1)
>  4 (+ 2 2))
>

Just one bone to pick, though.  The "are" macro doesn't work so well  
if I want to test a custom assert-expr function that only deals with a  
single expression.

Since this works fine:

(deftest array
   (is (:json= [1 2 3 4 5])))

it would be nice if I could write:

(deftest basics
   (are :json=
[1 2 3 4 5]
{:bar 2 :foo 1}
[[1 2 3 4 5]]
{:bam {:foo 1} :baz {:bar 2}}
[{:foo 1} {:bar 2}]))


The :json= handler for assert-expr encodes and then decodes the expr  
into/from JSON.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---