Re: 'first vs 'nth on maps

2009-04-22 Thread Victor Rodriguez

On Mon, Apr 20, 2009 at 5:17 PM, Hugh Winkler hwink...@gmail.com wrote:

 On Mon, Apr 20, 2009 at 1:59 PM, David Nolen dnolen.li...@gmail.com wrote:
 Maps aren't ordered so this isn't a good idea anyway.

 It's a good idea if you have a sorted map. My example should have used
 sorted-map.

 The reason first/second work is because they call seq on the collection.
 (key (nth (seq {:a 1 :b 2 :c 3}) 1)) - :b


 Thanks! I think 'nth ought to behave just like 'first and 'second,
 don't you? If it's a good idea for 'first it's a good idea for 'nth.

Probably not.  I expect nth on a vector to be much faster than on a
seq.  O(1) vs O(n), respectively.

Cheers,

Victor Rodriguez.


 [Apologies to all for the several redundant posts on this topic. I've
 been getting rejection messages from Google Groups for no reason].

 On Mon, Apr 20, 2009 at 2:51 PM, hughw hwink...@gmail.com wrote:

 Hi all,

 Why should 'first and 'second work on maps, but not 'nth?

 user (key (first {:a 1 :b 2 :c 3}))
 :a
 user (key (nth  {:a 1 :b 2 :c 3} 0))
 ; Evaluation aborted.

 java.lang.UnsupportedOperationException: nth not supported on this
 type: PersistentArrayMap (NO_SOURCE_FILE:0)
  [Thrown class clojure.lang.Compiler$CompilerException]

 Thanks,
 Hugh




 




 --
 Hugh Winkler, CEO
 Wellstorm Development
 31900 Ranch Road 12
 Suite 206
 Dripping Springs, TX 78620
 USA
 http://www.wellstorm.com/
 +1 512 264 3998 x801

 


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



Re: 'first vs 'nth on maps

2009-04-22 Thread e
i've noticed a pattern in explanations in clojure that interface and runtime
are related.  Is that the point being made here?  Make expensive things hard
or at least explicit?

Maybe instead of nth, since that causes controversy,

call it find-nth or something?




On Wed, Apr 22, 2009 at 12:58 PM, Victor Rodriguez vict...@gmail.comwrote:


 On Mon, Apr 20, 2009 at 5:17 PM, Hugh Winkler hwink...@gmail.com wrote:
 
  On Mon, Apr 20, 2009 at 1:59 PM, David Nolen dnolen.li...@gmail.com
 wrote:
  Maps aren't ordered so this isn't a good idea anyway.
 
  It's a good idea if you have a sorted map. My example should have used
  sorted-map.
 
  The reason first/second work is because they call seq on the collection.
  (key (nth (seq {:a 1 :b 2 :c 3}) 1)) - :b
 
 
  Thanks! I think 'nth ought to behave just like 'first and 'second,
  don't you? If it's a good idea for 'first it's a good idea for 'nth.

 Probably not.  I expect nth on a vector to be much faster than on a
 seq.  O(1) vs O(n), respectively.

 Cheers,

 Victor Rodriguez.

 
  [Apologies to all for the several redundant posts on this topic. I've
  been getting rejection messages from Google Groups for no reason].
 
  On Mon, Apr 20, 2009 at 2:51 PM, hughw hwink...@gmail.com wrote:
 
  Hi all,
 
  Why should 'first and 'second work on maps, but not 'nth?
 
  user (key (first {:a 1 :b 2 :c 3}))
  :a
  user (key (nth  {:a 1 :b 2 :c 3} 0))
  ; Evaluation aborted.
 
  java.lang.UnsupportedOperationException: nth not supported on this
  type: PersistentArrayMap (NO_SOURCE_FILE:0)
   [Thrown class clojure.lang.Compiler$CompilerException]
 
  Thanks,
  Hugh
 
 
 
 
  
 
 
 
 
  --
  Hugh Winkler, CEO
  Wellstorm Development
  31900 Ranch Road 12
  Suite 206
  Dripping Springs, TX 78620
  USA
  http://www.wellstorm.com/
  +1 512 264 3998 x801
 
  
 

 


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



Re: 'first vs 'nth on maps

2009-04-21 Thread David Nolen
On Mon, Apr 20, 2009 at 5:17 PM, Hugh Winkler hwink...@gmail.com wrote


 Thanks! I think 'nth ought to behave just like 'first and 'second,
 don't you? If it's a good idea for 'first it's a good idea for 'nth.


It does seems like a reasonable behavior for sorted-set and sorted-map, but
what else really? Also this does seem to imply a performance penalty
(converting a large collection into a seq to which nth is applied). In
anycase I don't know enough about the performance implications to say
whether there's a reason for the current implementation of nth.

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



Re: 'first vs 'nth on maps

2009-04-20 Thread Hugh Winkler

On Mon, Apr 20, 2009 at 1:59 PM, David Nolen dnolen.li...@gmail.com wrote:
 Maps aren't ordered so this isn't a good idea anyway.

It's a good idea if you have a sorted map. My example should have used
sorted-map.

 The reason first/second work is because they call seq on the collection.
 (key (nth (seq {:a 1 :b 2 :c 3}) 1)) - :b


Thanks! I think 'nth ought to behave just like 'first and 'second,
don't you? If it's a good idea for 'first it's a good idea for 'nth.


[Apologies to all for the several redundant posts on this topic. I've
been getting rejection messages from Google Groups for no reason].

 On Mon, Apr 20, 2009 at 2:51 PM, hughw hwink...@gmail.com wrote:

 Hi all,

 Why should 'first and 'second work on maps, but not 'nth?

 user (key (first {:a 1 :b 2 :c 3}))
 :a
 user (key (nth  {:a 1 :b 2 :c 3} 0))
 ; Evaluation aborted.

 java.lang.UnsupportedOperationException: nth not supported on this
 type: PersistentArrayMap (NO_SOURCE_FILE:0)
  [Thrown class clojure.lang.Compiler$CompilerException]

 Thanks,
 Hugh




 




-- 
Hugh Winkler, CEO
Wellstorm Development
31900 Ranch Road 12
Suite 206
Dripping Springs, TX 78620
USA
http://www.wellstorm.com/
+1 512 264 3998 x801

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