Re: Datatypes and Protocols - early experience program

2009-11-13 Thread cody koeninger
On Nov 13, 9:42 am, Sean Devlin 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 "baz docs" ([a

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread John Harrop
On Fri, Nov 13, 2009 at 8:50 PM, Mark Engelberg wrote: > 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 a

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 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 hilbert-ma

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 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. It's a feature! http

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 programming

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 :

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 messag

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Sierra
On Nov 13, 3:42 pm, Laurent PETIT 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 problem : doesn't the

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 wrote: >> On Nov 12, 7:10 am,

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 1:01 pm, Constantine Vetoshev wrote: > On Nov 12, 7:10 am, Rich Hickey 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 types, rather than making it > autom

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Laurent PETIT
Hi, 2009/11/13 Stuart Sierra : > On Nov 12, 7:10 am, Rich Hickey 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 nu

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Sierra
On Nov 12, 7:10 am, Rich Hickey 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 defprotocol. It d

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 wrote: > On Wed, Nov 11, 2009 at 4:24 PM, John Harrop 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

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/). sec

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread AlexK
On 13 Nov., 17:07, Rich Hickey 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 interface dispatch,

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 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 Clojure functions, no

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 wrote: > On Nov 12, 7:10 am, Rich Hickey wrote: > > > [1]http://www.assembla.com/wiki/show/clojure/Datatypes > > Could you please elaborate on why you chose to make IPersistentMap an > option

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 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 & c])

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Constantine Vetoshev
On Nov 12, 7:10 am, Rich Hickey 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 types, rather than making it automatic? I'm asking because I found the automatic defstruct-map eq

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 beh

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 9:24 am, James Reeves 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. > > (defn sql-get [table ke

Re: swap two elements in an arbitrary collection

2009-11-13 Thread Lauri Pesonen
Hi Mark, 2009/11/13 Mark Tomko : > > 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 value of prev

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 wrote: > > > On Nov 13, 10:42 am, Sean Devlin wrote: > > Rich, > > I was wondering something about defprotocol. > > > > Here's your example: > > > > (defprotocol AProtocol :on AnInterfa

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread David Nolen
I place my vote for no data hiding. On Fri, Nov 13, 2009 at 10:48 AM, Stuart Halloway wrote: > >> But do > >> people feel that some degree of data hiding is worthwhile? > > > > I don't. > > > Hooray for benevolent dictators! > > -- > You received this message because you are subscribed to the G

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 imp

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 10:48 am, Stuart Halloway 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 Google Groups "Clo

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 9:26 am, AlexK 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 multifns and protocolfns: > ... > This is what I

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 10:42 am, Sean Devlin 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 & c]) "baz docs")) > >

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 op

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Stuart Halloway
>> But do >> people feel that some degree of data hiding is worthwhile? > > I don't. Hooray for benevolent dictators! -- 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

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 & c]) "baz docs")) In this case, you provide the docs for each method after para

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 Rich Hickey
On Nov 13, 9:03 am, MikeM 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 notice that (extend

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 4:55 am, Alex Osborne 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 p

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 5:27 am, Chris Kent wrote: > Mark Engelberg 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 > >

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Nov 13, 3:58 am, Konrad Hinsen 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 be an important

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, 2:13 am, Mark Engelberg 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 the strong overla

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread James Reeves
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. (defn sql-get [table key] (sql-query (str "select * from " table " wher

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

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

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

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Rich Hickey
On Fri, Nov 13, 2009 at 2:13 AM, Krukow wrote: > > > On Nov 12, 1:10 pm, Rich Hickey wrote: >> An early version of the code for a few important new language >> features, datatypes[1] and protocols[2] is now available in the 'new' >> branch[3]. Note also that the build system[4] has builds of 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 ser

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Meikel Brandmeyer
Hi, On Nov 13, 8:13 am, Mark Engelberg 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 time to discuss what kin

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 Chris Kent
Mark Engelberg 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 I think that

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Jarkko Oranen
On Nov 13, 9:13 am, Krukow 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 dot because the sp

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 > impleme

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 M

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] ...) > Wh

Re: swap two elements in an arbitrary collection

2009-11-13 Thread Christophe Grand
It's a pet peeve of mine but, please, try hard not to use indices :-) (or if you need indices pick a better suited data structure) The code you try to write is hard to write because you are going against the grain. If you try to write swap for vectors (which support efficient random lookup and ass