Re: Datatypes and Protocols update

2010-04-23 Thread Konrad Hinsen

On 22 Apr 2010, at 21:15, Konrad Hinsen wrote:

I have several former deftypes that are a perfect fit for the new  
defrecord, except that they need a specific comparison function.  
This is usually for excluding some fields from equality testing, or  
for requiring identity rather than equality for some fields.


What I'd actually like to have for defrecord is an "equality" protocol  
that I can implement myself or use a default implementation. That  
protocol would have a function "equals" guaranteed to be called only  
if the object compared to is of the same type. Object.equals would  
take care of type testing and then call the protocol function. That  
would remove the check-type-before-comparing-fields overhead that  
every equals implementation for deftype and defrecord currently  
requires.


Konrad.

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


Newbie: Finding performance bottlenecks

2010-04-23 Thread msappler
Hi this is my first clojure application: http://pastebin.com/Vv7xr6Uj
(Code Criticism welcome!)

I am porting my hack'and'slay game from java to clojure.

It is using slick2d and rendering and moving bodies (rectangles) on a
2d collision map.

-
I created a computationally intensive situation with 200 moving
projectiles and wanted to try find the bottleneck function.

I used JRat when developing with java but the results do not help me
much @ clojure:

Method Time %
#1 var deref() 12,1%
#2 var get() 6,2%
#3-#7 some,filter,distinct...

Is this because I use vars for storing for example the cell-map of the
game?
Are atoms allowing faster access and should I use atoms even for
immutable globals like the 2d-cell-map?
Or is this standart clojure bottleneck for dereferencing functions?
How can I profile so that I find the functions of my 'test namespace?

Then I used JavaVisualVM .. and specified

test.** as my class settings to try to get only the functions of my
namespace.

But there came a lot of errors:

Profiler Agent Warning: Failed to lookup cached class ...my test ns
functions...
Profiler Agent Warning: Failed to lookup cached class 
Profiler Agent Warning: Failed to lookup cached class 

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


Re: CLR - Error following a tutorial and setting up project depending on ClojureCLR

2010-04-23 Thread Joerthan Panest
Simple fix, the new project was targeting .NET 4.0 Client. Switching to 3.5
solved the issues.

On Thu, Apr 22, 2010 at 10:37 PM, Joerthan Panest  wrote:

> Hello, I have successfully built ClojureCLR and run the main REPL
> successfully.
>
> Now, I would like to set up a project that uses ClojureCLR. So, I
> followed the short tutorial at:
> http://www.genericerror.com/blog/2010/01/22/SimpleClojureCLRExample.aspx
>
> At the first call of RT.LoadScript(...) I am getting an exception of:
>
> ---
>
> ---
> System.TypeInitializationException was unhandled
>  Message=The type initializer for 'clojure.lang.RT' threw an
> exception.
>  Source=Clojure
>  TypeName=clojure.lang.RT
>  StackTrace:
>   at clojure.lang.RT.LoadScript(FileInfo cljInfo)
>   at ClojureInteropTest.Program.Main(String[] args) in
> ClojureInteropTest\ClojureInteropTest\Program.cs:line 39
>   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
> String[] args)
>   at System.AppDomain.ExecuteAssembly(String assemblyFile,
> Evidence assemblySecurity, String[] args)
>   at
> Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
>   at System.Threading.ThreadHelper.ThreadStart_Context(Object
> state)
>   at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> ignoreSyncCtx)
>   at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)
>   at System.Threading.ThreadHelper.ThreadStart()
>  InnerException: System.TypeInitializationException
>   Message=The type initializer for 'clojure.lang.Compiler' threw
> an exception.
>   Source=Clojure
>   TypeName=clojure.lang.Compiler
>   StackTrace:
>at clojure.lang.Compiler.LoadAssembly(FileInfo assyInfo)
>at clojure.lang.RT.load(String pathname, Boolean
> failIfNotFound) in clojure-clr\Clojure\Clojure\Lib\RT.cs:line 1918
>at clojure.lang.RT.load(String pathname) in clojure-clr
> \Clojure\Clojure\Lib\RT.cs:line 1898
>at clojure.lang.RT.DoInit() in clojure-clr\Clojure\Clojure
> \Lib\RT.cs:line 543
>at clojure.lang.RT..cctor() in clojure-clr\Clojure\Clojure
> \Lib\RT.cs:line 538
>   InnerException: System.Reflection.AmbiguousMatchException
>Message=Ambiguous match found.
>Source=mscorlib
>StackTrace:
> at System.RuntimeType.GetMethodImpl(String name,
> BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
> Type[] types, ParameterModifier[] modifiers)
> at System.Type.GetMethod(String name)
> at clojure.lang.Compiler..cctor() in clojure-clr
> \Clojure\Clojure\CljCompiler\Compiler.cs:line 190
>InnerException:
>
>
> ---
>
> ---
>
> If I reduce Main() to exclusively be:
> RT.random();
>
> I get a pop up that the application has encountered an exception and
> needs to close, with the signature:
>
>
> ---
>
> ---
> EventType : clr20r3 P1 : clojureinteroptest.exe P2 :
> 1.0.0.0
> P3 : 4bd10730 P4 : mscorlib P5 : 4.0.0.0 P6 : 4ba1da6f
> P7 : fed
> P8 : 4f P9 : system.reflection.ambiguousmatch
>
> ---
>
> ---
>
> Is this tutorial up to date? I have the Clojure, Microsoft.{Dynamic,
> Scripting, Scripting.Core, Scripting.ExtensionAttribute} projects in
> the solution, and each is referenced by the test project.
>
> Thanks,
> Joerthan

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

Re: Reading from file

2010-04-23 Thread Alan Dipert
On Thu, 2010-04-22 at 22:29 +0700, Per Vognsen wrote:
> How about this?
> 
> (use 'clojure.contrib.str-utils 'clojure.contrib.duck-streams)
> 
> (defn parse [file]
>   (let [r (reader file)]
> (map (fn [line] (map #(Integer/parseInt %) (.split line " ")))
> (take (Integer/parseInt (.readLine r)) (repeatedly
> #(.readLine r))

There's also read-lines in c.c.duck-streams, which cleans things up a
bit in my opinion:

(defn parse [file]
  (map (fn [line]
 (map #(Integer. %) (.split line " ")))
   (read-lines file)))

Cheers,
Alan

> 
> (defn unparse [xss file]
>   (let [w (writer file)]
> (.writeLine w (str (count xss))
> (doseq [xs xss]
>   (.writeLine w (str-join " " (map str xs)))
> 
> -Per
> 
> On Thu, Apr 22, 2010 at 1:40 AM, I.K.  wrote:
> > Hi!
> > I'm learning Clojure and trying some Google Code Jam exercises.
> > I am more or less satisfied with the style of algorithms I write, but
> > I would like to know how to do input/output. I want it to be Clojure
> > style (terse/functional/efficient) not just rewriting the usual
> > loops...
> > Take a look at simplest example from io standpoint:
> > http://code.google.com/codejam/contest/dashboard?c=188266#.
> > I want the file:
> >
> > 3
> > 2 3
> > 2 3 7
> > 9 10
> >
> > turn into vector: [ [2 3] [2 3 7] [9 10] ],
> >
> > and in reverse direction (produce file given above from this vector).
> >
> > Show your style.
> >
> > Thanks,
> > I.K.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> 


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


CLR - Error following a tutorial and setting up project depending on ClojureCLR

2010-04-23 Thread Joerthan Panest
Hello, I have successfully built ClojureCLR and run the main REPL
successfully.

Now, I would like to set up a project that uses ClojureCLR. So, I
followed the short tutorial at:
http://www.genericerror.com/blog/2010/01/22/SimpleClojureCLRExample.aspx

At the first call of RT.LoadScript(...) I am getting an exception of:
---
---
System.TypeInitializationException was unhandled
  Message=The type initializer for 'clojure.lang.RT' threw an
exception.
  Source=Clojure
  TypeName=clojure.lang.RT
  StackTrace:
   at clojure.lang.RT.LoadScript(FileInfo cljInfo)
   at ClojureInteropTest.Program.Main(String[] args) in
ClojureInteropTest\ClojureInteropTest\Program.cs:line 39
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
   at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeInitializationException
   Message=The type initializer for 'clojure.lang.Compiler' threw
an exception.
   Source=Clojure
   TypeName=clojure.lang.Compiler
   StackTrace:
at clojure.lang.Compiler.LoadAssembly(FileInfo assyInfo)
at clojure.lang.RT.load(String pathname, Boolean
failIfNotFound) in clojure-clr\Clojure\Clojure\Lib\RT.cs:line 1918
at clojure.lang.RT.load(String pathname) in clojure-clr
\Clojure\Clojure\Lib\RT.cs:line 1898
at clojure.lang.RT.DoInit() in clojure-clr\Clojure\Clojure
\Lib\RT.cs:line 543
at clojure.lang.RT..cctor() in clojure-clr\Clojure\Clojure
\Lib\RT.cs:line 538
   InnerException: System.Reflection.AmbiguousMatchException
Message=Ambiguous match found.
Source=mscorlib
StackTrace:
 at System.RuntimeType.GetMethodImpl(String name,
BindingFlags bindingAttr, Binder binder, CallingConventions callConv,
Type[] types, ParameterModifier[] modifiers)
 at System.Type.GetMethod(String name)
 at clojure.lang.Compiler..cctor() in clojure-clr
\Clojure\Clojure\CljCompiler\Compiler.cs:line 190
InnerException:

---
---

If I reduce Main() to exclusively be:
RT.random();

I get a pop up that the application has encountered an exception and
needs to close, with the signature:

---
---
EventType : clr20r3 P1 : clojureinteroptest.exe P2 :
1.0.0.0
P3 : 4bd10730 P4 : mscorlib P5 : 4.0.0.0 P6 : 4ba1da6f
P7 : fed
P8 : 4f P9 : system.reflection.ambiguousmatch
---
---

Is this tutorial up to date? I have the Clojure, Microsoft.{Dynamic,
Scripting, Scripting.Core, Scripting.ExtensionAttribute} projects in
the solution, and each is referenced by the test project.

Thanks,
Joerthan

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


ClojureCLR start-up time

2010-04-23 Thread Joerthan Panest
Hello,

I am considering ClojureCLR for embedding in an application, but it appears
as though it takes ~4secs to start up. Is this typical? Is there a way to
speed up? I realize that this could be hidden by opening it in a background
process and leaving it open but I can see where that is less than ideal in
some situations.

I also noticed that the current development environment has many references
to Debug bin settings and a short attempt to get it in Release mode failed
with a number of errors. Is this due to the nature of the required run-time
information or simply because it is still a Beta?

Thank you,
Joerthan

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

problem installing clojure/Enclojure with Netbeans

2010-04-23 Thread numa
I am completely new to Clojure. I decided to use Netbeans with
Enclojure, but can't get it to work.  I'm using Netbeans 6.8 on a Mac
(Leopard).  The Netbeans Plugin window Installed tab says that it is
active (under User Installed Plugins it says Source: enclojure-
plugin-2010-23-mar.nbm, Enclojure   Version: 1.0).  If I check Show
details, I see that it is listed as Clojure Plugin, and there is also
an entry for Enclojure Clojure Plugin, which reports Source:
Enclojure  Version: 1.1.1.
Java SE is, of course, active.

I added labrepl as a new project, but "some dependency artifacts are
not  in the local repository." "The project loading failed or was not
complete."  I tried to create a new Clojure application, but get the
error "The target filesystem or folder does not exist."

I had followed the instructions at assembla wiki.  Are the files for
running clojure not installed by the Enclojure plugin?  Originally I
had downloaded clojure-1.1.0 but was just running it from my home
directory.  Should I put this somewhere for Netbeans?

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


Re: Try + finally question

2010-04-23 Thread ka
Hi all,

I've written my first macro: with-open-flexi!

(defmacro with-open-flexi!
  " Just like with-open except it takes closing expression instead
of assuming it to be .close

Macro definition :
(with-open-flexi! [] body) expands to -
  (do body)

(with-open-flexi! [obj1 init1 close1 more] body)) expands to
  (let [obj1 init1]
(try
  (with-open-flexi! [more] body)
  (finally close1)))

Note: It is your responsibility to ensure -
  1. Count of elements in the bindings is a multiple of 3
  2. 0th, 3rd, 6th, 9th ... index of binding is a symbol

example usage -
(with-open-flexi! [conn1 (API1/Conn args) (API1/Disconn conn1
args)
 conn2 (API2. args) (API2/Disconn
args conn2)
 conn3 (API3. args) (.disconn
conn3)]
  (... use conn1, conn2, conn3 ...)
  42)
  "
  [bindings & body]
  (if (= 0 (count bindings))
`(do ~...@body)
(let [[o i c & more] bindings]
  `(let [~o ~i]
 (try
   (with-open-flexi! [...@more] ~...@body)
   (finally ~c))


Tested it :

=> (with-open-flexi! [o1 (println "i1") (println o1 "c1")
   o2 (println "i2") (println o2 "c2")]
  (println "body1") (println "body2") 42)
i1
i2
body1
body2
nil c2
nil c1
42

Please let me know if there are any bugs / gotchas / improvements etc.

- Thanks

On Apr 21, 8:04 pm, "Mark J. Reed"  wrote:
> The main thing about Perl6 in this case is that the catch/finally blocks are
> inside the same scope as the try.   But that's true in Clojure as well!
> The difference is that Clojure's try is not itself a lexical binding scope;
> you have to wrap one around it or within it via let.  That's why I thought a
> combination of try and let would be useful, if only as syntactic sugar.
>
>
>
> On Wed, Apr 21, 2010 at 10:43 AM, ka  wrote:
> > Thanks all for replies.
>
> > Laurent, Alex you guys are right, the problem is only with aesthetics
> > of nesting / boilerplate.  The nesting implementation semantically
> > expresses exactly what is required.
>
> > The with-cleanup macro seems really neat.  Guess I'll learn macros
> > first and try to implement one.
>
> > One more interesting perspective to exceptional handling is the way
> > Perl 6 is doing it -
> >http://feather.perl6.nl/syn/S04.html#Exception_handlers
>
> > See this -
>
> > {
> >    my $s = '';
> >    die 3;
> >    CATCH {
> >        when 1 {$s ~= 'a';}
> >        when 2 {$s ~= 'b';}
> >        when 3 {$s ~= 'c';}
> >        when 4 {$s ~= 'd';}
> >        default {$s ~= 'z';}
> >    }
>
> >    is $s, 'c', 'Caught number';
> > };
>
> > Thanks!
>
> > On Apr 21, 7:05 pm, Alex Osborne  wrote:
> > > ka  writes:
> > > > The whole code gets cluttered with all these try finally (and one
> > > > catch) statements.
>
> > > >   (try
> > > >     (let [conn1 (API1/getConnection ..)]
> > > >       (try
> > > >         (let [conn2 (API2/getConnection ..)]
> > > >           (try
> > > >             ( ... Do something with conn1 conn2 )
> > > >             (finally
> > > >               (API2/closeConnection conn2
> > > >         (finally
> > > >           (API1/closeConnection conn1
> > > >     (catch Exception ex (.printStackTrace ex)))
>
> > > I guess the main difference in this compared to your java example is the
> > > levels of nesting.  This may look messy but it's semantically exactly
> > > what you're trying to express.
>
> > > > The macro solution looks good.  But with 2 different APIs for 2
> > > > connections, I would need to write 2 macros right?
>
> > > > (defmacro with-api1-connection [conn-sym arg1 arg2 & body]
> > > >   `(let [~conn-sym (API1/getConnection ~arg1 ~arg2)]
> > > >      (try
> > > >       ~...@body
> > > >       (finally (API1/closeConnection ~conn-sym)
>
> > > > (defmacro with-api2-connection [conn-sym arg1 arg2 arg3 & body]
> > > >   `(let [~conn-sym (API2/getConnection ~arg1 ~arg2 ~arg3)]
> > > >      (try
> > > >       ~...@body
> > > >       (finally (API2/closeConnection ~conn-sym)
>
> > > You could make things more general:
>
> > > (with-cleanup [conn1 (API1/getConnection ...) API1/closeConnection
> > >                conn2 (API2/openConnection ...) #(.disconnect %)]
> > >  ...)
>
> > > I'll leave implementation as an exercise, it's not much more complicated
> > > than the previous ones, the main trick would just be to make the macro
> > > recursive, have it expand into:
>
> > > (let [conn1 (API1/getConnection ...)]
> > >   (try
> > >     (with-cleanup [conn2 (API2/openConnection ...) #(.disconnect %)]
> > >       ...)
> > >     (finally
> > >       (API1/closeConnection conn1
>
> > > I'd probably start with a signature like this:
>
> > > (defmacro with-cleanup [[sym create cleanup & more] & body]
> > >   ...)
>
> > > Take a look at the source for with-open if you get stuck.
>
> > > > Coming from Java, this would be implemented as -
>
> > > > Connection1 con

Cannot find juxt in clojure 1.1 (??)

2010-04-23 Thread Base
Hi ALl

I am using CounterClockwise for Eclipse and for some reason I keep
getting the error:

Unable to resolve var: juxt in this context (repl-1:34)

This happens when I fire up the repl in the user NS or when I do:

(ns testit
  (:require clojure.core))

What am I missing here?  It has to be something extra dumb (even for
me...)

 *clojure-version*
{:interim true, :major 1, :minor 1, :incremental 0, :qualifier
"alpha"}

Thanks

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


Re: Cannot find juxt in clojure 1.1 (??)

2010-04-23 Thread Jarkko Oranen


>  *clojure-version*
> {:interim true, :major 1, :minor 1, :incremental 0, :qualifier
> "alpha"}
>

Looks like you have some old version of 1.1 prior to release. The
release version of 1.1 shouldn't have the alpha qualifier.

Try upgrading.

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


Re: Slides for short (45 minutes) presentation of clojure for java devs

2010-04-23 Thread cburroughs
What I did when I needed to give a shorter talk was to base it on some
of the well known presentations and just cut out a lot. I don't think
Stuart's intro or Rich's "for Java people" talk assumes people are
already enthusiastic about functional programming.

[1] http://github.com/stuarthalloway/clojure-presentations/ or those
attached to the file section

On Apr 21, 8:14 am, Laurent PETIT  wrote:
> Hello,
>
> I've consulted a lot of already made presentations of clojure.
> They are great, but I guess they may not suit my needs because it
> seems to me that either:
>   * they are more 1 1/2 to 2 hours talks than 45 minutes
>   * they assume the "public" will not be relunctant to some terms like
> "Lisp", "Functional Programming" and directly present these as
> advantages
>
> My goal is to raise interest into clojure in the mind of a public of
> people having used java for a long time. They may have Scala already
> in their "radar", but not clojure, or may have seen it and immediately
> dismissed it for what seemed to them good reasons (mainly aversion for
> lisp syntax), though we all know this is not true after the "normal"
> adaptation period.
>
> Say this presentation could be the presentation that leads people, at
> its end, asking you for giving all those great other presentations
> already available that I mentioned before ...
>
> Any references I missed that already solve my problem ? :-)
>
> Thanks in advance,
>
> --
> Laurent
>

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


Re: Newbie: Finding performance bottlenecks

2010-04-23 Thread David Nolen
In your code you have:

(defstruct body
  :id
  :type ; :projectile or :unit -> projectiles do not collide with other
bodies;
  :current-position ; ref
  :current-cells  ; ref
  :current-rotation  ;atom
  :pixel-half-width :pixel-half-height
  :half-width :half-height
  :components) ; a map of (:comp-type comp)

It's discouraged to use the mutable reference types in a fine-grained way
like this. I would recommend changing your code to just be a vector of
Clojure PersistentMaps that you map over.  It seems that your program is not
so dissimilar from something that I worked on, you might want to look at
this code for some ideas how to improve the speed of your code:
http://github.com/swannodette/flocking/blob/master/src/flocking/flocking3.clj

When I first implemented this in early 2008 it was taking about 100-120ms to
update 150 "boids". This version can do it in about 6-8ms.

I also note that you're not type-hinting your math, but I'm unsure how much
that plays into the perf you're seeing.

David

On Fri, Apr 23, 2010 at 4:55 AM, msappler  wrote:

> http://pastebin.com/Vv7xr6Uj

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

Re: Try + finally question

2010-04-23 Thread Armando Blancas
> Is there any easy workaround which doesn't involve defing a global
> conn.

To do all in a single place you'll have to mimic the Java idiom.

(let [conn (atom nil)]
  (try
(reset! conn (API/getConnection ...) ...
(catch ...)
(finally (if @conn (API/closeConnection @conn)

As it's been explained, a better way would be a variant of with-open,
maybe within a try form if you want to handle open errors locally.

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


Re: Datatypes and Protocols update

2010-04-23 Thread ataggart
One problem with requiring the "other" object to be of the same type
is that it would break the current model, e.g.:

user=> (= '(1 2 3) [1 2 3])
true

I'm left to wonder if it the more correct implementation of the
desired behavior is not to override the equals, but rather to
implement Comparable.


On Apr 23, 12:12 am, Konrad Hinsen  wrote:
> On 22 Apr 2010, at 21:15, Konrad Hinsen wrote:
>
> > I have several former deftypes that are a perfect fit for the new  
> > defrecord, except that they need a specific comparison function.  
> > This is usually for excluding some fields from equality testing, or  
> > for requiring identity rather than equality for some fields.
>
> What I'd actually like to have for defrecord is an "equality" protocol  
> that I can implement myself or use a default implementation. That  
> protocol would have a function "equals" guaranteed to be called only  
> if the object compared to is of the same type. Object.equals would  
> take care of type testing and then call the protocol function. That  
> would remove the check-type-before-comparing-fields overhead that  
> every equals implementation for deftype and defrecord currently  
> requires.
>
> Konrad.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

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


Re: problem installing clojure/Enclojure with Netbeans

2010-04-23 Thread Sophie
I had trouble with Enclojure 1.1.1

What worked for me: uninstall it and follow the Netbeans section at
http://github.com/relevance/labrepl

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


Re: Datatypes and Protocols update

2010-04-23 Thread Rich Hickey


On Apr 22, 2010, at 3:15 PM, Konrad Hinsen wrote:


On 22.04.2010, at 18:53, Rich Hickey wrote:


Feedback and errata welcome as always,


One feature in the deftype/defrecord split that I regret is that  
defrecord no longer allows the redefinition of equals and hashCode.  
Any attempt to override those results in an error message about  
duplicate method definitions.


I have several former deftypes that are a perfect fit for the new  
defrecord, except that they need a specific comparison function.  
This is usually for excluding some fields from equality testing, or  
for requiring identity rather than equality for some fields.


It is a design goal of defrecord that the types it creates have  
uniform semantics. As soon as you have user-defined equality you can  
get broken semantics.




As it is, I must convert all these to the new deftype, losing the  
convient field access through keywords.




You can get that back easily by implementing ILookup/IKeywordLookup,  
as does defrecord. I still have ideas about macro-like mixins for use  
in deftype, but I concluded the mandatory use of such mixins to create  
record-like things was too much user effort, and we need more  
experience with code reuse in deftype to determine need.


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


Re: Datatypes and Protocols update

2010-04-23 Thread Rich Hickey


On Apr 23, 2010, at 3:12 AM, Konrad Hinsen wrote:


On 22 Apr 2010, at 21:15, Konrad Hinsen wrote:

I have several former deftypes that are a perfect fit for the new  
defrecord, except that they need a specific comparison function.  
This is usually for excluding some fields from equality testing, or  
for requiring identity rather than equality for some fields.


What I'd actually like to have for defrecord is an "equality"  
protocol that I can implement myself or use a default  
implementation. That protocol would have a function "equals"  
guaranteed to be called only if the object compared to is of the  
same type. Object.equals would take care of type testing and then  
call the protocol function. That would remove the check-type-before- 
comparing-fields overhead that every equals implementation for  
deftype and defrecord currently requires.




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


Re: Datatypes and Protocols update

2010-04-23 Thread Rich Hickey


On Apr 22, 2010, at 1:30 PM, Mark Engelberg wrote:


I tried using deftype relatively recently, but realized it wouldn't
work for my needs because serialization via *print-dup* wasn't yet
implemented.  I'd recommend including this with the 1.2 release (or is
there a new recommended way to serialize Clojure data?)


print-dup is likely for defrecord, but not deftype (roll your own  
there).


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


Re: Datatypes and Protocols update

2010-04-23 Thread Krukow
On Apr 22, 6:53 pm, Rich Hickey  wrote:
[snip..]
> Feedback and errata welcome as always,
>

1) Typo on http://clojure.org/protocols:

Section "Basics"
defprotocol will automatically generate a corresponding interface,
with the same name as the protocol, i.e. given a protocol my.ns/
Protocol, an interface my.ns.MyProtocol.

my.ns.MyProtocol => my.ns.Protocol


2) Question. Could someone elaborate on the bullet

"You can implement a protocol on an interface"

Spefically the relation to multiple inheritance

3) When is 1.2 expected (roughly)?

Thanks,
/Karl

[snip..]

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


Re: Datatypes and Protocols update

2010-04-23 Thread Konrad Hinsen
On 23.04.2010, at 17:49, ataggart wrote:

> One problem with requiring the "other" object to be of the same type
> is that it would break the current model, e.g.:
> 
> user=> (= '(1 2 3) [1 2 3])
> true

I'd want this only for defrecord, which is a more limited (but also more 
convenient) way to define types. For the more basic and general deftype, 
everything should be possible.

However, a perhaps better way to arrive at the same goal is to provide a macro 
that takes care of the type comparison.

> I'm left to wonder if it the more correct implementation of the
> desired behavior is not to override the equals, but rather to
> implement Comparable.

Comparable requires a fully defined order relation, if I remember correctly. 
And it's not used by the standard Clojure comparison operators.

Konrad.

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


Re: Datatypes and Protocols update

2010-04-23 Thread Konrad Hinsen
On 23.04.2010, at 19:20, Rich Hickey wrote:

> You can get that back easily by implementing ILookup/IKeywordLookup, as does 
> defrecord. I still have ideas about macro-like mixins for use in deftype, but 
> I concluded the mandatory use of such mixins to create record-like things was 
> too much user effort, and we need more experience with code reuse in deftype 
> to determine need.

That sounds very interesting. I have been playing with various ideas for 
reusing method code in several defttypes, but I am not really happy with any of 
them. Macros are difficult to use because nothing at the toplevel of a deftype 
form is macro-expanded. Syntax-quote is messy because it requires so many 
symbols to be prefixed with ~'. I ended up writing my own little templating 
system but its use is getting messier all the time as well.

Konrad.

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


emacs setup

2010-04-23 Thread catonano
Hello,

I need some help in order to set up a decent setting as in the
subject.

I mean, there's elpa, leningen, apt-get, what am I supposed to do ?

Thanks for any hint
Cato

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


Re: emacs setup

2010-04-23 Thread Phil Hagelberg
On Fri, Apr 23, 2010 at 12:36 PM, catonano  wrote:
> I need some help in order to set up a decent setting as in the subject.
>
> I mean, there's elpa, leningen, apt-get, what am I supposed to do ?


The Getting Started page on the wiki covers this pretty well:

http://www.assembla.com/wiki/show/clojure/Getting_Started_with_Emacs

-Phil

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


Sponge: A Clojure App with a Swing Interface

2010-04-23 Thread Neill Alexander
Just in case anybody is interested

I have written a tool to aid developing against a web-service. It sits
between the Soap client and the Soap service and acts as a router (a
bit like SoapTrace). You can use it to record Soap sessions then
replay them. See http://github.com/NeillAlexander/sponge.

The bulk of the logic is in Clojure, with a GUI written in Java using
the Netbeans GUI builder. The entry point for the application is in
Clojure code. It instantiates the GUI and passes in a proxy which
implements the GUIController interface. That's how I got the Java and
Clojure bits talking to each other.

I built the early versions of Sponge using Leiningen which I found was
a very quick and easy way to get up and running. Once I started
working on the GUI I converted the project to use Maven for the build.

I just thought I would post this in case anybody wants to look at a
project that integrates Java and Clojure, using Maven for the build.
I'm not making any great claims for the quality of the Clojure code
(or the Java code for that matter). I still have a lot to learn (put
it this way - I'm looking forward to reading "The Joy of Clojure").
But it works, and someone somewhere might find it useful.

I really enjoyed developing in Clojure. Being able to start a REPL
from the application then connect to it from Emacs was incredibly
useful for fixing bugs. Thanks to Rich and all the Clojure devs for
designing a wonderful language. I will be doing my best to introduce
into every project I work on from now on!

:-)

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


Re: Try + finally question

2010-04-23 Thread ataggart
I wrote this, which seems to solve the problem being discussed:

http://gist.github.com/377278

Thoughts?



On Apr 23, 8:10 am, Armando Blancas  wrote:
> > Is there any easy workaround which doesn't involve defing a global
> > conn.
>
> To do all in a single place you'll have to mimic the Java idiom.
>
> (let [conn (atom nil)]
>   (try
>     (reset! conn (API/getConnection ...) ...
>     (catch ...)
>     (finally (if @conn (API/closeConnection @conn)
>
> As it's been explained, a better way would be a variant of with-open,
> maybe within a try form if you want to handle open errors locally.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

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


Re: Slides for short (45 minutes) presentation of clojure for java devs

2010-04-23 Thread Laurent PETIT
Thanks for the "food for thought". I'm concerned with the short
introduction not being too much "goal oriented" (and more "tutorial
oriented"), I'll continue think about it in "background mode".

Cheers,

-- 
Laurent

2010/4/23 cburroughs :
> What I did when I needed to give a shorter talk was to base it on some
> of the well known presentations and just cut out a lot. I don't think
> Stuart's intro or Rich's "for Java people" talk assumes people are
> already enthusiastic about functional programming.
>
> [1] http://github.com/stuarthalloway/clojure-presentations/ or those
> attached to the file section
>
> On Apr 21, 8:14 am, Laurent PETIT  wrote:
>> Hello,
>>
>> I've consulted a lot of already made presentations of clojure.
>> They are great, but I guess they may not suit my needs because it
>> seems to me that either:
>>   * they are more 1 1/2 to 2 hours talks than 45 minutes
>>   * they assume the "public" will not be relunctant to some terms like
>> "Lisp", "Functional Programming" and directly present these as
>> advantages
>>
>> My goal is to raise interest into clojure in the mind of a public of
>> people having used java for a long time. They may have Scala already
>> in their "radar", but not clojure, or may have seen it and immediately
>> dismissed it for what seemed to them good reasons (mainly aversion for
>> lisp syntax), though we all know this is not true after the "normal"
>> adaptation period.
>>
>> Say this presentation could be the presentation that leads people, at
>> its end, asking you for giving all those great other presentations
>> already available that I mentioned before ...
>>
>> Any references I missed that already solve my problem ? :-)
>>
>> Thanks in advance,
>>
>> --
>> Laurent
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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


Annotations

2010-04-23 Thread Rich Hickey
I've started adding some support for Java annotations, as of this
commit:

http://github.com/richhickey/clojure/commit/fa899d22dceb531d9f5af833ac6af0d956e6bdc7

Example of use:

http://gist.github.com/377213

It supports annotations for definterface/type/record types (put in
metadata on type name), deftype/record fields (in metadata on field
names), and deftype/record methods (in metadata on method name)

Interestingly, the bulk of the work is only 50 lines of Clojure. The
same code should be useful to gen-class.

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


Re: Cannot find juxt in clojure 1.1 (??)

2010-04-23 Thread Laurent PETIT
Hi,

yes, you may use a project created with a (very) old version of ccw,
thus initialized with a pre-release of 1.1.

To upgrade, use the Project > Properties > Java Build Path > Libs for
your project.

Or else, in the contextual menu of the project, click the
"enable/disable clojure support". This will automatically deregister
clojure and clojure-contrib from the project's java build path.
Then, remove the clojure/contrib jars if they were local to your
project's directory.
Ensure you have a recent version of ccw.
Then, "reclick" "enable/disable clojure support". It will
automatically add clojure/contrib jars (as well as jar source files)
to the root directory of your project, and to your projects java build
path settings. Hopefully these will be 1.1 release versions (as was
the case for me, I just double checked in my test environment).

HTH,

-- 
Laurent

2010/4/23 Jarkko Oranen :
>
>
>>  *clojure-version*
>> {:interim true, :major 1, :minor 1, :incremental 0, :qualifier
>> "alpha"}
>>
>
> Looks like you have some old version of 1.1 prior to release. The
> release version of 1.1 shouldn't have the alpha qualifier.
>
> Try upgrading.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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


Re: Annotations

2010-04-23 Thread Laurent PETIT
2010/4/24 Rich Hickey :
> I've started adding some support for Java annotations, as of this
> commit:
>
> http://github.com/richhickey/clojure/commit/fa899d22dceb531d9f5af833ac6af0d956e6bdc7
>
> Example of use:
>
> http://gist.github.com/377213
>
> It supports annotations for definterface/type/record types (put in
> metadata on type name), deftype/record fields (in metadata on field
> names), and deftype/record methods (in metadata on method name)
>
> Interestingly, the bulk of the work is only 50 lines of Clojure. The
> same code should be useful to gen-class.
>
> Feedback welcome,

Yay !
Do you also intend to add indentation support for method args ? Seems
to be heavily used e.g. in annotations for web services when one wants
to map methods args names to request args, etc. ?

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


Re: Annotations

2010-04-23 Thread Richard Newman

I've started adding some support for Java annotations, as of this
commit:


Fantastic! I'm just about to do some JAX-WS stuff (which requires  
annotations), so this is a welcome change.


The syntax looks no worse than Java's, so no comment on that...

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


Re: ClojureCLR start-up time

2010-04-23 Thread dmiller
I haven't compiled under a release in a while.  Recent changes to the
build system may have messed it up.  I'll check it out.

David


On Apr 23, 2:11 am, Joerthan Panest  wrote:
> Hello,
>
> I am considering ClojureCLR for embedding in an application, but it appears
> as though it takes ~4secs to start up. Is this typical? Is there a way to
> speed up? I realize that this could be hidden by opening it in a background
> process and leaving it open but I can see where that is less than ideal in
> some situations.
>
> I also noticed that the current development environment has many references
> to Debug bin settings and a short attempt to get it in Release mode failed
> with a number of errors. Is this due to the nature of the required run-time
> information or simply because it is still a Beta?
>
> Thank you,
> Joerthan
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

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


Re: Datatypes and Protocols update

2010-04-23 Thread Mark Engelberg
A few meandering observations:

I like the latest change to include a this argument.  It makes the
number of arguments line up which is a good thing.

I like the idea of defrecord for the common case, rather than having
to request default implementations of various interfaces within
deftype.  Still, I think the splitting of deftype and defrecord has
merely delayed, not eliminated, the need to eventually find a
convenient, general scheme for layering in default implementations of
interfaces.  I look forward to seeing how this evolves.

I like Rich's description of Clojure's datatypes/protocols as
"opinionated, and mostly agree with his manifesto.  The one opinion I
have the most difficulty with is:
"It has always been an unfortunate characteristic of using classes for
application domain information that it resulted in information being
hidden behind class-specific micro-languages, e.g. even the seemingly
harmless employee.getName() is a custom interface to data. Putting
information in such classes is a problem, much like having every book
being written in a different language would be a problem. You can no
longer take a generic approach to information processing. This results
in an explosion of needless specificity, and a dearth of reuse."

OO programmers write employee.getName() methods to preserve the option
of doing something more sophisticated later, which isn't readily
possible once all your clients start using employee.name everywhere.
So if you really want to create a generic approach to information
processing, it seems like the best approach is to address the
underlying reason that these custom interfaces are needed.

For this reason, I've always found appealing languages which let you
optionally write getter/setter methods that "hook into" the standard
field access syntax.  This lets you start out with your fields public,
and let your clients use the standard field access "interface".
Later, if you realize you need to do something special, you can easily
add a custom getter without breaking your clients.

As far as I know, Clojure doesn't currently make any attempt to
address this problem of allowing a standard way to access public data
from an object, while preserving the option of doing something more
sophisticated later.  So a programmer is still forced to choose
between the convenience of keyword lookup of data, versus a protocol
filled with "get-name" functions to preserve future flexibility.

Ideally, I'd like to see a way to allow me to write a program using
(:name employee), and later, if I need to, customize the employee
datatype so that (:name employee) actually dispatches to some other
function.  Ditto with (assoc employee :name "Mark") (for example, to
validate the data in some way?).

If I'm off-base, and these issues are easy to currently workaround in
Clojure, I'd love to hear more about how others are handling this in
their own programs.

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


Re: Datatypes and Protocols update

2010-04-23 Thread Michał Marczyk
On 24 April 2010 05:48, Mark Engelberg  wrote:
> Ideally, I'd like to see a way to allow me to write a program using
> (:name employee), and later, if I need to, customize the employee
> datatype so that (:name employee) actually dispatches to some other
> function.  Ditto with (assoc employee :name "Mark") (for example, to
> validate the data in some way?).

You can do that with deftype by implementing the appropriate
interfaces, like Rich mentioned in response to Konrad above. I've been
playing around with this actually:

http://gist.github.com/377480

Note that (:x (Foo. 1 2 3) nil) returns 1, while ((Foo. 1 2 3) :x)
returns 2. (It could be the other way around or whatever, anything
seems possible.)

Also note that for some reason (:x (Foo. 1 2 3) nil) works fine, while
(:x (Foo. 1 2 3)) throws an exception; not sure if I've run into a bug
here or simply done something silly (I'd expect the latter though).

Sincerely,
Michał

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


Adding an option to clojure.main

2010-04-23 Thread Phil Hagelberg
So it seems like recently the only thing I use AOT for is producing
-main functions that can be easily run from the command-line. I've
found that an alternate to this is to use clojure.main -e, require the
necessary namespace, and then call (apply -main *command-line-args*),
but this is rather awkward. I wonder if it would be convenient to have
clojure.main take another argument that would accept the name of a
namespace to look for a -main function in.

Thoughts? Would others use this?

-Phil

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


Re: wget replacement code review

2010-04-23 Thread JonathanMeeks
It's not answering your idiomatic clojure question, but extract-url-
filename will have problems because of this:

user> (.getFile (URL. "http://www.foo.com/";))
"/"



On Apr 21, 1:08 pm, Brent Millare  wrote:
> Technically I didn't write my own cause I just copied pasted it ;)
>
> For the purposes of this review, just consider that library code or a
> reference so everyone knows what it does. :)
>
>
>
> Sean Devlin wrote:
> > At first glance, you should be requiring c.c.string, and don't write
> > your own blank? fn.  That's the only low hanging fruit I see.
>
> > On Apr 21, 1:47 pm, Brent Millare  wrote:
> > > Hey all,
>
> > > I wrote a clojure version of the simplest functionality of wget. I
> > > basically translated the java version into clojure code, but I'm not
> > > quite happy with the wget-binary function because I use a loop, and I
> > > feel like someone else has a more idiomatic solution to iterating
> > > through a java-array. Also, I don't know if my way of handling the no
> > > filename case is best. Please tell me how to improve my code,
> > > especially in the interop sections.
>
> > > (ns dj
> > >   (:import [java.io File FileOutputStream BufferedInputStream
> > > BufferedReader InputStreamReader])
> > >   (:import [java.net URL])
> > >   (:require [clojure.contrib [duck-streams :as duck-streams]]))
>
> > > (defn blank?
> > >   "True if s is nil, empty, or contains only whitespace."
> > >   [#^String s]
> > >   (every? (fn [#^Character c] (Character/isWhitespace c)) s))
>
> > > (defn- extract-url-filename [url]
> > >   (let [filename (.getFile url)]
> > >     (if (blank? filename)
> > >       "index.html"
> > >       (subs filename 1
>
> > > (defn- wget-binary [con content-length]
> > >   (with-open [stream (BufferedInputStream. (.getInputStream con))]
> > >     (let [data (make-array Byte/TYPE content-length)]
> > >       (loop [offset 0]
> > >         (if (< offset content-length)
> > >           (let [bytesRead (.read stream
> > >                                  data
> > >                                  offset
> > >                                  (- content-length
> > >                                     offset))]
> > >             (if (= bytesRead -1)
> > >               data
> > >               (recur (+ offset bytesRead
> > >           data)
>
> > > (defn- wget-text [url-obj]
> > >   (with-open [buf (-> url-obj
> > >                       (.openStream)
> > >                       (InputStreamReader.)
> > >                       (BufferedReader.))]
> > >     (apply str (line-seq buf
>
> > > (defn wget [url-address]
> > >   (let [url (URL. url-address)
> > >         filename (extract-url-filename url)
> > >         con (.openConnection url)
> > >         content-length (.getContentLength con)]
> > >     (if (or (= -1 content-length)
> > >             (.startsWith (.getContentType con) "text/"))
> > >       (duck-streams/spit filename (wget-text url))
> > >       (with-open [out-file (FileOutputStream. filename)]
> > >         (.write out-file (wget-binary con content-length))
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to clojure@googlegroups.com
> > > Note that posts from new members are moderated - please be patient with 
> > > your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/clojure?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

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


Re: Annotations

2010-04-23 Thread Mark Derricutt
Looks nice from just looking at the gists - I have a small project
where annotations support would actually come in handy as well so will
definitely give this a try shortly.

mark

-- 
Pull me down under...

On Sat, Apr 24, 2010 at 12:06 PM, Rich Hickey  wrote:
> It supports annotations for definterface/type/record types (put in
> metadata on type name), deftype/record fields (in metadata on field
> names), and deftype/record methods (in metadata on method name)
>

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