Re: android app development with clojure

2009-02-04 Thread Remco van 't Veer

Caching Reflector.getMethods, as described below, works pretty well.
Performance seems acceptable for now.  Startup time is still dramatic,
need to investigate.  Considering releasing changes as a fork on
github is anybody is interested.


On Sat, Jan 31, 2009 at 8:35 PM, Remco van 't Veer  wrote:
> Some naive caching code does speed up my sample by 4 times.  Will
> investigate further later this week, need to take my flu to bed now..
>
>
> diff --git a/src/jvm/clojure/lang/Reflector.java
> b/src/jvm/clojure/lang/Reflector.java
> index f530b78..eccebb8 100644
> --- a/src/jvm/clojure/lang/Reflector.java
> +++ b/src/jvm/clojure/lang/Reflector.java
> @@ -296,7 +296,21 @@ static public Field getField(Class c, String
> name, boolean getStatics){
>return null;
>  }
>
> +static private java.util.Map methodsCache = new
> java.util.HashMap();
> +
>  static public List getMethods(Class c, int arity, String name,
> boolean getStatics){
> +synchronized (methodsCache) {
> +String key = "" + c + "-" + arity + " " + name + " " + getStatics;
> +if (methodsCache.containsKey(key)) {
> +return methodsCache.get(key);
> +} else {
> +List methods = originalGetMethods(c, arity, name, getStatics);
> +methodsCache.put(key, methods);
> +return methods;
> +}
> +}
> +}
> +static public List originalGetMethods(Class c, int arity, String
> name, boolean getStatics){
>Method[] allmethods = c.getMethods();
>ArrayList methods = new ArrayList();
>ArrayList bridgeMethods = new ArrayList();
>
>
> On Sat, Jan 31, 2009 at 3:55 PM, Remco van 't Veer  wrote:
>> I've been playing around with clojure on the android platform.  To my
>> surprise it was pretty easy to get running, after removing the bean
>> method from the clojure.jar as hinted by Rich somewhere.   Of course
>> clojure code needs to be compiled AOT and eval doesn't work, as was to
>> be expected, but all seems to run fine otherwise.
>>
>> There's a problem though, it's really slow..  I've played around with
>> the tracing tools of the android sdk and noticed about half of the
>> time spend is doing reflection related things.  Reflection on Android/
>> Dalvik is known to be slow.  At the top of the method list sorted by
>> exclusive times is clojure/lang/Reflector.getMethods with a 10% score
>> of total time spend, followed by java/lang/reflect/
>> ReflectionAccessImpl.clone, java/lang/reflect/Method.,  java/
>> lang/ClassCache.deepCopy, java/lang/reflect/Method.getName and java/
>> lang/String.equals and java/lang/reflect/AccessibleObject..
>>
>> My test case was pretty simpel; get the public-time-line from twitter,
>> parse it with xml/parse (needs a small tweak to work on android btw),
>> populate some struct-maps and display a listview.  Unfortunately this
>> simple task takes about 12 seconds to complete on a g1 phone.
>>
>> So I setup *warn-on-reflection* and put type hints in all the
>> appropriate places but didn't detect any performance improvements.
>> Then I ran compile-clojure in the clojure source tree with an adjusted
>> compiler to see the reflection warning in the core.  This yields about
>> 40 warnings and I wonder if fixing those will improve performance at
>> all.
>>
>> Another approach is to try and speedup clojure/lang/
>> Reflector.getMethods by caching results.  Any idea's on what route
>> will get me the best results?
>>
>> Thanks,
>> Remco
>

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



Re: Possible bug in preduce

2009-02-04 Thread Zak Wilson

I got a 50% speedup using psort instead of sort with a compute-
intensive comparator and a 100 element sequence on a dual-core
machine.

That said, I found a faster way to do it: I separated the intensive
calculations from the comparator - just returning a numeric value. I
used pmap to get a sequence of structs of item and value, which I
sorted by value using a regular sort. This version was 80% faster than
the original.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Possible bug in preduce

2009-02-04 Thread Anand Patil



On Feb 3, 11:09 pm, Rich Hickey  wrote:
> On Feb 3, 4:43 pm, Anand Patil 
> wrote:

> No, it's not. as the docs for preduce say:http://clojure.org/api#preduce
>
> "Also note that (f base an-element) might be performed many times"
>
> in fact, an arbitrary number of times depending on how many parallel
> tasks are fired up. So, the function with base value should produce an
> identity, e.g. (+ 0 x) and (* 1 x), and your q with 0 does not.

Ah, thanks. I interpreted the docs as meaning preduce might do this:

(q (q (q 2 0) (q 3 0)) (q 1 0))

meaning (f base an-element) is performed many times, but just once per
an-element. I didn't understand that f with base needed to be an
identity.

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



Re: SVN branches

2009-02-04 Thread Frantisek Sodomka

Streams were also intended for I/O. Is lazier addition also able to
cope with I/O sucessfully?
Can we have both - streams and lazy-seq?

My thought about streams is that if they get included, they could be
looked at as unsafe operations in Java/C# or unchecked math operations
- as long as programmer knows what he is doing, it is fine...

Frantisek


On 3 Ún, 15:31, Rich Hickey  wrote:
> On Feb 2, 2:27 pm, Chouser  wrote:
>
> > On Mon, Feb 2, 2009 at 2:05 PM, MikeM  
> > wrote:
>
> > > There is a "lazy" branch in SVN. The "streams" branch has been
> > > discussed, but I haven't seen any discussion of the "lazy" branch -
> > > perhaps I missed it.
>
> > Here's a discussion from earlier today, mainly about the "lazy" branch:
>
> >http://clojure-log.n01se.net/date/2009-02-02.html#09:47
>
> I've started documenting the lazy branch work here:
>
> http://clojure.org/lazier
>
> Feedback 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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: My SLIME installation diary

2009-02-04 Thread Craig McDaniel

Thanks Stuart. Since the clojure-contrib.jar you built in step 3 does
include both clj and class files, I think you can reduce

 (setq swank-clojure-extra-classpaths
   (list "/Users/stuart/Projects/clj/contrib/src"
 "/Users/stuart/Projects/clj/contrib/classes"))

to

 (setq swank-clojure-extra-classpaths
   (list "/Users/stuart/Projects/clj/contrib/clojure-
contrib.jar"))

-Craig

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



Re: java.lang.NoClassDefFoundError: clojure/main

2009-02-04 Thread Terrence Brannon

well, I found technomancy's update of clojure mode... there was
something very odd though.

each time I would 'git clone' it, I would end up with the jochu source
code instead... even though .git/config pointed to technomancy's
github location!

I had to manually download the .zip file and unpack it!

My working .emacs config is here -
http://paste.lisp.org/display/74865

inlined for convenience -
;;; clojure-mode
;;; http://github.com/technomancy/clojure-mode/tree/master

(add-to-list 'load-path "c:/tmp/c/technomancy-clojure-mode")
(require 'clojure-mode)

(setq clojure-src-root "c:/tmp/c")
(clojure-slime-config)

(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))




On Feb 3, 10:17 pm, Terrence Brannon  wrote:
> Hello, I cannot get slime and clojure-mode up and running:
>
> ;;; inferior lisp output
>
> (add-classpath "file:///c:/Documents and Settings/Administrator/
> Application Data/emacs-contrib/swank-clojure/")
>
> (require 'swank.swank)
>
> (swank.swank/ignore-protocol-version "2009-01-30")
>
> (swank.swank/start-server "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/slime.
> 21424" :encoding "iso-latin-1-unix")
>
> java.lang.NoClassDefFoundError: clojure/main
> Caused by: java.lang.ClassNotFoundException: clojure.main
>         at java.net.URLClassLoader$1.run(Unknown Source)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
> Could not find the main class: clojure.main.  Program will exit.
> Exception in thread "main"
> Process inferior-lisp exited abnormally with code 1
>
> ;;; .emacs
>
> ;;; clojure-mode
>
> ;;;http://github.com/nablaone/slime/tree/master
> (add-to-list 'load-path "~/emacs-contrib/slime")
>
> ;;;http://github.com/jochu/swank-clojure/tree/master
> (add-to-list 'load-path "~/emacs-contrib/swank-clojure")
>
> ;;;http://github.com/jochu/clojure-mode/tree/master
> (add-to-list 'load-path "~/emacs-contrib/clojure-mode")
>
> (require 'slime)
>
> (autoload 'slime "slime" "" t)
> ;(swank-clojure-config (setq swank-clojure-jar-path "~/src/clojure/
> clojure.jar"))
> (setq swank-clojure-jar-path "~/src/clojure/clojure.jar")
>
> ;(setq swank-clojure-extra-classpaths '("~/src/clojure-contrib/clojure-
> contrib.jar"))
>
> ;; (setq swank-clojure-binary "clojure")
> ;(require 'clojure-auto)
> (require 'swank-clojure-autoload)
>
> (autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
> (add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: SVN branches

2009-02-04 Thread Rich Hickey



On Feb 4, 7:21 am, MikeM  wrote:
> > Other than that, there is just the general loss of nil-punning. This
> > was the theoretical problem that kept me from making this tradeoff
> > earlier. I'm very much interesting in hearing from those for whom the
> > lazy branch represents a real problem due to loss of nil punning.
>
> To preserve nil-punning, could the 'if' special form be changed to
> internally perform the equivalent of the seq call when presented with
> a sequence? Since more is guaranteed to never return nil, in the
> context of an 'if', a seq call would always be appropriate. I suppose
> there's a performance hit for checking whether the argument is a
> Sequence before calling seq on it, but instanceof is supposed to be
> very fast with hotspot.

I don't think a fundamental primitive like 'if' could be burdened with
such a check. Also, most collections can be supplied when their seq is
required, but what would this return?

(if [] true false)

I'd hate to lose the ability to distinguish between an empty
collection and nothing.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Stupid Java questions

2009-02-04 Thread Anand Patil

I agree & don't mean to complain. I'm just flagging the issues to make
it easier for whoever goes through the docs after clojure 1.0 is
tagged.

Anand

On Feb 4, 9:45 am, Zak Wilson  wrote:
> The namespace is correct on clojure.org/api, but there it doesn't
> mention that it has a dependency that isn't included with Clojure.
>
> Clojure has been evolving very quickly, and sometimes the website
> doesn't keep up. It might be nice if somebody could take charge of
> making sure the site is up to date, but right now I'd rather keep
> being thrilled by the fact that the feature I find myself needing
> today was just added yesterday.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: SVN branches

2009-02-04 Thread Rich Hickey



On Feb 4, 1:45 am, Mark Engelberg  wrote:
> One thing I couldn't tell from the "lazier" doc is whether rest is
> only being kept around for backward compatibility or whether there
> still might be reasons to actively prefer rest to more.

rest is being kept for compatibility and ease of use. It can be quite
convenient on the consuming/terminal end of the chain, but its
continued use in lazy sequence functions is suspect.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: SVN branches

2009-02-04 Thread Rich Hickey



On Feb 4, 6:55 am, Frantisek Sodomka  wrote:
> Streams were also intended for I/O. Is lazier addition also able to
> cope with I/O successfully?

Yes. After full laziness, most of the issues with I/O have to deal
with resource management, which I plan to deal with a la carte with
the scope construct.

> Can we have both - streams and lazy-seq?
>

I'm not sure we'll have either. I've been working on streams, fully-
lazy sequences and left fold enumerators in an effort to resolve what,
if any, breaking changes would be required to address the problems
they solve:

1) Resource management in lazy contexts
2) Memory consumption in recursive lazy contexts (the filter retains
skipped range issue)
3) Full laziness in I/O and other side-effect contexts, and for ease
of understanding
4) Performance/elegance

1 - As I said, the resource management is orthogonal and solved with
scope.

2 - I can probably back-port the 'clear closed-overs on tail call' in
once-only closures to the current lazy-cons model.

3 - I thought the demand for full laziness was greater than it
apparently is, given the lack of feedback on these features.

4 - Right now there is a plain tradeoff of elegance for performance,
and I'm not satisfied with that.

> My thought about streams is that if they get included, they could be
> looked at as unsafe operations in Java/C# or unchecked math operations
> - as long as programmer knows what he is doing, it is fine...
>

While unsafe math ops live in the bowels of tight loops, streams are
interface points. That's why the API I've come up with for them is
safe.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Rich Hickey



On Feb 3, 10:44 pm, Jason Wolfe  wrote:
> This just bit me a second time, since one of my revised set functions
> uses "contains?" and thus doesn't work on java.util.Sets (or even
> the .keySets of Clojure maps).
>
> user> (contains? (.keySet {:a :b}) :a)
> false
>
> It seems that all that's required to make "contains?" work on general
> Sets is to replace "IPersistentSet" with "Set" on lines 648 and 649 of
> RT.java.  I can make a patch if desired.
>

Patch welcome - must handle both overloads of RT.get() - 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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Rich Hickey



On Feb 3, 11:16 pm, "Stephen C. Gilardi"  wrote:
> On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>
> > user> (contains? (.keySet {:a :b}) :a)
> > false
>
> > It seems that all that's required to make "contains?" work on general
> > Sets is to replace "IPersistentSet" with "Set" on lines 648 and 649 of
> > RT.java.  I can make a patch if desired.
>
> Along those lines, would it be a good idea for the object returned by
> clojure.core/keys to implement java.util.Set and/or
> clojure.lang.IPersistentSet?
>

Right now keys is just a filter on the seq of the map. I wouldn't be
opposed to it being an IPersistentSet, but keys must be a constant-
time operation, so the set would have to be a view on the map, not a
copy of the keys.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: rules for writing macros

2009-02-04 Thread Stuart Halloway

Thanks Mark, Chouser,

I will update that section of the book with a corrected example in  
Beta 7.

Cheers,
Stuart

>
> On Tue, Feb 3, 2009 at 11:26 AM, Mark Volkmann
>  wrote:
>>
>> Now I remember what I was thinking about. This isn't so much a
>> difference between macros and functions as it is a rule about
>> something you cannot do in a macro. Quoting from "Programming  
>> Clojure"
>> ...
>>
>> "You cannot write a macro that expands to any of the syntactic sugar
>> forms ... For example, you cannot write a macro that
>> expands to (Math/PI)."
>
> Hm...
>
> (defmacro pi [] 'Math/PI)  ==> #'user/pi
> (macroexpand '(pi))  ==> Math/PI
> (pi)  ==> 3.141592653589793
>
> (defmacro strlen [s] `(.length ~s))  ==> #'user/strlen
> (strlen "hello")  ==> 5
>
> (defmacro mydoc [s] `(:doc ^#'~s))  ==> #'user/mydoc
> (macroexpand '(mydoc doc))  ==> (:doc (clojure.core/meta (var doc)))
> (mydoc doc)  ==> "Prints documentation for a var or special form  
> given its name"
>
> That's a whole lot of sugar that all seems to work ok.  Is there some
> other syntactic sugar form that does not work?  Perhaps he's referring
> to actually producing reader macro usages, like this:
>
> (defmacro mydoc2 [s] `(:doc ~(symbol (str "^#'" s  ==> #'user/ 
> mydoc2
> (macroexpand '(mydoc2 doc))  ==> (:doc ^#'doc)
> (mydoc2 doc)  ==> java.lang.Exception: Unable to resolve symbol:  
> ^#'doc
>
> --Chouser
>
> >


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



Re: SVN branches

2009-02-04 Thread Rich Hickey



On Feb 4, 9:03 am, MikeM  wrote:
> > (if [] true false)
>
> > I'd hate to lose the ability to distinguish between an empty
> > collection and nothing.
>
> As a trade-off to allow nil-punning, you could stipulate the use of
> coll? in the above situation:
> (if (coll? []) true false) => true
> This seems less burdensome - fewer cases where I'd need to do this vs
> (if (seq s) ...

I'm not seriously considering this. As I said, 'if' can't be burdened
with this kind of a check.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Questions about a Clojure Datalog

2009-02-04 Thread Timothy Pratley

> providing relations from clojure-sets and sql-queries.

Wow - this is really neat Erik - thanks for showing

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



Re: clojure.contrib.sql and inner joins

2009-02-04 Thread Stephen C. Gilardi

Hi Brian,

On Feb 4, 2009, at 9:21 AM, BrianS wrote:


However, whenever I insert
a SQL query that contains an inner join command (standard SQL), I get
the following error:
java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.IllegalArgumentException: Too many arguments to struct
constructor (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4186)
...and more


with-query-results uses resultset-seq which does not handle result  
sets with duplicate column names. There's an issue about it with  
pointers to previous discussions:


http://code.google.com/p/clojure/issues/detail?id=33&q=result&colspec=ID%20Type%20Status%20Priority%20Reporter%20Owner%20Summary

That sounds like what's going on in your example. Can you please  
confirm?


Thanks,

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: android app development with clojure

2009-02-04 Thread igorrumiha

On Feb 4, 10:12 am, "Remco van 't Veer"  wrote:
> Caching Reflector.getMethods, as described below, works pretty well.
> Performance seems acceptable for now.  Startup time is still dramatic,
> need to investigate.  Considering releasing changes as a fork on
> github is anybody is interested.
>

I would also be interested in running Clojure on the Android. I tried
running a "Hello world" application on the emulator but the startup
time od 15 seconds put me off. There is definitely room for
improvement. I don't have much experience in Java (zero would be the
best description) so I don't really know where to start with
profiling.

I've run the application through the Instrumentation mechanism and the
trace shows me that much of the time is spent in a huge amount of
calls to some character compare methods (something like 20 calls)
(I don't have the trace with me right now so I don't have the exact
numbers and I don't know the exact method name).

I find this curious when I know that all code is compiled ahead of
time. When I get the chance I will recreate that call graph an upload
it to the files section.

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



Re: SVN branches

2009-02-04 Thread Rich Hickey



On Feb 4, 9:19 am, Konrad Hinsen  wrote:
> On 04.02.2009, at 14:03, Rich Hickey wrote:
>
> > 1) Resource management in lazy contexts
> > 2) Memory consumption in recursive lazy contexts (the filter retains
> > skipped range issue)
> > 3) Full laziness in I/O and other side-effect contexts, and for ease
> > of understanding
> > 4) Performance/elegance
> > 3 - I thought the demand for full laziness was greater than it
> > apparently is, given the lack of feedback on these features.
>
> I'd say the most immediate need is for I/O, including network access.
> I have a couple of other applications in mind, for example
> computational pipellines, but those will take a while to implement.
> Perhaps Clojure is too young for much demand to appar on this list.
>

It's come up many times - a frequent complaint of those coming from
Haskell, and a definite expectation of those using side-effects with
map et al.

> > 4 - Right now there is a plain tradeoff of elegance for performance,
> > and I'm not satisfied with that.
>
> What is the main reason for the performance loss in new-style lazy
> sequences? Memory allocation? Creation of the closures that represent
> the state of data generation?
>

There's allocation and more indirection.

> Would it be possible to have new-style lazy seqs plus a generator
> interface as for streams?

Yes. If/when I combine the streams with the new sequences, the streams
will terminate in sequences, not seqs.

> That could take the form of a function that
> takes a generator and presents it as a fully sequence. Generator
> functions that manage their own state would serve two purposes: (1)
> an efficient alternative to recursive sequence-producing functions
> for optimizing critical pieces of code, and (2) a straightforward way
> to use code in Java or another JVM language to define a stream of data.
>

There are many easy paths to the latter, including via iterators.

As for the former, yes, the streams are currently most efficient. But
that would behoove me to use them for the core functions map, filter
et al, leaving no examples of clean recursive algorithms in core, only
ugly stream stuff. I'm not yet resigned to that.

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.sql and inner joins

2009-02-04 Thread Stephen C. Gilardi


On Feb 4, 2009, at 9:46 AM, Stephen C. Gilardi wrote:

That sounds like what's going on in your example. Can you please  
confirm?


Also, if you have one handy, could you please send me a short,  
standalone example of code that triggers the problem? I'd like to look  
at how clojure.contrib.sql can best handle this case.


Thanks,

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: SVN branches

2009-02-04 Thread Konrad Hinsen


On 04.02.2009, at 15:03, MikeM wrote:

> This seems less burdensome - fewer cases where I'd need to do this vs
> (if (seq s) ...

A slightly off-topic comment: I wonder why the (if (seq s)...) idiom  
is so important. It is completely unintellegible to a reader who is  
not aware of the idiomatic use of seq. The first time I saw it, I  
looked up the documentation for seq and was still wondering what the  
code was doing. There is the nice convention of having test  
predicates end in ?, so I'd expect to see something like (if (non- 
empty? s) ...)

Konrad.



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



Re: clojure.contrib.sql and inner joins

2009-02-04 Thread BrianS

Steve,
   Big apologies, I should have done just a little more investigating
before posting.  I serve as my team's DBA, so I should rightfully
abhor the "SELECT * ", but that is what was causing the
problem:duplicate column names in the returnset, as you said above.
Once I substituted actual
column names in the SELECT portion of the statement, the inner joins
started working as they should.  As always, thanks for the attention,
assistance, and the original work in clojure.contrib.sql, it has all
been VERY helpful to me.

Brian

On Feb 4, 10:02 am, "Stephen C. Gilardi"  wrote:
> On Feb 4, 2009, at 9:46 AM, Stephen C. Gilardi wrote:
>
> > That sounds like what's going on in your example. Can you please  
> > confirm?
>
> Also, if you have one handy, could you please send me a short,  
> standalone example of code that triggers the problem? I'd like to look  
> at how clojure.contrib.sql can best handle this case.
>
> Thanks,
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: SVN branches

2009-02-04 Thread MikeM


>
> (if [] true false)
>
> I'd hate to lose the ability to distinguish between an empty
> collection and nothing.
>
As a trade-off to allow nil-punning, you could stipulate the use of
coll? in the above situation:
(if (coll? []) true false) => true
This seems less burdensome - fewer cases where I'd need to do this vs
(if (seq 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
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: SVN branches

2009-02-04 Thread MikeM


>
> Other than that, there is just the general loss of nil-punning. This
> was the theoretical problem that kept me from making this tradeoff
> earlier. I'm very much interesting in hearing from those for whom the
> lazy branch represents a real problem due to loss of nil punning.
>
To preserve nil-punning, could the 'if' special form be changed to
internally perform the equivalent of the seq call when presented with
a sequence? Since more is guaranteed to never return nil, in the
context of an 'if', a seq call would always be appropriate. I suppose
there's a performance hit for checking whether the argument is a
Sequence before calling seq on it, but instanceof is supposed to be
very fast with hotspot.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: SVN branches

2009-02-04 Thread Konrad Hinsen


On 04.02.2009, at 14:03, Rich Hickey wrote:

> 1) Resource management in lazy contexts
> 2) Memory consumption in recursive lazy contexts (the filter retains
> skipped range issue)
> 3) Full laziness in I/O and other side-effect contexts, and for ease
> of understanding
> 4) Performance/elegance


> 3 - I thought the demand for full laziness was greater than it
> apparently is, given the lack of feedback on these features.

I'd say the most immediate need is for I/O, including network access.  
I have a couple of other applications in mind, for example  
computational pipellines, but those will take a while to implement.  
Perhaps Clojure is too young for much demand to appar on this list.

> 4 - Right now there is a plain tradeoff of elegance for performance,
> and I'm not satisfied with that.

What is the main reason for the performance loss in new-style lazy  
sequences? Memory allocation? Creation of the closures that represent  
the state of data generation?

Would it be possible to have new-style lazy seqs plus a generator  
interface as for streams? That could take the form of a function that  
takes a generator and presents it as a fully sequence. Generator  
functions that manage their own state would serve two purposes: (1)  
an efficient alternative to recursive sequence-producing functions  
for optimizing critical pieces of code, and (2) a straightforward way  
to use code in Java or another JVM language to define a stream of data.

Konrad.



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



Re: Stupid Java questions

2009-02-04 Thread Zak Wilson

The namespace is correct on clojure.org/api, but there it doesn't
mention that it has a dependency that isn't included with Clojure.

Clojure has been evolving very quickly, and sometimes the website
doesn't keep up. It might be nice if somebody could take charge of
making sure the site is up to date, but right now I'd rather keep
being thrilled by the fact that the feature I find myself needing
today was just added yesterday.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: My SLIME installation diary

2009-02-04 Thread bOR_

As we never can have enough examples, and this one was about the
simplest that just worked on Ubuntu, I'll paste my variant of it here.
It is slightly different because I'm behind a proxy, and thus my git
calls are somewhat different, and I got my slime from a git repository
rather than a cvs one.

;; compiled together from http://riddell.us/clojure/ and
;; 
http://groups.google.com/group/clojure/browse_thread/thread/bb2445519f74dcef/e725f3cab7e6a76

;; run from ~/opt
svn checkout http://clojure.googlecode.com/svn/trunk/ clojure
svn checkout http://clojure-contrib.googlecode.com/svn/trunk/ contrib

;;cvs -d :pserver:anonymous:anonym...@common-lisp.net:/project/slime/
cvsroot co slime
;; Doesn't work for me, might be something with my proxy. As an
alternative:
git clone http://git.boinkor.net/git/slime.git


git clone http://github.com/jochu/clojure-mode.git clojure-mode
git clone http://github.com/jochu/swank-clojure.git swank-clojure

cd clojure
ant
cd ..
cd contrib
ant -Dclojure.jar=../clojure/clojure.jar
cd ..


;; put the below in ~/.emacs, and uncomment the
;; comments that start with only 1 ;
;(add-to-list 'load-path "~/opt/clojure-mode")
;(require 'clojure-mode)

;; Swank bit
;; Instructions from
;; http://github.com/jochu/swank-clojure/tree/master
;;
;(add-to-list 'load-path "~/opt/swank-clojure")
;(require 'swank-clojure-autoload)
;(swank-clojure-config
;   (setq swank-clojure-jar-path "~/opt/clojure/clojure.jar")
;   (setq swank-clojure-extra-classpaths (list
;   "~/opt/contrib/src"
;   "~/opt/contrib/classes"
;   "~/.clojure")))
;
;
;(add-to-list 'load-path "~/opt/slime")
;(require 'slime)
;(slime-setup)



;; Uncomment to turn off the "beep" which sounded
;; everytime the top or bottom of a file was reached
;(setq ring-bell-function 'ignore)


On Dec 23 2008, 7:15 pm, Stuart Sierra 
wrote:
> Hi folks,
>
> Up 'till now I've been perfectly happy with Emacs' inferior-lisp mode,
> but I decided to try SLIME.  Since there seem to be a lot of questions
> about SLIME, I thought I would make a record of everything I did to
> get it set up.  This is on OSX with Aquamacs.  I'm setting up Clojure,
> clojure-contrib, SLIME, swank-clojure, clojure-mode, and paredit.
>
> Step 1: prepare a space
>
>     cd /Users/stuart/Projects
>     mkdir clj
>     cd clj
>
> Step 2: get the latest sources of everything
>
>     svn checkouthttp://clojure.googlecode.com/svn/trunk/clojure
>     svn checkouthttp://clojure-contrib.googlecode.com/svn/trunk/
> contrib
>     cvs -d :pserver:anonymous:anonym...@common-lisp.net:/project/slime/
> cvsroot co slime
>     git clone git://github.com/jochu/clojure-mode.git clojure-mode
>     git clone git://github.com/jochu/swank-clojure.git swank-clojure
>
> Step 3: compile everything
>
>     cd clojure
>     ant
>     cd ..
>     cd contrib
>     ant -Dclojure.jar=../clojure/clojure.jar
>     cd ..
>
> Step 3: edit Emacs configuration.  Since this is Aquamacs, I edited
> ~/Library/Preferences/Aquamacs Emacs/Preferences.el
> to add the following lines:
>
>     (push "/Users/stuart/Projects/clj/clojure-mode" load-path)
>     (load-library "clojure-auto")
>     (load-library "clojure-paredit")
>
>     (push "/Users/stuart/Projects/clj/swank-clojure" load-path)
>     (require 'swank-clojure-autoload)
>     (swank-clojure-config
>      (setq swank-clojure-jar-path
>            "/Users/stuart/Projects/clj/clojure/clojure.jar")
>      (setq swank-clojure-extra-classpaths
>            (list "/Users/stuart/Projects/clj/contrib/src"
>                  "/Users/stuart/Projects/clj/contrib/classes")))
>
>     (push "/Users/stuart/Projects/clj/slime" load-path)
>     (require 'slime)
>     (slime-setup)
>
> Step 4: restart Emacs
>
> Step 5: In Emacs, enter: M-x slime
>
> Step 6: SLIMEy, Clojurey goodness!
>
> The only snag I ran into was figuring out that swank-clojure has to be
> loaded BEFORE slime in the Emacs configuration.
>
> -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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: rules for writing macros

2009-02-04 Thread H Durer

Marde, Feb 3, 2009 at 14:24, Konrad Hinsen  skribis:
[...]
> I can't think of anything that would be "forbidden" in a macro but
> "allowed" in a plain function. There are many things that don't make
> sense in a macro, of course: launching agents, opening windows, ...

Well, for normal functions you have macros to avoid the usual eager
applicative rule of argument evaluation.
This allows you to build e.g. infinte data structures (assuing you
don't try to evaluate it all thus findining the limits of your JVM).
There is I think no equivalent for macros, i.e. you cannot write a
macro that expands into an infinite program (well, you can I guess but
the compiler will soon show you the limits of the JVM again).

Holger

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



clojure.contrib.sql and inner joins

2009-02-04 Thread BrianS

This may be a duplicate post, if so I apologize. I am having a problem
while investigating the inner workings and capabilities of the
clojure.contrib.sql class, specifically with the "inner join" syntax.
I have a function that returns recordset maps that is taken directly
from the test.clj file in the clojure.contrib.sql folder.  It returns
data properly from database (works with SQL Server and HSQLDB so far),
even works when calling stored procedures.  However, whenever I insert
a SQL query that contains an inner join command (standard SQL), I get
the following error:
java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.IllegalArgumentException: Too many arguments to struct
constructor (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4186)
...and more

My function is simple:
(defn db-join-read
  "Read joined counties and states tables"
  []
  (sql/with-connection
   db
   (sql/with-query-results
res
["SELECT * FROM counties inner join states on counties.StateJID =
states.StateID"]
 (dorun (map #(println %) res)

If I substitute the other types of SQL statements mentioned above
(SELECT statements from one table, stored procedures, anything other
than inner join statements) into the string that is in the vector in
the function, everything executes ok, and I get back maps of
records.

However, inner joins generate the error above, both using Microsoft's
SQL Server JDBC driver and in HSQLDB using its own JDBC driver, so I
suspect the problem lies in the clojure.contrib.sql code, either I am
not formatting inner join statements properly for  clojure.contrib.sql
(which is entirely possible), or there is an issue with SQL inner
joins (maybe how JDBC implements them?) and this library.

Does anyone have any sample code which uses clojure.contrib.sql and
utilizes INNER JOIN statements.  My only other option is to include
all inner join queries in stored procedures (which I know are executed
properly even if there are inner join with the SP). Thanks in advance
for any assistance.

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



Re: London Clojurians

2009-02-04 Thread H Durer

2009/2/3 AndrewC. :
[...]
> The people at Scheme UK have (very) occasional meetings in Shoreditch.
> We could join up with them and get a few more people, perhaps.
>
> http://upcoming.yahoo.com/group/4654/
>
> Perhaps someone could do an introductory talk 'Clojure for Schemers'
> and then move on to Compojure.

I agree -- the schemers group has been quite quiet lately; I'd think
they welcome new faces and interesting talks even if not directly
Scheme related.

I just wish their meetings weren't always on a Wednesday...

Holger

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



Re: android app development with clojure

2009-02-04 Thread Remco van 't Veer
Having a lisp to do android app development is definately worth some efford.
Kawa already has some android support in svn trunk but it doesn't seem in a
usable state; my experiments break because a lot of expressions do not seem
to compile AOT. The parts that do compile are very fast on the other hand.

But if it comes down to app development I would of course prefer clojure
over kawa's schema and scheme over java..

I hope to do some tracing to find out what slowing down the startup later
this week and will keep the list in formed. If anybody has any suggestions
please yes pretty please.

Remco

On Feb 4, 2009 3:59 PM, "igorrumiha"  wrote:

On Feb 4, 10:12 am, "Remco van 't Veer"  wrote: >
Caching Reflector.getMethods,...
I would also be interested in running Clojure on the Android. I tried
running a "Hello world" application on the emulator but the startup
time od 15 seconds put me off. There is definitely room for
improvement. I don't have much experience in Java (zero would be the
best description) so I don't really know where to start with
profiling.

I've run the application through the Instrumentation mechanism and the
trace shows me that much of the time is spent in a huge amount of
calls to some character compare methods (something like 20 calls)
(I don't have the trace with me right now so I don't have the exact
numbers and I don't know the exact method name).

I find this curious when I know that all code is compiled ahead of
time. When I get the chance I will recreate that call graph an upload
it to the files section.

--
IgorR

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



Re: rules for writing macros

2009-02-04 Thread CuppoJava

Personally I find that the clearest way to think about macros, is to
treat them like a *very* advanced search-and-replace feature.
Just keep in mind that macros expand into code, and check to make sure
that your generated code is indeed valid code.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Type hint Java array of your own Java class

2009-02-04 Thread David Nolen
(defn foobar [#^MyClass[] myarray])
This syntax doesn't seem to 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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Type hint Java array of your own Java class

2009-02-04 Thread Christophe Grand

David Nolen a écrit :
> (defn foobar [#^MyClass[] myarray])
>
> This syntax doesn't seem to work.
Indeed it's a bit tricky:
#^"[Lyour.package.YourClass;"

You can find it by doing:
user=> (class (into-array [(your.package.YourClass.)]))
[Lyour.package.YourClass;

Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
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 or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe

> On Feb 3, 11:16 pm, "Stephen C. Gilardi"  wrote:
>> On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>>
>>> user> (contains? (.keySet {:a :b}) :a)
>>> false
>>
>>> It seems that all that's required to make "contains?" work on  
>>> general
>>> Sets is to replace "IPersistentSet" with "Set" on lines 648 and  
>>> 649 of
>>> RT.java.  I can make a patch if desired.
>>
>> Along those lines, would it be a good idea for the object returned by
>> clojure.core/keys to implement java.util.Set and/or
>> clojure.lang.IPersistentSet?
>>
>
> Right now keys is just a filter on the seq of the map. I wouldn't be
> opposed to it being an IPersistentSet, but keys must be a constant-
> time operation, so the set would have to be a view on the map, not a
> copy of the keys.

OK, thanks!  I will take a shot at making patches for both of these.

-Jason


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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread prhlava


Hello Tim,

> Feel free to use it as you wish.

I have added the code (with attribution) to the guide.

Also, the .java generated code listing should now compile.

Updated guide is now on the same locations (including the files
section of this group).

>... So calling
> MainFrame.main() runs the static method, but you cannot do m = new
> MainFrame(); m.main();
> The generated "main" creates a new instance of MainFrame and makes it
> visible. There is no way for you to provide the object to "main" or
> get the object from "main" without modifying the java code.

Thank you for the explanation, now I get it...

Vlad

PS: Fixing the quote to be paste friendly is maybe possible somewhere
in LyX but so far I did not find out how...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Type hint Java array of your own Java class

2009-02-04 Thread David Nolen
Many thanks.

On Wed, Feb 4, 2009 at 12:49 PM, Christophe Grand wrote:

>
> David Nolen a écrit :
> > (defn foobar [#^MyClass[] myarray])
> >
> > This syntax doesn't seem to work.
> Indeed it's a bit tricky:
> #^"[Lyour.package.YourClass;"
>
> You can find it by doing:
> user=> (class (into-array [(your.package.YourClass.)]))
> [Lyour.package.YourClass;
>
> Christophe
>
> --
> Professional: http://cgrand.net/ (fr)
> On Clojure: http://clj-me.blogspot.com/ (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
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: Parsec style library

2009-02-04 Thread Meikel Brandmeyer

Hi,

Am 04.02.2009 um 05:24 schrieb Tom Faulhaber:


Meikel Brandmeyer has been doing some work on one. Check it out at:
http://kotka.de/projects/clojure/parser.html.

I haven't looked at it too closely myself. Maybe Meikel will stop in
and give you a feeling for how close/far it is from full Parsec.


Yes. I'm working on a Parsec port. It state is at the moment, well,
kind of a mess. I'm not sure it even compiles at the moment. I
want to "do it right" and work on my monad library at the moment.
This made some progress lately, but it isn't fully finished.

So I'm still working on it, but I wouldn't recommend that you
hold your breath... My pointy-haired boss on #clojure can sing
a song about such announcements. :]

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: rules for writing macros

2009-02-04 Thread Nathanael Cunningham
I just wanted to point out that ' is syntactic sugar for (quote) not (list).
(list) will evaluate your arguments, where as '() will not. So if you try to
use them interchangeable you'll run into trouble.

user> (list 1 2 (+ 1 2))
(1 2 3)
user> '(1 2 (+ 1 2))
(1 2 (+ 1 2))

Its a pretty common lisp gotcha.
-Nate

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



Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe

On Feb 4, 5:33 am, Rich Hickey  wrote:
> On Feb 3, 10:44 pm, Jason Wolfe  wrote:
>
> > This just bit me a second time, since one of my revised set functions
> > uses "contains?" and thus doesn't work on java.util.Sets (or even
> > the .keySets of Clojure maps).
>
> > user> (contains? (.keySet {:a :b}) :a)
> > false
>
> > It seems that all that's required to make "contains?" work on general
> > Sets is to replace "IPersistentSet" with "Set" on lines 648 and 649 of
> > RT.java.  I can make a patch if desired.
>
> Patch welcome - must handle both overloads of RT.get() - thanks!
>
> Rich

Hah, I'm not sure if you are serious or trying to get me to answer my
own question ... either way, thanks :)

I went to implement the RT.get() portion of this patch, and was very
surprised to find that there seems to be no way to get "the [actual,
identical?] object that is held in the set which compares equal to the
key, if found" from a java.util.Set in sublinear time.  You could
use .contains and return "an object .equal to the object in the set,
if found", but I suspect this is not what "get" is supposed to do.  In
this case, I guess there is good reason that "contains?" does not work
on java.util.Sets :).  Please correct me if I'm wrong on the contract
of "get"; otherwise, I'll drop this.

Thanks!
Jason


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



Re: My SLIME installation diary

2009-02-04 Thread Phil Hagelberg


Seeing all these complicated steps that need to be reproduced made me
wonder if it couldn't be automated. I've added an M-x clojure-install
command to my fork of clojure-mode, so if you are wanting to get started
with SLIME and Clojure, please give it a look.

Installation and configuration should be as simple as putting this
file into your Emacs config, pressing M-x clojure-install, and following
a few simple instructions:

http://github.com/technomancy/clojure-mode/blob/4506f07fd69262057fd07ece127466e27fb6b74d/clojure-mode.el

I blogged about the details here: http://technomancy.us/122

I've tested this on GNU/Linux systems (Emacs 23 and 22), and it's been
reported to work well on Mac OS X also. Please let me know how it works
for you or if you have any comments. This has definitely been a pain
point in the past, and it would be great if it could be streamlined.

-Phil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Questions about a Clojure Datalog

2009-02-04 Thread John Fries

AFAICT, Datalog only supports the closed-world assumption.  Does
anyone prefer an open-world assumption reasoner?  In my opinion, they
are significantly more powerful.

On Feb 4, 6:16 am, Timothy Pratley  wrote:
> > providing relations from clojure-sets and sql-queries.
>
> Wow - this is really neat Erik - thanks for showing

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



Re: Parsec style library

2009-02-04 Thread Dan Larkin


On Feb 3, 2009, at 9:42 PM, sbkogs wrote:

>
> Parsec is a very powerful parsing library for Haskell.  I was mainly
> attracted to Haskell because of this library (ala Pugs project which
> used Parsec to create a Perl6 parser).
>
> I am wondering if there is an ongoing effort to write similar library
> for Clojure.  I have seen a very nice implementation of Monads in
> Clojure.Contrib which can be used to build this library.  Having such
> powerful and easy way to build a parser could attract many more users
> to Clojure.  BTW, I have seen a parser combinator file by jim in the
> files section, which could be used as a stepping stone.
>
> If anybody is working on similar library, please drop me a line.  I
> have some bandwidth to spend towards such work/fun.
>

http://github.com/joshua-choi/fnparse/tree/master

It's very good!


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



Re: Parsec style library

2009-02-04 Thread James Reeves

On Feb 4, 2:42 am, sbkogs  wrote:
> If anybody is working on similar library, please drop me a line.  I
> have some bandwidth to spend towards such work/fun.

I created some simple LL parser tools for my Rend library:

http://github.com/weavejester/rend/blob/43f882a9474fb8662007e5a5d0c50648fc0caa75/src/rend/parser/tools.clj

I might turn them into a proper parser generator in the near future.

- 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
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: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread AlamedaMike

I'm having a problem that appears tied to this aspect of the guide
(written for Linux):

>> Before continuing, symlink build/classes/gui into the test-project directory 
>> (note, there is a “.” as the last character in the 2nd command):

cd ~/test-project
ln -s build/classes/gui/ .  // note the trailing period

I'm running Vista and when I enter the command "mklink /D . build
\classes\gui\"
I get the message "Cannot create a file when that file already
exists." It works fine when I substitute a name such as xyz for the
"."

I realize this isn't a Clojure issue as such, but I assume others will
run into the same problem here. Has anyone worked around 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
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: Parsec style library

2009-02-04 Thread jim

Take a look at:

http://clojure.googlegroups.com/web/monad-parser.clj

It's the code from "Monadic Parsing in Haskell" written in Clojure.
It'd have to be modified slightly to work with the new
clojure.contrib.monads.  But that would be easy to do.

jim

On Feb 3, 8:42 pm, sbkogs  wrote:
> Parsec is a very powerful parsing library for Haskell.  I was mainly
> attracted to Haskell because of this library (ala Pugs project which
> used Parsec to create a Perl6 parser).
>
> I am wondering if there is an ongoing effort to write similar library
> for Clojure.  I have seen a very nice implementation of Monads in
> Clojure.Contrib which can be used to build this library.  Having such
> powerful and easy way to build a parser could attract many more users
> to Clojure.  BTW, I have seen a parser combinator file by jim in the
> files section, which could be used as a stepping stone.
>
> If anybody is working on similar library, please drop me a line.  I
> have some bandwidth to spend towards such work/fun.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe

On Feb 4, 5:39 am, Rich Hickey  wrote:
> On Feb 3, 11:16 pm, "Stephen C. Gilardi"  wrote:
>
> > On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>
> > > user> (contains? (.keySet {:a :b}) :a)
> > > false
>
> > > It seems that all that's required to make "contains?" work on general
> > > Sets is to replace "IPersistentSet" with "Set" on lines 648 and 649 of
> > > RT.java.  I can make a patch if desired.
>
> > Along those lines, would it be a good idea for the object returned by
> > clojure.core/keys to implement java.util.Set and/or
> > clojure.lang.IPersistentSet?
>
> Right now keys is just a filter on the seq of the map. I wouldn't be
> opposed to it being an IPersistentSet, but keys must be a constant-
> time operation, so the set would have to be a view on the map, not a
> copy of the keys.

OK, I put up an issue & patch here:

http://code.google.com/p/clojure/issues/detail?id=66&colspec=ID%20Type%20Status%20Priority%20Reporter%20Owner%20Summary

Comments/questions/criticisms welcome.

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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread AlamedaMike

I'm having a problem that shows as:

java.lang.ClassNotFoundException: gui2.MainFrame
java.lang.ClassNotFoundException: gui2.MainFrame
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at clojure.lang.DynamicClassLoader.findClass
(DynamicClassLoader.java:52)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at clojure.import__776.doInvoke(boot.clj:1486)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at user.eval__2296.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:3891)
at clojure.lang.Repl.main(Repl.java:75)

I'm running Vista and when I enter the command "mklink /D . build
\classes\gui\" . (The order for link and target is reversed on
Windows.)
I get the message "Cannot create a file when that file already
exists."

It works fine when I substitute a name such as xyz for the
"."

I've tried everything I can think of, including copying the .class
files to the test-project directory. Nothing works.

I realize this isn't a Clojure issue as such, but I assume others
might
run into the same problem. Has anyone worked around this?



On Feb 4, 10:41 am, prhlava  wrote:
> Hello Tim,
>
> > Feel free to use it as you wish.
>
> I have added the code (with attribution) to the guide.
>
> Also, the .java generated code listing should now compile.
>
> Updated guide is now on the same locations (including the files
> section of this group).
>
> >... So calling
> > MainFrame.main() runs the static method, but you cannot do m = new
> > MainFrame(); m.main();
> > The generated "main" creates a new instance of MainFrame and makes it
> > visible. There is no way for you to provide the object to "main" or
> > get the object from "main" without modifying the java code.
>
> Thank you for the explanation, now I get it...
>
> Vlad
>
> PS: Fixing the quote to be paste friendly is maybe possible somewhere
> in LyX but so far I did not find out how...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: My SLIME installation diary

2009-02-04 Thread chris

(defun get-classpath-list ()
  (if
  (or
   (eq 'windows-nt system-type)
   (eq 'ms-dos system-type))
  (split-string (getenv "CLASSPATH") ";")
(split-string (getenv "CLASSPATH") ":")))

(setq swank-clojure-jar-path
  (dev-dir "clojure/clojure.jar"))
(setq swank-clojure-extra-classpaths
  (get-classpath-list))

Get the classpath from the system and set it as your swank classpath.

My slime setup currently fails completely on windows, however.  The
slime repl never starts; is there a way to get slime to dump all of
its communication (both ways, not just sending) to a file?

Chris

On Feb 4, 12:14 pm, Phil Hagelberg  wrote:
> Seeing all these complicated steps that need to be reproduced made me
> wonder if it couldn't be automated. I've added an M-x clojure-install
> command to my fork of clojure-mode, so if you are wanting to get started
> with SLIME and Clojure, please give it a look.
>
> Installation and configuration should be as simple as putting this
> file into your Emacs config, pressing M-x clojure-install, and following
> a few simple instructions:
>
> http://github.com/technomancy/clojure-mode/blob/4506f07fd69262057fd07...
>
> I blogged about the details here:http://technomancy.us/122
>
> I've tested this on GNU/Linux systems (Emacs 23 and 22), and it's been
> reported to work well on Mac OS X also. Please let me know how it works
> for you or if you have any comments. This has definitely been a pain
> point in the past, and it would be great if it could be streamlined.
>
> -Phil
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: My SLIME installation diary

2009-02-04 Thread chris

Also, I would love to get some more debugging support into slime.

I was wondering how difficult it would be to use the java debugging
API, embedded in the swank module, and send debug commands across?

Chris

On Feb 4, 2:36 pm, chris  wrote:
> (defun get-classpath-list ()
>   (if
>       (or
>        (eq 'windows-nt system-type)
>        (eq 'ms-dos system-type))
>       (split-string (getenv "CLASSPATH") ";")
>     (split-string (getenv "CLASSPATH") ":")))
>
> (setq swank-clojure-jar-path
>       (dev-dir "clojure/clojure.jar"))
> (setq swank-clojure-extra-classpaths
>       (get-classpath-list))
>
> Get the classpath from the system and set it as your swank classpath.
>
> My slime setup currently fails completely on windows, however.  The
> slime repl never starts; is there a way to get slime to dump all of
> its communication (both ways, not just sending) to a file?
>
> Chris
>
> On Feb 4, 12:14 pm, Phil Hagelberg  wrote:
>
> > Seeing all these complicated steps that need to be reproduced made me
> > wonder if it couldn't be automated. I've added an M-x clojure-install
> > command to my fork of clojure-mode, so if you are wanting to get started
> > with SLIME and Clojure, please give it a look.
>
> > Installation and configuration should be as simple as putting this
> > file into your Emacs config, pressing M-x clojure-install, and following
> > a few simple instructions:
>
> >http://github.com/technomancy/clojure-mode/blob/4506f07fd69262057fd07...
>
> > I blogged about the details here:http://technomancy.us/122
>
> > I've tested this on GNU/Linux systems (Emacs 23 and 22), and it's been
> > reported to work well on Mac OS X also. Please let me know how it works
> > for you or if you have any comments. This has definitely been a pain
> > point in the past, and it would be great if it could be streamlined.
>
> > -Phil
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread Michael Wood

Hi

On Wed, Feb 4, 2009 at 10:54 PM, AlamedaMike  wrote:
>
> I'm having a problem that appears tied to this aspect of the guide
> (written for Linux):
>
>>> Before continuing, symlink build/classes/gui into the test-project 
>>> directory (note, there is a "." as the last character in the 2nd command):
>
> cd ~/test-project
> ln -s build/classes/gui/ .  // note the trailing period
>
> I'm running Vista and when I enter the command "mklink /D . build
> \classes\gui\"
> I get the message "Cannot create a file when that file already
> exists." It works fine when I substitute a name such as xyz for the
> "."
>
> I realize this isn't a Clojure issue as such, but I assume others will
> run into the same problem here. Has anyone worked around this?

Well, on Unix, the following:

$ ln -s /path/to/source .

is a short cut for:

$ ln -s /path/to/source source

I have never used Windows' mklink command, but perhaps this is what you want:

mklink /D gui build\classes\gui

-- 
Michael Wood 

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



How to capture printing in a unit test

2009-02-04 Thread samppi

I want to test if a certain function prints a certain message to the
system's standard output. How may I go about doing this?

(defn printing-fn []
  (print "YES"))

(deftest test-printing-fn
  (some-context-that-switches-the-default-target-of-printing
(printing-fn)
(is (= the-standard-output "YES"


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



Re: Type hint Java array of your own Java class

2009-02-04 Thread Chouser

On Wed, Feb 4, 2009 at 12:49 PM, Christophe Grand  wrote:
>
> David Nolen a écrit :
>> (defn foobar [#^MyClass[] myarray])
>>
>> This syntax doesn't seem to work.
> Indeed it's a bit tricky:
> #^"[Lyour.package.YourClass;"
>
> You can find it by doing:
> user=> (class (into-array [(your.package.YourClass.)]))
> [Lyour.package.YourClass;

Christophe, thanks for pointing the way.  Sorry I kept going...

(defn array-of [cname]
  (-> cname resolve .newInstance list into-array class .getName))

With that, you can:

(defn foobar [#^#=(array-of MyClass) myarray])

At least it appears to work:

user=> (meta #^#=(array-of String) [])
{:tag "[Ljava.lang.String;"}

Again, I apologize for even suggesting this.

--Chouser

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



Re: How to capture printing in a unit test

2009-02-04 Thread Laurent PETIT
Hello,

this should work for you :

   (binding [*out* (java.io.StringWriter.)]
  (printing-fn)
  (= (.toString *out*) "YES"))

Regards,

-- 
Laurent

2009/2/4 samppi 

>
> I want to test if a certain function prints a certain message to the
> system's standard output. How may I go about doing this?
>
> (defn printing-fn []
>  (print "YES"))
>
> (deftest test-printing-fn
>  (some-context-that-switches-the-default-target-of-printing
>(printing-fn)
>(is (= the-standard-output "YES"
>
>
> >
>

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



Re: My SLIME installation diary

2009-02-04 Thread Phil Hagelberg

chris  writes:

> (defun get-classpath-list ()
>   (if
>   (or
>(eq 'windows-nt system-type)
>(eq 'ms-dos system-type))
>   (split-string (getenv "CLASSPATH") ";")
> (split-string (getenv "CLASSPATH") ":")))
>
> (setq swank-clojure-jar-path
>   (dev-dir "clojure/clojure.jar"))
> (setq swank-clojure-extra-classpaths
>   (get-classpath-list))
>
> Get the classpath from the system and set it as your swank classpath.

Thanks; this looks useful. But I've heard people say that using
environment variables for your classpath should be avoided. I'm not sure
what the reasoning behind this is though. Maybe it's just a case of "you
should be explicit instead of implicit"; I could see how it would be
annoying to track down problems that result from the value of an
invisible variable that lives outside your code base.

If the general consensus is that using environment variables is a good
idea, then I can merge this into clojure-mode.

For projects that depend on Java jars, my approach so far has been to
construct the classpath list from a directory listing and then include
the elisp code to do so in the source directory:

(setq concourse-dir (file-name-directory
 (or (buffer-file-name) load-file-name))
  swank-clojure-jar-path (concat concourse-dir "/jars/clojure.jar")
  swank-clojure-extra-classpaths (directory-files (concat concourse-dir 
"/jars/") 
  t ".jar$"))

-Phil

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



Re: How to capture printing in a unit test

2009-02-04 Thread Meikel Brandmeyer

Hi,

Am 04.02.2009 um 23:01 schrieb Laurent PETIT:


this should work for you :

   (binding [*out* (java.io.StringWriter.)]
  (printing-fn)
  (= (.toString *out*) "YES"))


There is also with-out-str:

(= "YES" (with-out-str (printing-fn)))

(And for the record: there is also a with-in-str.)

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Questions about a Clojure Datalog

2009-02-04 Thread Jeffrey Straszheim

Well, Datalog does give you guaranteed termination, so there is that,
although its bottom-up strategy is A LOT harder to implement (I'm now
trolling trough about a billion journal articles on "magic sets" and
so on to try to fix this).

I expect to provide full-on evaluable predicates, which I believe are
outside of the original Datalog scope, but I will still require the
"safe query" rules for those.

On Feb 4, 12:41 pm, John Fries  wrote:
> AFAICT, Datalog only supports the closed-world assumption.  Does
> anyone prefer an open-world assumption reasoner?  In my opinion, they
> are significantly more powerful.
>
> On Feb 4, 6:16 am, Timothy Pratley  wrote:
>
> > > providing relations from clojure-sets and sql-queries.
>
> > Wow - this is really neat Erik - thanks for showing
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Questions about a Clojure Datalog

2009-02-04 Thread John Fries
Guaranteed-termination is very desirable.  However, you can have guaranteed
termination with an open-world assumption just as well.  And I think an
open-world assumption does a better job of mimicking human reasoning.

On Wed, Feb 4, 2009 at 2:16 PM, Jeffrey Straszheim <
straszheimjeff...@gmail.com> wrote:

>
> Well, Datalog does give you guaranteed termination, so there is that,
> although its bottom-up strategy is A LOT harder to implement (I'm now
> trolling trough about a billion journal articles on "magic sets" and
> so on to try to fix this).
>
> I expect to provide full-on evaluable predicates, which I believe are
> outside of the original Datalog scope, but I will still require the
> "safe query" rules for those.
>
> On Feb 4, 12:41 pm, John Fries  wrote:
> > AFAICT, Datalog only supports the closed-world assumption.  Does
> > anyone prefer an open-world assumption reasoner?  In my opinion, they
> > are significantly more powerful.
> >
> > On Feb 4, 6:16 am, Timothy Pratley  wrote:
> >
> > > > providing relations from clojure-sets and sql-queries.
> >
> > > Wow - this is really neat Erik - thanks for showing
> >
>

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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread Timothy Pratley

> java.lang.ClassNotFoundException: gui2.MainFrame

To resolve gui2.MainFrame there needs to be MainFrame.class, in
directory gui2, in the current class-path.
Please check:
1) The directory name matches the namespace (If you can't get mklink
working, maybe just copy it instead?)
2) The current directory (parent of gui2) is in the class-path -cp
option when launching Clojure




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Type hint Java array of your own Java class

2009-02-04 Thread chris

Sorry for jumping in, but

"#^#=" doesn't make any sense to me.  Where did this come from?

Chris

On Feb 4, 2:55 pm, Chouser  wrote:
> On Wed, Feb 4, 2009 at 12:49 PM, Christophe Grand  
> wrote:
>
> > David Nolen a écrit :
> >> (defn foobar [#^MyClass[] myarray])
>
> >> This syntax doesn't seem to work.
> > Indeed it's a bit tricky:
> > #^"[Lyour.package.YourClass;"
>
> > You can find it by doing:
> > user=> (class (into-array [(your.package.YourClass.)]))
> > [Lyour.package.YourClass;
>
> Christophe, thanks for pointing the way.  Sorry I kept going...
>
> (defn array-of [cname]
>   (-> cname resolve .newInstance list into-array class .getName))
>
> With that, you can:
>
> (defn foobar [#^#=(array-of MyClass) myarray])
>
> At least it appears to work:
>
> user=> (meta #^#=(array-of String) [])
> {:tag "[Ljava.lang.String;"}
>
> Again, I apologize for even suggesting this.
>
> --Chouser
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.sql and inner joins

2009-02-04 Thread Stephen C. Gilardi


On Feb 4, 2009, at 11:09 AM, BrianS wrote:

Once I substituted actual column names in the SELECT portion of the  
statement, the inner joins started working as they should.


Excellent!

As always, thanks for the attention, assistance, and the original  
work in clojure.contrib.sql, it has all been VERY helpful to me.


Thanks very much for the kind words. I'm happy to help. I'm glad  
you're finding it useful!


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Type hint Java array of your own Java class

2009-02-04 Thread Chouser

On Wed, Feb 4, 2009 at 6:22 PM, chris  wrote:
>
> "#^#=" doesn't make any sense to me.  Where did this come from?

I already apologized twice, what more do you want from me!?

As penance, I will try to explain.

#^ is a reader macro, documented at http://clojure.org/reader

#= is another reader macro, largely undocumented, but discussed here:
http://groups.google.com/group/clojure/browse_thread/thread/7a24eeb982490a87/d579d881fea5b16d?#d579d881fea5b16d

>> user=> (meta #^#=(array-of String) [])
>> {:tag "[Ljava.lang.String;"}

The whole point of this example was to attach type-hint metadata to a
function arg, so the use of #^ was necessary.  But usually #^ just
takes a literal symbol or map, and I wanted to use the results of a
function call, so I abused #= to do just that.

--Chouser

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



Custom exception classes

2009-02-04 Thread Jeffrey Straszheim

Is there an easy way to create custom exception classes.  Like in Java
where you do:

public class MyOwnException {}

I suppose there is a way to do it with gen-class, but gen-class looks
complicated.


Can someone post a simple example?

(btw, this would make a great macro in clojure.contrib.  I'd write it
if someone tells me how to contribute a diff.)


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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread AlamedaMike

Michael, Timothy,

Thanks much to both of you.

>> 2) The current directory (parent of gui2) is in the class-path -cp
option when launching Clojure

The problem was that I had used the gui directory in the classpath,
rather than its parent. (The real problem is that I'm a Java noobie.)

The frame opens now and I can cancel it  correctly. However, when I
click OK (using either the original app.clj or Timothy's version) I
get:

C:\Users\Mike\Documents\test-project>c:\clojure\clj.bat app.clj
Exception in thread "AWT-EventQueue-0" java.io.IOException: Stream
closed
at sun.nio.cs.StreamEncoder.ensureOpen(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.Writer.write(Unknown Source)
at clojure.lang.RT.print(RT.java:1186)
at clojure.pr__788.invoke(boot.clj:1516)
at clojure.lang.AFn.applyToHelper(AFn.java:184)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at clojure.prn__799.doInvoke(boot.clj:1540)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at clojure.println__805.doInvoke(boot.clj:1556)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.eval__2299$fn__2301.invoke(app.clj:12)
at clojure.lang.Proxy__2305.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown
Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown
Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown
Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

The problem is in the println function, as it works fine when I
comment them out. I assume this is some sort of problem sending text
to the DOS/Vista command shell that doesn't happen under *nix. Also,
no text appears in the command shell when I enter some into the boxes
and click OK.

This isn't critical to running the app, of course, though having print
capability back to the command shell makes an excellent debugging
tool. It seems clear it will be an issue for anyone on Windows, and
for a broad range of apps. As this is well beyond my modest Java
powers, any ideas would be appreciated.

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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread AlamedaMike

>> The quote symbol rendered is not copy+paste friendly.

The quote problem can be fixed by using:

(import (quote (gui2 MainFrame)))etc...

instead of using the single quote 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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Map from generator?

2009-02-04 Thread Conrad

It is useful to build a map from a list of keys and a value generator
function. Of Course, such a function is easy to write:

(defn genmap [keys fun]
  (zipmap keys (map fun keys)))

In fact, it seems so useful that it must be in the standard API
somewhere, but I can't find it... did I miss it somewhere, or was I
right to create my own? Please let me know if I'm reinventing the
wheel.

Thanks!

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



how to reason about two dimentional array(vector) like...

2009-02-04 Thread wubbie

Hi,

Have some difficulties in reasoning about it.
>From ants.clj,
(def board
  (apply vector
 (map (fn [_]
(apply vector
   (map (fn [_] (ref (struct cell white)))
(range dim
  (range dim

Is there any simpler two dimentional array construct which would be
easiler to grasp?

thanks,
-sun


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



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread Timothy Pratley


> C:\Users\Mike\Documents\test-project>c:\clojure\clj.bat app.clj
> Exception in thread "AWT-EventQueue-0" java.io.IOException: Stream
> closed

The reason you are seeing this is that stdout has closed when the main
clj program reaches the end, but the Swing thread is still running. I
remember having this problem with an older build of Clojure but it
doesn't happen for me anymore, so either something changed or the .bat
file launching the script affects this behavior (I'm running on XP).

If you put (read) at the end of your .clj file it will keep stdout
open (until you enter some text at the consol).

Here is a version which avoids the issue altogether by using a Dialog
instead of stdout:
http://groups.google.com/group/clojure/web/app.clj


Regards,
Tim.


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



Re: How to capture printing in a unit test

2009-02-04 Thread samppi

Awesome. Thanks for the answers, everyone.

On Feb 4, 3:07 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 04.02.2009 um 23:01 schrieb Laurent PETIT:
>
> > this should work for you :
>
> >    (binding [*out* (java.io.StringWriter.)]
> >       (printing-fn)
> >       (= (.toString *out*) "YES"))
>
> There is also with-out-str:
>
> (= "YES" (with-out-str (printing-fn)))
>
> (And for the record: there is also a with-in-str.)
>
> Sincerely
> Meikel
>
>  smime.p7s
> 5KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Custom exception classes

2009-02-04 Thread Tom Faulhaber

You have to build a class with gen-class.

Here's an example:
---
(ns com.infolace.format.InternalFormatException
  (:gen-class
   :extends Exception
   :init init
   :constructors { [ String Integer ] [ String ] }
   :state pos))

(defn- -init [msg level]
  [[msg] level])
---

The deal on gen-class is that you actually need to compile the class
files before they are useful. I use an ant task to do this. You can
see it here: 
http://github.com/tomfaulhaber/cl-format/blob/0d436ab7026b74865df99bb26bafbbeed0726b4d/build.xml

It's probably a better idea to have your class inherit from
RuntimeException to avoid having it be rewrapped (though I think it
sometimes gets rewrapped anyway). This happens because Clojure doesn't
support checked exceptions (Rich has a very compelling explanation for
this).

In the end, I abandoned using custom exceptions. I was only using them
to carry custom information. Instead, I bind an error function that
takes the extra information as an argument and just I generate an
exception using that function if I have an error. (Thanks to Chouser
for brainstorming up that idea with me.)

I would love to see a better thought out way to be able to selectively
throw and catch since this is (to me) the big advantage of custom
exceptions. Might be done with a variation of proxy.

Hope that helps,

Tom




On Feb 4, 6:55 pm, Jeffrey Straszheim 
wrote:
> Is there an easy way to create custom exception classes.  Like in Java
> where you do:
>
> public class MyOwnException {}
>
> I suppose there is a way to do it with gen-class, but gen-class looks
> complicated.
>
> Can someone post a simple example?
>
> (btw, this would make a great macro in clojure.contrib.  I'd write it
> if someone tells me how to contribute a diff.)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: how to reason about two dimentional array(vector) like...

2009-02-04 Thread wubbie

are they really equivalent?
Looks like they are but...

Also I was trying to decompose...
user=> (def x (apply vector (map (fn [_] 1) (range 3
#'user/x
user=> x
[1 1 1]
user=> (apply vector (map (fn [_] x) (range 3)))
[[1 1 1] [1 1 1] [1 1 1]]

and now it makes a lot more sense...



On Feb 5, 12:19 am, wwmorgan  wrote:
> Here's what I came up with: is it any clearer?
>
> (def board
>   (vec (for [i (range dim)]
>             (vec (for [j (range dim)]
>                       (ref (struct cell white)))
>
> On Feb 4, 11:30 pm, wubbie  wrote:
>
> > Hi,
>
> > Have some difficulties in reasoning about it.
> > From ants.clj,
> > (def board
> >   (apply vector
> >          (map (fn [_]
> >                 (apply vector
> >                        (map (fn [_] (ref (struct cell white)))
> >                             (range dim
> >               (range dim
>
> > Is there any simpler two dimentional array construct which would be
> > easiler to grasp?
>
> > thanks,
> > -sun
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-02-04 Thread Keith Bennett

Samppi -


On Jan 28, 12:53 pm, samppi  wrote:
> Thanks for the replies, everyone. I read in an article that one of the
> most common Swing mistakes is putting non-GUI work into the event
> dispatch thread, but it seems like oftentimes the cost of creating a
> new thread outweighs the benefit of separation, if the work is simple.
> With the code above, I was trying to figure out how to do a Swing app
> while performing potentially long procedure, such as contacting a
> different connected computer.

In that case, yes, you should do the time consuming work on a
different thread.

>
> But for Keith's comments—when would it good to block the Swing thread?
> Even if I wanted to disable the control that started the action,
> shouldn't I just use (.setEnabled button false)? I'd think that the
> GUI should always be able to respond to the user, or else it would
> seem frozen.
>

I'm not sure what you mean by this.  If you are doing the work on the
Swing (AWT) thread, there is no need to disable any components because
the GUI will not accept any input until your work is done.  If you do
the work on a different thread, then, yes, you would need to call
setEnabled to disable the button.  And there may be other things you
need to disable (a program exit command, for example).

> I guess it'd be bad with multiple modal dialogs. I think maybe I
> should just try to avoid those. :)

There is a meme that has been going around for years that "modal
dialogs are evil".  This use case would certainly support that
view. ;)

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



Re: Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-02-04 Thread Keith Bennett

Samppi -


On Jan 28, 12:53 pm, samppi  wrote:
> Thanks for the replies, everyone. I read in an article that one of the
> most common Swing mistakes is putting non-GUI work into the event
> dispatch thread, but it seems like oftentimes the cost of creating a
> new thread outweighs the benefit of separation, if the work is simple.
> With the code above, I was trying to figure out how to do a Swing app
> while performing potentially long procedure, such as contacting a
> different connected computer.

In that case, yes, you should do the time consuming work on a
different thread.

>
> But for Keith's comments—when would it good to block the Swing thread?
> Even if I wanted to disable the control that started the action,
> shouldn't I just use (.setEnabled button false)? I'd think that the
> GUI should always be able to respond to the user, or else it would
> seem frozen.
>

I'm not sure what you mean by this.  If you are doing the work on the
Swing (AWT) thread, there is no need to disable any components because
the GUI will not accept any input until your work is done.  If you do
the work on a different thread, then, yes, you would need to call
setEnabled to disable the button.  And there may be other things you
need to disable (a program exit command, for example).

> I guess it'd be bad with multiple modal dialogs. I think maybe I
> should just try to avoid those. :)

There is a meme that has been going around for years that "modal
dialogs are evil".  This use case would certainly support that
view. ;)

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



Re: how to reason about two dimentional array(vector) like...

2009-02-04 Thread wwmorgan

Here's what I came up with: is it any clearer?

(def board
  (vec (for [i (range dim)]
(vec (for [j (range dim)]
  (ref (struct cell white)))

On Feb 4, 11:30 pm, wubbie  wrote:
> Hi,
>
> Have some difficulties in reasoning about it.
> From ants.clj,
> (def board
>   (apply vector
>          (map (fn [_]
>                 (apply vector
>                        (map (fn [_] (ref (struct cell white)))
>                             (range dim
>               (range dim
>
> Is there any simpler two dimentional array construct which would be
> easiler to grasp?
>
> thanks,
> -sun
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Trying to make a recursive parser, puzzling over certain behavior

2009-02-04 Thread samppi

Let's say I want to make a small parser for a small language. The
language is made up of values of two kinds: arrays and bits. An array
can only be of the form "[x,y]", where x and y are values. A bit can
only be of the form "0" or "1". In other words, the language's strings
can look like this:
- 0
- 1
- [0,0]
- [1,0]
- [1,1]
- [[0,0],1]

Now, to create a parser I can create three metafunctions that can
create rules. Rules are functions that take a collection of tokens (in
this case, characters), and pass around an array made up of the
current parsed structure and the remaining tokens. If a rule receives
tokens that are invalid for the rule, it returns nil instead, which
would propagate back up the stack of function calls.

Clojure
user=> (defn conc [& subrules]
(fn [tokens]
(loop [subrule-queue (seq subrules), remaining-tokens (seq 
tokens),
products []]
(if (nil? subrule-queue)
[products remaining-tokens]
(let [[subrule-products subrule-remainder :as 
subrule-result]
((first subrule-queue) remaining-tokens)]
(when-not (nil? subrule-result)
(recur (rest subrule-queue) 
subrule-remainder (conj products
subrule-products
#'user/conc
user=> (defn alt [& subrules]
(fn [tokens]
(some #(% tokens) subrules)))
#'user/alt
user=> (defn literal [literal-token]
(fn [tokens]
(let [first-token (first tokens), remainder (rest tokens)]
(when (= first-token literal-token)
[first-token remainder]
#'user/literal
user=> (def on (literal \1))
#'user/on
user=> (def off (literal \0))
#'user/off
user=> (def bit (alt on off))
#'user/bit
user=> (bit (seq "1, 0"))
[\1 (\, \space \0)]
user=> (bit (seq "starst"))
nil
user=> (def array-start (literal \[))
#'user/array-start
user=> (array-start (seq "[1, 2, 3]"))
[\[ (\1 \, \space \2 \, \space \3 \])]
user=> (def array-end (literal \]))
#'user/array-end
user=> (def array-sep (literal \,))
#'user/array-sep

Now, value and array are recursive into each other. Because Clojure
substitutes variables immediately outside of functions—and barring
macros, I have to put either the value rule or the array rule into a
wrapper function. This does not behave as I expect, though:

user=> (declare value)
#'user/value
user=> (defn array []
  ; I'm defining it as a function because otherwise I'd get an unbound
variable exception.
(conc array-start value array-sep value array-end))
#'user/array
user=> (def value (conc (array) bit))
#'user/value
user=> (def value (alt (array) bit))
#'user/value
user=> (value (seq "0"))
[\0 nil]
user=> (value (seq "[1,0]"))
nil
user=> (value (seq "[0,0]")) ; It should accept it, because (array)
accepts it. But it doesn't:
nil
user=> ((array) (seq "[0,0]")) ; This works as intended:
[[\[ \0 \, \0 \]] nil]
user=> (value (seq "[0,3]")) ; This should return nil, but a weird
argument exception is raised instead:
java.lang.IllegalArgumentException: Key must be integer
(NO_SOURCE_FILE:0)
user=> ((array) (seq "[0,3]")) ; This is what I want:
nil

Can anybody shed light on why (value (seq "[0,0]")) and (value (seq
"[0,3]")) do not work as intended? This is a big problem with my
parser library, since dealing with two or more rules that refer to
each other is a huge pain. I'm considering switching my parser library
to macros if that could fix it more easily somehow.


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



Re: Type hint Java array of your own Java class

2009-02-04 Thread Christophe Grand

Chouser a écrit :
> (defn foobar [#^#=(array-of MyClass) myarray])
>
> Again, I apologize for even suggesting this
Wow what a clever (ab)use of reader macros!

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: how to reason about two dimentional array(vector) like...

2009-02-04 Thread Emeka
Where did 'ref' go in your own implementation?

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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: how to reason about two dimentional array(vector) like...

2009-02-04 Thread canadaduane

Wow, thanks wwmorgan!  I too was struggling to have some semblance of
intuition on the first form, but this one is much easier.

Duane

On Feb 4, 10:19 pm, wwmorgan  wrote:
> Here's what I came up with: is it any clearer?
>
> (def board
>   (vec (for [i (range dim)]
>             (vec (for [j (range dim)]
>                       (ref (struct cell white)))
>
> On Feb 4, 11:30 pm, wubbie  wrote:
>
> > Hi,
>
> > Have some difficulties in reasoning about it.
> > From ants.clj,
> > (def board
> >   (apply vector
> >          (map (fn [_]
> >                 (apply vector
> >                        (map (fn [_] (ref (struct cell white)))
> >                             (range dim
> >               (range dim
>
> > Is there any simpler two dimentional array construct which would be
> > easiler to grasp?
>
> > thanks,
> > -sun
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



How to write a unicode character in clojure?

2009-02-04 Thread Terrence Brannon

How do you write a unicode character in clojure?

Or properly put: what form do you provide the reader so that it
produces a unicode character as data structure?

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



Re: How to write a unicode character in clojure?

2009-02-04 Thread Terrence Brannon

I got some help from hiredman in the IRC channel -
http://github.com/metaperl/begin-clojure/blob/619eb489fb68839d2376d2cdf7375f2370d38494/1/unicode-chars.txt


On Feb 5, 2:24 am, Terrence Brannon  wrote:
> How do you write a unicode character in clojure?
>
> Or properly put: what form do you provide the reader so that it
> produces a unicode character as data structure?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---