Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Konrad Hinsen
On 13 Nov 2009, at 08:13, Mark Engelberg wrote: Is there a way to customize the way that types defined by deftype print in the REPL? Implement the multimethod clojure.core/print-method for the associated type tag: (deftype Foo ...) (defmethod clojure.core/print-method ::Foo [x] ...)

Re: Better documentation and error messages are needed for the ns macro

2009-11-13 Thread Andrew Boekhoff
With clojure-in-clojure on the horizon (if not around the corner) I wonder if an imports clause would be appropriate, and solve some of the complexities of discerning between clojure and java/clr/javascript/objectivec/(go?) (ns foo (uses clojure.contrib.repl-utils) (imports java.util [List

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Alex Osborne
Mark Engelberg wrote: Protocols: I don't understand whether there's any way to provide a partial implementation or default implementation of a given protocol/interface, and I believe this to be an important issue. For example, a protocol for and that provides a default implementation

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Jarkko Oranen
On Nov 13, 9:13 am, Krukow karl.kru...@gmail.com wrote: I was thinking this may make syntax irregular. I suspect this is a deliberate design choice to distinguish clojure protocols from java interfaces? Is this the case? As far as I understand it, in defprotocol's case, I suspect there is no

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Chris Kent
Mark Engelberg mark.engelberg at gmail.com writes: I'm a little worried about the strong overlap between reify/proxy, deftype/defstruct, and defclass/gen-class. I can just imagine the questions a year from now when people join the Clojure community and want to understand how they differ. So

New user/request for code critique/Clojure is awesome

2009-11-13 Thread Ross Thomas
Hello group, First I'd like to thank Rich for such a great new tool. The assertion in Programming Clojure that it feels like a general-purpose language beamed back from the near future really sums things up very nicely. Homoiconicity + FP + STM + JVM = epic win. Anyway, thought I'd say hi, and

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Meikel Brandmeyer
Hi, On Nov 13, 8:13 am, Mark Engelberg mark.engelb...@gmail.com wrote: Is there a way to customize the way that types defined by deftype print in the REPL? One can add a method to print-method for the type. While these datatype and protocol constructs are taking shape, maybe now is the

Re: New user/request for code critique/Clojure is awesome

2009-11-13 Thread Laurent PETIT
Hello, and welcome on board ! :-) One general remark : too much things done at the top level. It's ok to define some globals such as (def listen-port 8555) but having this (def server-sock (ServerSocket. listen-port)) will raise the problem that as soon as you 'require your namespace, the

Re: New user/request for code critique/Clojure is awesome

2009-11-13 Thread James Reeves
On Nov 13, 7:35 am, Ross Thomas halfacan...@gmail.com wrote: (ns seq-server   #^{:author Ross Thomas halfacan...@gmail.com}   (:import (java.net ServerSocket))) The metadata should come before the symbol it's applied to, i.e. (ns #^{:author Ross Thomas halfacan...@gmail.com} seq-server

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread MikeM
(deftype Foo [a b c]) (defprotocol P (bar [x] bar docs)) (extend ::Foo P {:bar (fn [afoo] :foo-thing)}) A common error may be to: (extend Foo P {:bar (fn [afoo] :foo-thing)}) when (extend ::Foo ... is intended. I notice that (extend Foo... doesn't throw - should extend check that it is

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 2:13 am, Mark Engelberg mark.engelb...@gmail.com wrote: I'm still trying to get my head around the new features. Seeing more code examples will definitely help. In the meantime, here is some stream-of-consciousness thoughts and questions. Datatypes: I'm a little worried about

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread AlexK
Hi everybody, after playing around with protocols datatypes, I found them very fun to use. Some questions: Performance I don't see (with my limited benchmarking) any significant difference between multifns and protocolfns: user= (defprotocol Test (protocol-fn [it] Protocol-fn)) Test user=

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 3:58 am, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 13 Nov 2009, at 08:13, Mark Engelberg wrote: Protocols: I don't understand whether there's any way to provide a partial implementation or default implementation of a given protocol/interface, and I believe this to

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 9:03 am, MikeM michael.messini...@invista.com wrote: (deftype Foo [a b c]) (defprotocol P (bar [x] bar docs)) (extend ::Foo P {:bar (fn [afoo] :foo-thing)}) A common error may be to: (extend Foo P {:bar (fn [afoo] :foo-thing)}) when (extend ::Foo ... is intended. I

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 4:55 am, Alex Osborne a...@meshy.org wrote: Mark Engelberg wrote: Protocols: I don't understand whether there's any way to provide a partial implementation or default implementation of a given protocol/interface, and I believe this to be an important issue. For example, a

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 5:27 am, Chris Kent cjk...@gmail.com wrote: Mark Engelberg mark.engelberg at gmail.com writes: I'm a little worried about the strong overlap between reify/proxy, deftype/defstruct, and defclass/gen-class.  I can just imagine the questions a year from now when people join the

Re: New user/request for code critique/Clojure is awesome

2009-11-13 Thread Sean Devlin
Heh, I was writing some networking stuff yesterday too. Small world. I'd make one change. Add (:use clojure.contrib.duck-streams) to your namespace definition. Then you can change handle-client to this (defn handle-client [_ client] (spit (.getOutputStream client) message) (doto client

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Sean Devlin
Rich, I was wondering something about defprotocol. Here's your example: (defprotocol AProtocol :on AnInterface A doc string for AProtocol abstraction (bar [a b] bar docs :on barMethod) (baz ([a] [a b] [a b amp; c]) baz docs)) In this case, you provide the docs for each method after

Re: swap two elements in an arbitrary collection

2009-11-13 Thread Sean Devlin
Yeah, and this code has the side effect of working on maps user=(swap [:a :b :c :d] 0 2) [:c :b :a :d] user=(swap {:a 1 :b 2 :c 3 :d 4} :a :c) {:a 3, :b 2, :c 1, :d 4} Hmmm... is this worth keeping? Maybe use the name switch instead, to avoid confusion with swap! (the atom operation).

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 10:42 am, Sean Devlin francoisdev...@gmail.com wrote: Rich, I was wondering something about defprotocol. Here's your example: (defprotocol AProtocol :on AnInterface   A doc string for AProtocol abstraction   (bar [a b] bar docs :on barMethod)   (baz ([a] [a b] [a b amp; c])

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 9:26 am, AlexK alexander.konstanti...@informatik.haw- hamburg.de wrote: Hi everybody, after playing around with protocols datatypes, I found them very fun to use. Some questions: Performance I don't see (with my limited benchmarking) any significant difference between

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 10:48 am, Stuart Halloway stuart.hallo...@gmail.com wrote:  But do people feel that some degree of data hiding is worthwhile? I don't. Hooray for benevolent dictators! I was just putting in my vote :) Rich -- You received this message because you are subscribed to the

Re: swap two elements in an arbitrary collection

2009-11-13 Thread Mark Tomko
Indeed it does. I still think the array implementation of a heap is probably worth using, in spite of its use of indexes, but rather than use a generalized swap implementation to percolate elements up and down the tree, I'll stick with a vector implementation and keep it all hidden beneath the

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread David Nolen
Is there an argument for putting it after the argument list? :) On Fri, Nov 13, 2009 at 11:11 AM, Rich Hickey richhic...@gmail.com wrote: On Nov 13, 10:42 am, Sean Devlin francoisdev...@gmail.com wrote: Rich, I was wondering something about defprotocol. Here's your example:

Re: swap two elements in an arbitrary collection

2009-11-13 Thread Lauri Pesonen
Hi Mark, 2009/11/13 Mark Tomko mjt0...@gmail.com: I notice you used the '-' macro.  Perhaps I'm a little dense, but I haven't found the documentation for it to be terribly helpful.  Do you have simple, succinct explanation for what it does? The - macro calls the given forms with the return

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 9:24 am, James Reeves weavejes...@googlemail.com wrote: Are there any plans to use protocols to define polymorphic functions like conj and get? Perhaps with an untype function to remove type metadata so one could always get at the datastructures hidden by the protocol. e.g.

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Konrad Hinsen
On 13.11.2009, at 17:07, Rich Hickey wrote: Admittedly, it is a difference from multimethods. With protocols, both protocols and their functions/methods are immutable. Redefining or extending a protocol modifies only the protocol and fn vars. I prefer that, and don't consider the above

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Konrad Hinsen
On 13.11.2009, at 17:11, Rich Hickey wrote: On Nov 13, 10:42 am, Sean Devlin francoisdev...@gmail.com wrote: Would the following be possible: (defprotocol AProtocol :on AnInterface A doc string for AProtocol abstraction (bar bar docs [a b] :on barMethod) (baz baz docs ([a] [a b] [a b

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Sean Devlin
I agree w/ Constantine. This would be very, very useful. Sean On Nov 13, 1:01 pm, Constantine Vetoshev gepar...@gmail.com wrote: On Nov 12, 7:10 am, Rich Hickey richhic...@gmail.com wrote: [1]http://www.assembla.com/wiki/show/clojure/Datatypes Could you please elaborate on why you chose

Re: Better documentation and error messages are needed for the ns macro

2009-11-13 Thread Chouser
On Wed, Nov 11, 2009 at 4:24 PM, John Harrop jharrop...@gmail.com wrote: One question: how would Java class imports be dealt with? I think it should be unified: (ns foo   (uses java.io :only [File FileInputStream] :as io)) I think this is a bad idea. Java (or other host) classes are not

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread AlexK
On 13 Nov., 17:07, Rich Hickey richhic...@gmail.com wrote: This kind of do-nothing microbenchmarking demonstrates nothing. Protocol dispatching is significantly faster than multimethod dispatching, and I haven't even looked into call-site optimization. Protocol dispatch is not as fast as

Re: Language request: make key and val work on vector pairs too

2009-11-13 Thread samppi
That works, but I don't think it's satisfactory. first and second aren't the intended functions to access a map entry's keys and vals— but most importantly, it's been documented that second is very, very slow compared to val (http://w01fe.com/blog/2009/01/more-on-clojure- map-accessor-speeds/).

Re: Better documentation and error messages are needed for the ns macro

2009-11-13 Thread John Harrop
On Fri, Nov 13, 2009 at 1:23 PM, Chouser chou...@gmail.com wrote: On Wed, Nov 11, 2009 at 4:24 PM, John Harrop jharrop...@gmail.com wrote: One question: how would Java class imports be dealt with? I think it should be unified: (ns foo (uses java.io :only [File FileInputStream] :as

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Sierra
On Nov 12, 7:10 am, Rich Hickey richhic...@gmail.com wrote: An early version of the code for a few important new language features, datatypes[1] and protocols[2] Very simple example here: http://paste.lisp.org/display/90329 This shows how to do arithmetic with complex numbers using deftype and

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Laurent PETIT
Hi, 2009/11/13 Stuart Sierra the.stuart.sie...@gmail.com: On Nov 12, 7:10 am, Rich Hickey richhic...@gmail.com wrote: An early version of the code for a few important new language features, datatypes[1] and protocols[2] Very simple example here: http://paste.lisp.org/display/90329 This

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 1:01 pm, Constantine Vetoshev gepar...@gmail.com wrote: On Nov 12, 7:10 am, Rich Hickey richhic...@gmail.com wrote: [1]http://www.assembla.com/wiki/show/clojure/Datatypes Could you please elaborate on why you chose to make IPersistentMap an optional interface for deftype'd

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Halloway
Initial gut reaction: would like a shortcut syntax for opting in(or out), as this will be a very common use case. Suspect that most classes would rather have it than not, but that may be the Ruby programmer in me. Stu On Nov 13, 1:01 pm, Constantine Vetoshev gepar...@gmail.com wrote: On

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Sierra
On Nov 13, 3:42 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Very simple example here:http://paste.lisp.org/display/90329 Why not have used add/sub/... instead of +/-/... in the extension of Arithmetic for ::Complex ? :-p Just a little simpler, that's all. This example has maybe a

with-command-line and empty/nil args list

2009-11-13 Thread Mike Hogye
Using with-command-line from clojure.contrib.command-line, if the list of command-line args is empty or nil, the usage message is printed (and the nested code is not run), even if all the options have default values. The following (note that the first arg is the empty list) prints the usage

local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-13 Thread ajuc
Hello. I've tried to translate nice Hilbert-curve-index calculating function to clojure (http://blog.notdot.net/2009/11/Damn-Cool-Algorithms- Spatial-indexing-with-Quadtrees-and-Hilbert-Curves). I've got sth like that: (def hilbert-map { :a {[0 0] [0 :d], [0 1] [1 :a], [1 0] [3 :b], [1 1] [2

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Mark Engelberg
Rich, thanks for the extended explanation of the overlap between the old and new constructs; I found this explanation much clearer than what is currently on the wiki. Basically, the key for me was realizing that these new constructs are all you're likely to need as long as you are just

Re: with-command-line and empty/nil args list

2009-11-13 Thread Chouser
On Fri, Nov 13, 2009 at 5:16 PM, Mike Hogye stacktra...@gmail.com wrote: Using with-command-line from clojure.contrib.command-line, if the list of command-line args is empty or nil, the usage message is printed (and the nested code is not run), even if all the options have default values.

Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)

2009-11-13 Thread John Harrop
On Fri, Nov 13, 2009 at 6:48 PM, ajuc aju...@gmail.com wrote: Hello. I've tried to translate nice Hilbert-curve-index calculating function to clojure (http://blog.notdot.net/2009/11/Damn-Cool-Algorithms- Spatial-indexing-with-Quadtrees-and-Hilbert-Curves). I've got sth like that: (def

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread John Harrop
On Fri, Nov 13, 2009 at 8:50 PM, Mark Engelberg mark.engelb...@gmail.comwrote: Rich, thanks for the extended explanation of the overlap between the old and new constructs; I found this explanation much clearer than what is currently on the wiki. Basically, the key for me was realizing that

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread cody koeninger
On Nov 13, 9:42 am, Sean Devlin francoisdev...@gmail.com wrote: In this case, you provide the docs for each method after parameters. Would the following be possible: (defprotocol AProtocol :on AnInterface   A doc string for AProtocol abstraction   (bar bar docs [a b] :on barMethod)   (baz