Re: funny (?) str behavior

2010-02-24 Thread Jarkko Oranen


On Feb 23, 10:47 am, Alfred Tarski atar...@gmail.com wrote:
 Hi,

 I have this function:

 (defn wrap [x]
   (str % x %))

 and I do

 bf= (str boo hoo  (map wrap [fdfd ggfs]))
 boo hoo clojure.lang.lazy...@9e050eb0

 This looks odd to me, but if the powers that be consider this to be
 the right behavior of str then my question is: what do I need to do do
 get what I want?

if you really want the seq to be stringified instead of the elements,
just do (str boo hoo  (seq (map (wrap [...]

I suppose lazy seqs are so lazy they won't even bother to provide a
string representation of themselves without coercion :)

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


Re: Can't get Ring to reload namespace

2010-02-24 Thread Neill Alexander
Great, that makes sense. Thanks very much guys.

On Feb 24, 1:00 am, James Reeves weavejes...@googlemail.com wrote:
 Ah yep, (var app) is probably a better idea than #(app %).

 - James

 On Feb 23, 11:55 pm, Mark McGranaghan mmcgr...@gmail.com wrote:

   Basically because wrap-reload is a function, so app is evaluated
   before it is passed to wrap-reload.

  Right. To elaborate, the code (reload/wrap-reload app '(ns1 ns2))
  invokes the wrap-reload function with the current value of the app
  Var, which is a specific and immutable function. The reload middleware
  may subsequently reload the namespaces and therefore change the value
  of the app Var, but the value that is used to invoke (app req) within
  the middleware remains unchanged.

  I'd therefore suggest passing a Var instead of a function:

  (reload/wrap-reload (var app) '(ns1 ns2))

   In this way, each time app is invoked within the middleware, it first
  goes to get the current value of the app var and then uses that value
  to evaluate the request argument; i.e. the reload works.

  Note that if the implementation of app itself never changes, only the
  functions that it in turn calls, then the (var app) bit becomes
  unnecessary.

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


Re: clojure-clr how to reference assemblies?

2010-02-24 Thread soyrochus
Hi,

Some assemblies are loaded by default an can be used directly. But
like IronPython, you will need to *explicitly* load most assemblies to
be imported into your program. This differs from C# which does it
under the hood. The Assemblies can be loaded from the GAC or from a
dll if it is not loaded/referenced by default. For example, as
System.Console is loaded by default you can directly use:

(System.Console/WriteLine Clo[sjz]ure)

However, the System.Windows.Forms assembly is not loaded by default.
So you would need:

(System.Reflection.Assembly/LoadWithPartialName
System.Windows.Forms)

or

(System.Reflection.Assembly/Load System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)


You can then import the MessageBox class

(import '(System.Windows.Forms MessageBox))
(MessageBox/Show Clo[sjz]ure)

Regards,

Iwan

On Feb 24, 12:26 am, adam11235 adam.k.web...@gmail.com wrote:
 Hi,

 I'm unsure of how to get clojure-clr to reference assemblies that a
 program needs.

 I can successfully get this to show a message box via the REPL:

 (System.Windows.Forms.MessageBox/Show hello world)

 I can successfully save this to a file, add the file as a command-line
 arg inside VisualStudio and run the Clojure.Main project which takes
 the cmd line arg, correctly loads and executes the code

 However if I save that to a file and then try the following (from the
 command line, outside of VS, I get an exception:

 pathTo\Clojure\Clojure.Main\bin\debug\Clojure.Main.Exe c:\clj
 \helloworld.clj

 I have also changed the contents of the file to the following, still
 with no success:

 1)
 (import '(System.Windows.Forms MessageBox ))
 (MessageBox/Show hello world)

 2)
 (import '(System.Windows.Forms MessageBox ))
 (System.Windows.Forms.MessageBox/Show hello world)

 Any hints?

 Thanks, Adam.

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


on-the-fly fn creation, arglist, with-meta, :tag

2010-02-24 Thread Jules
Guys,

I seem to have thrown myself in at the deep end here !

I'm writing some clojure which interacts very heavily with some pojos,
making, hopefully, millions of method invocations a second.

I tried :

Clojure 1.1.0-new-SNAPSHOT
user= (set! *warn-on-reflection* true)
true
user= (defn fn1 [s] (.length s))
Reflection warning, NO_SOURCE_PATH:15 - reference to field length
can't be resolved.
#'user/fn1
user= (time (dotimes [x 10] (fn1 foo)))
Elapsed time: 2424.1015 msecs
nil
user= (defn fn2 [#^String s] (.length s))
#'user/fn2
user= (time (dotimes [x 10] (fn2 foo)))
Elapsed time: 63.462 msecs
nil

and found that I really needed to take notice of the reflection
warnings for perfomance's sake !

My problem is, that I need to produce functions like the one above, on-
the-fly, from java-side metadata, where both the method name and arg
type are parameterised.

I've spent some time messing around with eval and defmacro and then
found that I was being defeated by the #^ reader macro at every turn,
so I tried switching to using with-meta, but I cannot figure out how
to place metadata correctly on the symbols in the arglist - e.g. :

user= (fn [(with-meta 's {:tag String})] (.length s))
java.lang.Exception: Unsupported binding form: (with-meta (quote s)
{:tag String}) (NO_SOURCE_FILE:30)

most probably because 'fn is a macro and arglist is not expanded as
you might expect, and:

user= (let [arg (with-meta 's {:tag String}) arglist [arg] body (list
'.length arg)] (eval (list 'fn arglist body)))
Reflection warning, NO_SOURCE_PATH:40 - reference to field length
can't be resolved.
#user$eval__168$fn__170 user$eval__168$fn__...@3a1834
user= (*1 foo)
3

The above looks like it worked - but the metadata has been ignored by
the compiler - aaargh !

There must be a way to put together a list/tree of code, at runtime,
that, when evaluated, gives me what I want, by flying beneath the 'fn
macro and/or the #^ reader macro, but at this point I run out of doc
and google-hits :-(

I'd really appreciate some help with this.

thanks,

Jules

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


Re: on-the-fly fn creation, arglist, with-meta, :tag

2010-02-24 Thread Meikel Brandmeyer
Hi,

On Feb 24, 12:50 pm, Jules jules.gosn...@gmail.com wrote:

 user= (let [arg (with-meta 's {:tag String}) arglist [arg] body (list
 '.length arg)] (eval (list 'fn arglist body)))
 Reflection warning, NO_SOURCE_PATH:40 - reference to field length
 can't be resolved.
 #user$eval__168$fn__170 user$eval__168$fn__...@3a1834
 user= (*1 foo)
 3

The following seems to work for me:

user= (defn hinted-fn
 [name arg-types args body]
 (eval `(defn ~name
  ~(vec (map #(with-meta %1 {:tag %2}) args arg-
types))
  ~body)))
#'user/hinted-fn
user= (hinted-fn 'len '[String] '[s] '(.length s))
#'user/len
user= (len Hello)
5

Note, that you also have to quote the argument-types (or use the
classname as a string). Using the class directly does not work:

user= (hinted-fn 'len [String] '[s] '(.length s))
Reflection warning, NO_SOURCE_PATH:7 - reference to field length can't
be resolv
ed.
#'user/len

Sincerely
Meikel

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


Re: on-the-fly fn creation, arglist, with-meta, :tag

2010-02-24 Thread Jules
Meikel,

Thanks for the quick answer.

So I was only one step away from a solution !

I had :

user= (let [arg (with-meta 's {:tag String}) arglist [arg] body (list
'.length arg)] (eval (list 'fn arglist body)))
Reflection warning, NO_SOURCE_PATH:52 - reference to field length
can't be resolved.
#user$eval__210$fn__212 user$eval__210$fn__...@b957ea
user=

when I needed :

user= (let [arg (with-meta 's {:tag java.lang.String}) arglist
[arg] body (list '.length arg)] (eval (list 'fn arglist body)))
#user$eval__198$fn__200 user$eval__198$fn__...@7f58ef
user= (*1 foo)
3

Thanks for your help - much appreciated :-)

Jules

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


Re: Strange reflection warning

2010-02-24 Thread Sean Devlin
Here's what I would suspect after running the following at the REPL

user= (set! *warn-on-reflection* true)
true
user= (defn bar [o] (.toString o))
Reflection warning, NO_SOURCE_PATH:605 - reference to field toString
can't be resolved.
#'user/bar
user= (bar 1)
1

How does the reader know the difference between .hashCode
and .reallyObsureMethod?  It would need to keep a whitelist of
everything in object, and know that these methods can be called
directly.  Maybe the reader should be upgraded to handle this?

Could be totally wrong.

Sean

On Feb 24, 2:56 am, Konrad Hinsen konrad.hin...@fastmail.net wrote:
 The following trivial code generates a reflection warning for the call  
 to hashCode:

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

 (defn foo [o]
    (.hashCode o))

 It's easy to fix:

 (defn foo [#^Object o]
    (.hashCode o))

 but I don't understand why a type hint for java.lang.Object could ever  
 be necessary. My understanding is (was?) that java.lang.Object is the  
 default type for all function arguments in Clojure. Am I wrong?

 Konrad.

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


Var Value from String of varname

2010-02-24 Thread Quzanti
I am sure this is really obvious but as I don't know the technical
term for what I am trying to do I can't google it

(def age 3)

then

(cons (symbol age) [2 1])

I get

(age 2 1)

rather than

(3 2 1)

which is what I was hoping for. Or maybe you cannot do this at runtime?

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


Enclojure plugin Netbeans

2010-02-24 Thread Larry Wykel
Anyone!!!

.

Anyway if your using Enclojure etc in Netbeans let me describe exactly what 
happens when I attempt to install plugin

Latest MacOS Snow Leopard
NetBeans 6.8 with just Ruby
Enclojure plugin from Git

File came down with a .zip extention



1. I renamed the file to same name with .nbm extension

2. Went into Netbeans plugin manager.downloads and added the file. I 
found it
and it showed up fine  and I could click the install button.

3. the process then runs and it loads when its done ti gave me no 
choice to restart it just restarted Netbeans.

4. Netbeans closed and restarted but when it came back up the Menu was 
gone except for Netbeans prefs and
the Netbeans Icon was in the Dock.

5. When you attempt to open clicking on the Icon does nothing. You 
cannot even git rid of it.
I actually go into the Activity monitor and kill the Netbeans 
process, then remove Netbeans and reinstall.

6. When I do Netbeans comes up fine and shows the Enclojure plugin 
installed. But you cannot activate it.

Just wanted to let you know if quickly looking at these iissues you 
know what the problem is or can suggest something

I am sure the plugin will do what I am after fro now once I get it activated.

Lar

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


clojure-clr how to wire up a delegate

2010-02-24 Thread adam11235
Hi,

I've made progress in creating a simple app to show a windows form,
however I am having trouble wiring up a delegate (to handle button
clicks).

The Java version uses Proxy to implement ActionListener, instead I am
just trying to create an EventHandler passing as the 2nd constructor
argument the code I would like executed. (see the .add_Click line)

The delegate code gets invoked immediately instead of when the button
click occurs, and then complains it expected a function pointer rather
than the DialogResult it received (due to execution of the code)

I tried quoting that code but no success.

How do you wire up delegates?

(import '(System.Windows.Forms MessageBox Form Button))

(defn windowsPlay []
(let
[   win (Form.)
temp-button (Button.)
]
(.. win (get_Controls) (Add temp-button))
(doto temp-button
(.set_Top 50)
(.set_Text Clicky)
(.add_Click (EventHandler. temp-button (MessageBox/Show I got
clicked
(doto win
(.set_Text hello)
(.ShowDialog

(windowsPlay)

Thanks, Adam.

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


Posting

2010-02-24 Thread Larry Wykel
I just joined, got confirm, the clicked link. Posted msg to group. got email 
back confirming but is not showing up
in messages

Lar

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


getting a library listed on the library page?

2010-02-24 Thread Kyle R. Burton
I've written an XPath library in clojure that wraps the Java api to
make it easier to use from clojure [1].  What is the process for
submitting libraries for inclusion on the clojure library page?  I'm
also not sure if the community feels this is worth including but I
thought I'd offer it to see if it is.

Best regards,

Kyle Burton

[1] http://github.com/kyleburton/clj-xpath

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


Re: Var Value from String of varname

2010-02-24 Thread Quzanti
Have found what I am trying to do eval

I am working through the Halloway book, which doesn't seem to have
eval in the index, so I probably should excuse myself my ignorance.

Is there much a performance impact of using eval,as presumably the
compiler can't do much until runtime? Or is the idea of functional
languages to delay as much until runtime as possible anyway?


On Feb 24, 11:16 am, Quzanti quza...@googlemail.com wrote:
 I am sure this is really obvious but as I don't know the technical
 term for what I am trying to do I can't google it

 (def age 3)

 then

 (cons (symbol age) [2 1])

 I get

 (age 2 1)

 rather than

 (3 2 1)

 which is what I was hoping for. Or maybe you cannot do this at runtime?

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


Re: clojure-clr how to wire up a delegate

2010-02-24 Thread Joop Kiefte
Tried to encapsulate what you want to put in the eventhandler in an
anonymous function?

And I don't know how that works in Clojure-CLR, but you might need proxy...

2010/2/24 adam11235 adam.k.web...@gmail.com:
 Hi,

 I've made progress in creating a simple app to show a windows form,
 however I am having trouble wiring up a delegate (to handle button
 clicks).

 The Java version uses Proxy to implement ActionListener, instead I am
 just trying to create an EventHandler passing as the 2nd constructor
 argument the code I would like executed. (see the .add_Click line)

 The delegate code gets invoked immediately instead of when the button
 click occurs, and then complains it expected a function pointer rather
 than the DialogResult it received (due to execution of the code)

 I tried quoting that code but no success.

 How do you wire up delegates?

 (import '(System.Windows.Forms MessageBox Form Button))

 (defn windowsPlay []
        (let
                [       win (Form.)
                        temp-button (Button.)
                ]
        (.. win (get_Controls) (Add temp-button))
        (doto temp-button
                (.set_Top 50)
                (.set_Text Clicky)
                (.add_Click (EventHandler. temp-button (MessageBox/Show I got
 clicked
        (doto win
                (.set_Text hello)
                (.ShowDialog

 (windowsPlay)

 Thanks, Adam.

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



-- 
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

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


Re: clojure-clr how to wire up a delegate

2010-02-24 Thread Joop Kiefte
Forget about the proxy part, re-read your message... =x

2010/2/24 Joop Kiefte iko...@gmail.com:
 Tried to encapsulate what you want to put in the eventhandler in an
 anonymous function?

 And I don't know how that works in Clojure-CLR, but you might need proxy...

 2010/2/24 adam11235 adam.k.web...@gmail.com:
 Hi,

 I've made progress in creating a simple app to show a windows form,
 however I am having trouble wiring up a delegate (to handle button
 clicks).

 The Java version uses Proxy to implement ActionListener, instead I am
 just trying to create an EventHandler passing as the 2nd constructor
 argument the code I would like executed. (see the .add_Click line)

 The delegate code gets invoked immediately instead of when the button
 click occurs, and then complains it expected a function pointer rather
 than the DialogResult it received (due to execution of the code)

 I tried quoting that code but no success.

 How do you wire up delegates?

 (import '(System.Windows.Forms MessageBox Form Button))

 (defn windowsPlay []
        (let
                [       win (Form.)
                        temp-button (Button.)
                ]
        (.. win (get_Controls) (Add temp-button))
        (doto temp-button
                (.set_Top 50)
                (.set_Text Clicky)
                (.add_Click (EventHandler. temp-button (MessageBox/Show I got
 clicked
        (doto win
                (.set_Text hello)
                (.ShowDialog

 (windowsPlay)

 Thanks, Adam.

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



 --
 Communication is essential. So we need decent tools when communication
 is lacking, when language capability is hard to acquire...

 - http://esperanto.net  - http://esperanto-jongeren.nl

 Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004




-- 
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

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


Re: Strange reflection warning

2010-02-24 Thread Konrad Hinsen
On 24.02.2010, at 14:43, Sean Devlin wrote:

 How does the reader know the difference between .hashCode
 and .reallyObsureMethod?  It would need to keep a whitelist of
 everything in object, and know that these methods can be called
 directly.  Maybe the reader should be upgraded to handle this?

It's not the reader who deals with method lookup, it's the compiler. It doesn't 
need any whitelist for that. If the compiler knows the (Java) type of a data 
item, it can look up the available methods statically, i.e. at compile time, 
and generate a direct method invocation is the lookup succeeds.

This works in fact very well, it's the basis of using hints for avoiding 
reflection. What I am surprised about is that in the absence of any hints, the 
compiler assumes to know nothing about a value's type, whereas I believe it 
could safely assume that it is a subclass of java.lang.Object, considering that 
only primitive types are not subclasses of java.lang.Object, but function 
arguments cannot be primitive types. But I am not enough of a JVM expert to be 
sure.

Konrad.

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


Re: Var Value from String of varname

2010-02-24 Thread Stuart Halloway

You don't need (and shouldn't use) eval for this:

@(resolve (symbol age)))

Stu


Have found what I am trying to do eval

I am working through the Halloway book, which doesn't seem to have
eval in the index, so I probably should excuse myself my ignorance.

Is there much a performance impact of using eval,as presumably the
compiler can't do much until runtime? Or is the idea of functional
languages to delay as much until runtime as possible anyway?


On Feb 24, 11:16 am, Quzanti quza...@googlemail.com wrote:

I am sure this is really obvious but as I don't know the technical
term for what I am trying to do I can't google it

(def age 3)

then

(cons (symbol age) [2 1])

I get

(age 2 1)

rather than

(3 2 1)

which is what I was hoping for. Or maybe you cannot do this at  
runtime?


--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient  
with your first post.

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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


Re: Strange reflection warning

2010-02-24 Thread Sean Devlin
Konrad,
Okay, I was looking in the wrong place.  Which leads me to suggest the
following:

Create a local fork of Clojure, make a new branch, and hack on the
compiler.  Run the experiment, see what happens :)

Sean

On Feb 24, 9:15 am, Konrad Hinsen konrad.hin...@fastmail.net wrote:
 On 24.02.2010, at 14:43, Sean Devlin wrote:

  How does the reader know the difference between .hashCode
  and .reallyObsureMethod?  It would need to keep a whitelist of
  everything in object, and know that these methods can be called
  directly.  Maybe the reader should be upgraded to handle this?

 It's not the reader who deals with method lookup, it's the compiler. It 
 doesn't need any whitelist for that. If the compiler knows the (Java) type of 
 a data item, it can look up the available methods statically, i.e. at compile 
 time, and generate a direct method invocation is the lookup succeeds.

 This works in fact very well, it's the basis of using hints for avoiding 
 reflection. What I am surprised about is that in the absence of any hints, 
 the compiler assumes to know nothing about a value's type, whereas I believe 
 it could safely assume that it is a subclass of java.lang.Object, considering 
 that only primitive types are not subclasses of java.lang.Object, but 
 function arguments cannot be primitive types. But I am not enough of a JVM 
 expert to be sure.

 Konrad.

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


Re: Posting

2010-02-24 Thread Michael Wood
On 24 February 2010 15:40, Larry Wykel lwy...@earthlink.net wrote:
 I just joined, got confirm, the clicked link. Posted msg to group. got email 
 back confirming but is not showing up
 in messages

 Lar

It looks like your message about Enclojure did take a little while to
come through.

[...]
Received: by 10.150.251.3 with SMTP id y3mr31409ybh.7.1267019824373;
Wed, 24 Feb 2010 05:57:04 -0800 (PST)
Received: by 10.150.235.3 with SMTP id i3mr6190769ybh.14.1267017537427;
Wed, 24 Feb 2010 05:18:57 -0800 (PST)
[...]

Perhaps the signature attached to all posts explains this:

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.


 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

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

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


Re: getting a library listed on the library page?

2010-02-24 Thread Krešimir Šojat
Hi,

On Feb 24, 2:59 pm, Kyle R. Burton kyle.bur...@gmail.com wrote:
 I've written an XPath library in clojure that wraps the Java api to
 make it easier to use from clojure [1].  What is the process for
 submitting libraries for inclusion on the clojure library page?

Instructions on how to get listed are at:
http://groups.google.com/group/clojure/browse_thread/thread/affb08d66c048c7f/77f10a8a9a55d089#77f10a8a9a55d089

--
Krešimir Šojat

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


Re: Strange reflection warning

2010-02-24 Thread Konrad Hinsen
On 24.02.2010, at 15:42, Sean Devlin wrote:

 Create a local fork of Clojure, make a new branch, and hack on the
 compiler.  Run the experiment, see what happens :)

Right now I have better ways to use my time than hacking on a compiler that 
Rich is replacing with a new one written in Clojure!

However, I did have a look at the compiler to see if I can find what's going 
on. I can't claim to have understood everything, so I may be wrong, but this is 
my current best explanation: no type tag means no method lookup at compile 
time, thus reflection on all method calls. Presumably one could modify the 
compiler to put a default type tag of java.lang.Object on all function 
arguments that don't have a type tag, but if one day the compiler is extended 
to allow unboxed primitives as function arguments, that would probably fail.

Konrad.

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


Minimax in Clojure – request for code review and a question

2010-02-24 Thread Tzach
Hi all
I made a naïve attempt to implement the minimax algorithm in Clojure.
I would appreciate any comment on style, wrong (or right) use of
idioms etc.
Specifically, can I create a “contract” for the function I use, like
heuristic, to formalize minimax requirement from it?

Thanks
Tzach

Pseudocode from http://en.wikipedia.org/wiki/Minimax:

function integer minimax(node, depth)
if node is a terminal node or depth == 0:
return the heuristic value of node
α = -∞
for child in node:   # evaluation is identical
for both players
α = max(α, -minimax(child, depth-1))
return α

My take in Clojure:

(defn minimax [pos depth player]
  minimax implementation, return a pair of the best value and move.
   Require the following functions:
heuristic - return the heuristic value of a pos
movegen - return a sequence of legal moves
next-pos - return the new position after a move was done

  (let [moves (movegen pos player)]
(if (or (empty? moves) (zero? depth))
  [(heuristic pos player) nil]
  (apply max-key first
 (cons
  [- nil]
  (for [m moves :let [n-pos (next-pos pos m)]]
[ (- (first (minimax n-pos (dec depth) (opposite player m ]
))

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


Re: Minimax in Clojure – request for code review a nd a question

2010-02-24 Thread Laurent PETIT
Hello,

2010/2/24 Tzach tzach.livya...@gmail.com:
 [...]
 Specifically, can I create a “contract” for the function I use, like
 heuristic, to formalize minimax requirement from it?

Yes, you can add pre- and post- conditions, have a look here:
http://clojure.org/special_forms

HTH,

-- 
Laurent

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


Re: Var Value from String of varname

2010-02-24 Thread Quzanti
Thanks.

So it isn't a counterexample to my rule of Thumb

'If it is isn't in Halloway you shouldn't be using it'

I'll catch you out one day.

On Feb 24, 2:19 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
 You don't need (and shouldn't use) eval for this:

 @(resolve (symbol age)))

 Stu

  Have found what I am trying to do eval

  I am working through the Halloway book, which doesn't seem to have
  eval in the index, so I probably should excuse myself my ignorance.

  Is there much a performance impact of using eval,as presumably the
  compiler can't do much until runtime? Or is the idea of functional
  languages to delay as much until runtime as possible anyway?

  On Feb 24, 11:16 am, Quzanti quza...@googlemail.com wrote:
  I am sure this is really obvious but as I don't know the technical
  term for what I am trying to do I can't google it

  (def age 3)

  then

  (cons (symbol age) [2 1])

  I get

  (age 2 1)

  rather than

  (3 2 1)

  which is what I was hoping for. Or maybe you cannot do this at  
  runtime?

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

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


Re: getting a library listed on the library page?

2010-02-24 Thread Kyle R. Burton
Thank you!

I have not yet picked a license for the library, I am open to any of
them, but would like to know what the preferred license is for the
project.  My first leaning is towards a permissive license such as
BSD.  What is preferred or recommended for clojure and its libraries?

Thank you,

Kyle

On Wed, Feb 24, 2010 at 10:44 AM, Krešimir Šojat kso...@gmail.com wrote:
 Hi,

 On Feb 24, 2:59 pm, Kyle R. Burton kyle.bur...@gmail.com wrote:
 I've written an XPath library in clojure that wraps the Java api to
 make it easier to use from clojure [1].  What is the process for
 submitting libraries for inclusion on the clojure library page?

 Instructions on how to get listed are at:
 http://groups.google.com/group/clojure/browse_thread/thread/affb08d66c048c7f/77f10a8a9a55d089#77f10a8a9a55d089

 --
 Krešimir Šojat

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



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


Re: getting a library listed on the library page?

2010-02-24 Thread Sean Devlin
IANAL.

The standard seems to be EPL 1.0, because it's what Rich uses for
Clojure  Contrib.  My understanding is that this causes problems w/
the GPL, so you'll probably want to stay away from that.

Sean

On Feb 24, 1:36 pm, Kyle R. Burton kyle.bur...@gmail.com wrote:
 Thank you!

 I have not yet picked a license for the library, I am open to any of
 them, but would like to know what the preferred license is for the
 project.  My first leaning is towards a permissive license such as
 BSD.  What is preferred or recommended for clojure and its libraries?

 Thank you,

 Kyle



 On Wed, Feb 24, 2010 at 10:44 AM, Krešimir Šojat kso...@gmail.com wrote:
  Hi,

  On Feb 24, 2:59 pm, Kyle R. Burton kyle.bur...@gmail.com wrote:
  I've written an XPath library in clojure that wraps the Java api to
  make it easier to use from clojure [1].  What is the process for
  submitting libraries for inclusion on the clojure library page?

  Instructions on how to get listed are at:
 http://groups.google.com/group/clojure/browse_thread/thread/affb08d66...

  --
  Krešimir Šojat

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

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


Re: Got a Clojure library?

2010-02-24 Thread Kyle R. Burton
 The name of your library

clj-xpath

 Library home page URL

http://github.com/kyleburton/clj-xpath

 Your name

Kyle Burton

 Category (db, web, UI, parsing etc)

XML Processing, XPath

 License

EPL

 A one-paragraph description. Include 3rd party dependencies if any.

Simplified XPath Library for Clojure.  This library provides a thin
layer around basic parsing and XPath interaction for common use cases.
3rd party dependencies are xalan and log4j.  The project can be built
and installed with maven or used as source.

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


Re: Map with multiple keys?

2010-02-24 Thread Johann Hibschman
Base basselh...@gmail.com writes:

 So this may be an extraordinary dumb question (even for me...) but is
 there such a thing as a map with compound keys?

[...]

 I could do map - in  - map, or do something like a (str cat gender) to
 amalgamate 2 fields to set the key but I was just wondering if this
 even existed.

I don't know of anything built-in, but I would prefer [cat gender] over
(str cat gender) as keys for a map.

-Johann

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


Re: clojure-clr how to wire up a delegate

2010-02-24 Thread soyrochus
Hi Adam,

You need to use the gen-delegate macro to create delegates,

See http://wiki.github.com/richhickey/clojure-clr/clr-interop

The signature of the macro is (gen-delegate Type [args] body) whereby
in case of event-handlers you would typically use the EventHandler
class.
The code becomes then:

(System.Reflection.Assembly/LoadWithPartialName
System.Windows.Forms)
(import '(System.Windows.Forms MessageBox Form Button))

(defn windowsPlay []
  (let [win (Form.)
temp-button (Button.)]
(.. win (get_Controls) (Add temp-button))
(doto temp-button
  (.set_Top 50)
  (.set_Text Clicky)
  (.add_Click (gen-delegate EventHandler [sender args] (MessageBox/
Show I got clicked
(doto win
  (.set_Text hello)
  (.ShowDialog

(windowsPlay)

Regards,

Iwan


On Feb 24, 7:43 am, adam11235 adam.k.web...@gmail.com wrote:
 Hi,

 I've made progress in creating a simple app to show a windows form,
 however I am having trouble wiring up a delegate (to handle button
 clicks).

 The Java version uses Proxy to implement ActionListener, instead I am
 just trying to create an EventHandler passing as the 2nd constructor
 argument the code I would like executed. (see the .add_Click line)

 The delegate code gets invoked immediately instead of when the button
 click occurs, and then complains it expected a function pointer rather
 than the DialogResult it received (due to execution of the code)

 I tried quoting that code but no success.

 How do you wire up delegates?

 (import '(System.Windows.Forms MessageBox Form Button))

 (defn windowsPlay []
         (let
                 [       win (Form.)
                         temp-button (Button.)
                 ]
         (.. win (get_Controls) (Add temp-button))
         (doto temp-button
                 (.set_Top 50)
                 (.set_Text Clicky)
                 (.add_Click (EventHandler. temp-button (MessageBox/Show I got
 clicked
         (doto win
                 (.set_Text hello)
                 (.ShowDialog

 (windowsPlay)

 Thanks, Adam.

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


Re: Enclojure plugin Netbeans

2010-02-24 Thread Mark Nutter
I think I know this one: you need NetBeans with the Java module
activated. I had the same problems trying to use NetBeans with just
PHP.

Mark

On Wed, Feb 24, 2010 at 8:18 AM, Larry Wykel lwy...@earthlink.net wrote:
 Anyone!!!

 .

 Anyway if your using Enclojure etc in Netbeans let me describe exactly what 
 happens when I attempt to install plugin

        Latest MacOS Snow Leopard
        NetBeans 6.8 with just Ruby
        Enclojure plugin from Git

        File came down with a .zip extention



        1. I renamed the file to same name with .nbm extension

        2. Went into Netbeans plugin manager.downloads and added the file. I 
 found it
                and it showed up fine  and I could click the install button.

        3. the process then runs and it loads when its done ti gave me no 
 choice to restart it just restarted Netbeans.

        4. Netbeans closed and restarted but when it came back up the Menu was 
 gone except for Netbeans prefs and
                the Netbeans Icon was in the Dock.

        5. When you attempt to open clicking on the Icon does nothing. You 
 cannot even git rid of it.
                I actually go into the Activity monitor and kill the Netbeans 
 process, then remove Netbeans and reinstall.

        6. When I do Netbeans comes up fine and shows the Enclojure plugin 
 installed. But you cannot activate it.

        Just wanted to let you know if quickly looking at these iissues you 
 know what the problem is or can suggest something

 I am sure the plugin will do what I am after fro now once I get it activated.

 Lar

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

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


Prefixed or suffixed symbols?

2010-02-24 Thread joshua-choi
When it comes to distinguishing certain types of symbols from other
things, should one use prefixes or suffixes?

Example: naming tests with clojure.test/deftest. If you distinguish
your tests’ symbols at all, do you do “t-addition” or “addition-t”?

(I need to know what the standard is, if there is any, because I need
a way to distinguish a certain type of symbol—those that represent
“rules”— in my libraries. I’m using an underscore suffix right now,
like “vector_”, which means “vector-rule” But “_rule” might be better,
or even “_rule_”, though the last one might be overkill. In the past,
I’ve used “vector-r, but I don’t like that now.)

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


Re: Enclojure plugin Netbeans

2010-02-24 Thread Lar
Wonderfull. Thanks so Much. Well you know I suspected as much. I did
not want all the Java stuff right now. I went on to other things. So
tommorow I will do the Java se plugin. ''

Again thanks much. Its  been fun last five days attempting to get a
good Clojure IDE thats good.

Larry

On Feb 24, 5:15 pm, Mark Nutter manutte...@gmail.com wrote:
 I think I know this one: you need NetBeans with the Java module
 activated. I had the same problems trying to use NetBeans with just
 PHP.

 Mark



 On Wed, Feb 24, 2010 at 8:18 AM, Larry Wykel lwy...@earthlink.net wrote:
  Anyone!!!

  .

  Anyway if your using Enclojure etc in Netbeans let me describe exactly what 
  happens when I attempt to install plugin

         Latest MacOS Snow Leopard
         NetBeans 6.8 with just Ruby
         Enclojure plugin from Git

         File came down with a .zip extention

         1. I renamed the file to same name with .nbm extension

         2. Went into Netbeans plugin manager.downloads and added the file. I 
  found it
                 and it showed up fine  and I could click the install 
  button.

         3. the process then runs and it loads when its done ti gave me no 
  choice to restart it just restarted Netbeans.

         4. Netbeans closed and restarted but when it came back up the Menu 
  was gone except for Netbeans prefs and
                 the Netbeans Icon was in the Dock.

         5. When you attempt to open clicking on the Icon does nothing. You 
  cannot even git rid of it.
                 I actually go into the Activity monitor and kill the 
  Netbeans process, then remove Netbeans and reinstall.

         6. When I do Netbeans comes up fine and shows the Enclojure plugin 
  installed. But you cannot activate it.

         Just wanted to let you know if quickly looking at these iissues you 
  know what the problem is or can suggest something

  I am sure the plugin will do what I am after fro now once I get it 
  activated.

  Lar

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

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


clojure.lib

2010-02-24 Thread cej38
I noticed a thread on the clojure developer's google group last night,
http://groups.google.com/group/clojure-dev/browse_thread/thread/97e5fa7c49f457b2#

I first want to give my vote for including:
io
seq
string

I would also like to see seq include more functionality.  Two
examples, which I use a lot, are:

(defn drop-n [n col]
  Works like nth, but instead of keeping only the nth term, this
keeps everything but the nth term.
  (concat (take (dec n) col) (drop n col)))


(defn flatten-n [n coll]
  Like flatten, but only goes n levels deep.
  (if (= n 0)
coll
(recur (dec n) (apply concat (map #(if (sequential? %) % (list %))
coll)


There are also ideas for other seq functions at:
http://github.com/francoisdevlin/devlinsf-clojure-utils/blob/master/src/lib/sfd/seq_utils.clj

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


Re: clojure-clr how to wire up a delegate

2010-02-24 Thread adam11235
Excellent that worked.

For other clojure-clr newbies, the Clojure.Source project has some
samples that are helpful.

Thanks, Adam.

On Feb 25, 7:39 am, soyrochus iwanvanderkle...@gmail.com wrote:
 Hi Adam,

 You need to use the gen-delegate macro to create delegates,

 Seehttp://wiki.github.com/richhickey/clojure-clr/clr-interop

 The signature of the macro is (gen-delegate Type [args] body) whereby
 in case of event-handlers you would typically use the EventHandler
 class.
 The code becomes then:

 (System.Reflection.Assembly/LoadWithPartialName
 System.Windows.Forms)
 (import '(System.Windows.Forms MessageBox Form Button))

 (defn windowsPlay []
   (let [win (Form.)
         temp-button (Button.)]
     (.. win (get_Controls) (Add temp-button))
     (doto temp-button
       (.set_Top 50)
       (.set_Text Clicky)
       (.add_Click (gen-delegate EventHandler [sender args] (MessageBox/
 Show I got clicked
     (doto win
       (.set_Text hello)
       (.ShowDialog

 (windowsPlay)

 Regards,

 Iwan

 On Feb 24, 7:43 am, adam11235 adam.k.web...@gmail.com wrote:



  Hi,

  I've made progress in creating a simple app to show a windows form,
  however I am having trouble wiring up a delegate (to handle button
  clicks).

  The Java version uses Proxy to implement ActionListener, instead I am
  just trying to create an EventHandler passing as the 2nd constructor
  argument the code I would like executed. (see the .add_Click line)

  The delegate code gets invoked immediately instead of when the button
  click occurs, and then complains it expected a function pointer rather
  than the DialogResult it received (due to execution of the code)

  I tried quoting that code but no success.

  How do you wire up delegates?

  (import '(System.Windows.Forms MessageBox Form Button))

  (defn windowsPlay []
          (let
                  [       win (Form.)
                          temp-button (Button.)
                  ]
          (.. win (get_Controls) (Add temp-button))
          (doto temp-button
                  (.set_Top 50)
                  (.set_Text Clicky)
                  (.add_Click (EventHandler. temp-button (MessageBox/Show I 
  got
  clicked
          (doto win
                  (.set_Text hello)
                  (.ShowDialog

  (windowsPlay)

  Thanks, Adam.

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


Using zip-filter to remove nodes

2010-02-24 Thread James Sofra
Hi all,

I am trying to use (abuse? *) zip-filter to remove some nodes and
return the xml tree to me.
If I do something like this:
(xml1- zipped-xml zf/descendants :model zip/remove zip/root)

I can remove one :model node, but what if I want to remove more than
one or all of the :model nodes?

If I do this:
(xml- zipped-xml zf/descendants :model zip/remove zip/root)

I get multiple xml-trees each with one node removed from each. So I
wrote a function zip-top to take me back to the top (like zip/root
but returns the loc not node) and can do this:
(xml- zipped-xml zf/descendants :model zip/remove zip-top zf/
descendants :model zip/remove zip/root)

and that will remove two of them but that is not really ideal I would
like to remove all of them ... any ideas? am I way off track? is there
better ways to manipulate xml trees in clojure? Enlive maybe? I
haven't played with it yet.

* I realise this probably abusing zip-filter since it is only supposed
to take predicates and zip/remove is not really a predicate.

James

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


Re: Bug in Clojure 1.2 case macro

2010-02-24 Thread pthatcher
Ouch.  Burned by documented behavior :).  Thanks for pointing that
out.

Seriously, though, I'm not the last that will get confused by this.
My suggestion would be to make (case) copy the value from the *var* at
compile time and use that.  In fact, I decided to do just that and
created (case-eval).  I hope it's useful to others also:

(defn count-from [start]
  (iterate inc start))

; like python
(defn zip [ lists]
  (apply map vector lists))

; like python
(defn enumerate [vals]
  (zip (count-from 0) vals))

(defn map-when-index [p? f vals]
  (for [[index val] (enumerate vals)]
(if (p? index)
  (f val)
  val)))

(defn eval-all [val]
  (if (seq? val)
(map eval val)
(eval val)))

;evals the test cases
(defmacro case-eval [e  clauses]
  `(case ~e ~@(map-when-index even? eval-all clauses)))


; these now work:
(def *abc* ABC)

(case-eval ABC
  ABC
:abc)

(case-eval ABC
  *abc*
:abc)

(case-eval ABC
  (*abc*)
:abc)

Find the full code here:

http://gist.github.com/314129


On Feb 23, 10:10 pm, Chouser chou...@gmail.com wrote:
 On Feb 23, 2010, at 8:47 PM, pthatcher pthatc...@gmail.com wrote:

  I noticed a funny bug in Clojure 1.2's case macro.  It doesn't work
  with *vars*.  For example:

  (def *a* a)

  ;this is true
  (case a
  a true
  false)

  ;but this is false!
  (case a
  *a* true
  false)

 If you read the first line or two of the docs for case I think you'll  
 see it's not a bug but documented behavior.  The values in the case  
 test clauses must be constants, so not a var or local.  If you need  
 those test values to be evaluated then your work around of using  
 condp (or cond) is entirely appropriate.

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


Re: Bug in Clojure 1.2 case macro

2010-02-24 Thread Chouser
On Wed, Feb 24, 2010 at 8:57 PM, pthatcher pthatc...@gmail.com wrote:
 Ouch.  Burned by documented behavior :).  Thanks for pointing that
 out.

 Seriously, though, I'm not the last that will get confused by this.
 My suggestion would be to make (case) copy the value from the *var* at
 compile time and use that.

But eval at compile time is completely different than eval at
runtime, and not generally not useful.

 ; these now work:
 (def *abc* ABC)

 (case-eval ABC
  ABC
    :abc)

 (case-eval ABC
  *abc*
    :abc)

 (case-eval ABC
  (*abc*)
    :abc)

Sure, but these don't:

(let [xyz XYZ] (case-eval XYZ xyz :xyz))
java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.UnsupportedOperationException: Can't eval locals
(NO_SOURCE_FILE:36) (NO_SOURCE_FILE:36)


(def *xyz* update later)
(defn xyz? [] (case-eval XYZ *xyz* :xyz))
(def *xyz* XYZ)
(xyz?)
java.lang.IllegalArgumentException: No matching clause: XYZ (NO_SOURCE_FILE:0)

The first case fails because locals don't have values yet when
macros used in their scope are being expanded.

The second case fails because the var's value is inserted into
the expanded code before it's updated.

The implementation of 'case' is built around the test values
being constants, and when that's what you have offers excellent
performance.  If your test values are not known until runtime,
use 'if', 'cond', or 'condp'.

--Chouser
http://joyofclojure.com/

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


Re: Using zip-filter to remove nodes

2010-02-24 Thread Chouser
On Wed, Feb 24, 2010 at 8:09 PM, James Sofra james.so...@gmail.com wrote:
 Hi all,

 I am trying to use (abuse? *) zip-filter to remove some nodes and
 return the xml tree to me.
 If I do something like this:
    (xml1- zipped-xml zf/descendants :model zip/remove zip/root)

 I can remove one :model node, but what if I want to remove more than
 one or all of the :model nodes?

 If I do this:
    (xml- zipped-xml zf/descendants :model zip/remove zip/root)

 I get multiple xml-trees each with one node removed from each. So I
 wrote a function zip-top to take me back to the top (like zip/root
 but returns the loc not node) and can do this:
    (xml- zipped-xml zf/descendants :model zip/remove zip-top zf/
 descendants :model zip/remove zip/root)

 and that will remove two of them but that is not really ideal I would
 like to remove all of them ... any ideas? am I way off track? is there
 better ways to manipulate xml trees in clojure? Enlive maybe? I
 haven't played with it yet.

 * I realise this probably abusing zip-filter since it is only supposed
 to take predicates and zip/remove is not really a predicate.

You have correctly identified the behavior of zip-filter and its
negative consequences.  I didn't realize until too late that my
design for zip-filter essentially prevents using it to edit more
than a single filter result.  I haven't thought deeply about what
could be done to fix it -- I think it would have to be pretty
radical.  Instead of returning a lazy seq it would have to have
some kind of mechanism for continuation, or perhaps using a monad
or one of these new cells.

Christophe Grand's enlive lib address a lot of these problems
for html and some xml.  I'd recommend you take a look at it and
see if it would work in your case.

--Chouser
http://joyofclojure.com/

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


Re: clojure.lib

2010-02-24 Thread Sean Devlin
Rich has stated in a later thread on the dev list that he's more
concerned with library refinement for the time being.  The idea seemed
to be that our efforts should be placed in getting signatures right 
improving performance.  I'm all for having the what if discussions,
but now doesn't seem to be the right time for adding features.
Hopefully there will be time for this in the future.

Sean

On Feb 24, 5:51 pm, cej38 junkerme...@gmail.com wrote:
 I noticed a thread on the clojure developer's google group last 
 night,http://groups.google.com/group/clojure-dev/browse_thread/thread/97e5f...

 I first want to give my vote for including:
 io
 seq
 string

 I would also like to see seq include more functionality.  Two
 examples, which I use a lot, are:

 (defn drop-n [n col]
   Works like nth, but instead of keeping only the nth term, this
 keeps everything but the nth term.
   (concat (take (dec n) col) (drop n col)))

 (defn flatten-n [n coll]
   Like flatten, but only goes n levels deep.
   (if (= n 0)
     coll
     (recur (dec n) (apply concat (map #(if (sequential? %) % (list %))
 coll)

 There are also ideas for other seq functions 
 at:http://github.com/francoisdevlin/devlinsf-clojure-utils/blob/master/s...

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


Re: Bug in Clojure 1.2 case macro

2010-02-24 Thread Michael Wood
On 25 February 2010 03:57, pthatcher pthatc...@gmail.com wrote:
[...]
 (defn count-from [start]
  (iterate inc start))

 ; like python
 (defn zip [ lists]
  (apply map vector lists))

 ; like python
 (defn enumerate [vals]
  (zip (count-from 0) vals))
[...]

By the way, there's an implementation of enumerate called indexed
in clojure.contrib.seq-utils (or clojure.contrib.seq in master):

(defn indexed
  Returns a lazy sequence of [index, item] pairs, where items come
  from 's' and indexes count up from zero.

  (indexed '(a b c d))  =  ([0 a] [1 b] [2 c] [3 d])
  [s]
  (map vector (iterate inc 0) s))

Basically the same as yours, but as a single function.  Also, if you
use it you don't have to write it yourself :)

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

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