Re: I need a vector not a list?

2013-12-03 Thread Cedric Greevey
Seems to me that you can make a case for a seq is sort of like an
immutable PersistentIterator would be.

Iterator - next (get object)
seq - first (get object)

Iterator - next (mutate to point to next object)
seq - next (return new seq whose first is next object)





On Tue, Dec 3, 2013 at 2:49 AM, Andy Smith the4thamig...@googlemail.comwrote:

 Great point...

 --
 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-02 Thread Alex Miller
Actually, I'd say seqs are very much *unlike* iterators in other languages 
(Java in particular). 

Iterators - stateful cursors that conflate iteration with a check for 
whether more elements exist
Seqs - immutable persistent views of a collection that separate iteration 
from checking for more elements

http://clojure.org/sequences


On Sunday, December 1, 2013 6:22:57 PM UTC-6, James Reeves wrote:

 Seqs in Clojure are very much like iterators in other languages. They're 
 an abstraction for navigating a sequential data structure.

 Also because values in Clojure are immutable, you rarely, if at all, 
 encounter situations where those objects need to be copied. Why would you, 
 when you can just reference the original object, secure in the knowledge 
 that its value cannot change.

 - James


 On 1 December 2013 20:15, Andy Smith the4th...@googlemail.comjavascript:
  wrote:

 Can a seq be thought of as a kind of a list of pointers to the original 
 vector elements then? If so, then does an operation on a vector, (e.g. 
 reverse), cause clojure to internally generate a seq of pointers to the 
 original vector elements? In other words seqs seem to provide a layer of 
 indirection to avoid the need to copy elements of the original collection?


 On Saturday, 30 November 2013 21:31:34 UTC, Jim foo.bar wrote:

 On Sat, 30 Nov 2013 13:15:33 -0800 (PST) 
 Andy Smith the4th...@googlemail.com wrote: 

  but 
  my question is really about the more general case of any function 
  that manipulates a vector e.g. the following also returns a list 
  rather than a vector as desired, 

 In Clojure you rarely have to worry about types. All the 
 data-structures fall under a common set of abstractions and in 
 particular the ISeq interface. Strictly speaking map returns a seq not 
 a list. In fact a lazy seq...this is by design so further operations 
 can be applied lazily later...if you use eager operations like mapv 
 exclusively you lose the ability to aggregate operations without cost. 
 hope that clarifies it... 


 Jim 

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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 unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-02 Thread James Reeves
Perhaps I should have said that seqs fulfil the same role as iterators do,
rather than claiming they're alike :)

- James


On 2 December 2013 21:42, Alex Miller a...@puredanger.com wrote:

 Actually, I'd say seqs are very much *unlike* iterators in other languages
 (Java in particular).

 Iterators - stateful cursors that conflate iteration with a check for
 whether more elements exist
 Seqs - immutable persistent views of a collection that separate iteration
 from checking for more elements

 http://clojure.org/sequences


 On Sunday, December 1, 2013 6:22:57 PM UTC-6, James Reeves wrote:

 Seqs in Clojure are very much like iterators in other languages. They're
 an abstraction for navigating a sequential data structure.

 Also because values in Clojure are immutable, you rarely, if at all,
 encounter situations where those objects need to be copied. Why would you,
 when you can just reference the original object, secure in the knowledge
 that its value cannot change.

 - James


 On 1 December 2013 20:15, Andy Smith the4th...@googlemail.com wrote:

 Can a seq be thought of as a kind of a list of pointers to the original
 vector elements then? If so, then does an operation on a vector, (e.g.
 reverse), cause clojure to internally generate a seq of pointers to the
 original vector elements? In other words seqs seem to provide a layer of
 indirection to avoid the need to copy elements of the original collection?


 On Saturday, 30 November 2013 21:31:34 UTC, Jim foo.bar wrote:

 On Sat, 30 Nov 2013 13:15:33 -0800 (PST)
 Andy Smith the4th...@googlemail.com wrote:

  but
  my question is really about the more general case of any function
  that manipulates a vector e.g. the following also returns a list
  rather than a vector as desired,

 In Clojure you rarely have to worry about types. All the
 data-structures fall under a common set of abstractions and in
 particular the ISeq interface. Strictly speaking map returns a seq not
 a list. In fact a lazy seq...this is by design so further operations
 can be applied lazily later...if you use eager operations like mapv
 exclusively you lose the ability to aggregate operations without cost.
 hope that clarifies it...


 Jim

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-02 Thread Andy Smith
Great point...

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-01 Thread Andy Smith
Interesting alternatives. (vec) makes a vector out of a collection, so this 
is meant to be faster than (apply vector)? Also how does (into []) differ 
from (vec) in terms of what it does and its performance?


On Saturday, 30 November 2013 21:48:10 UTC, Kelker Ryan wrote:

 Vectors are mostly for speed and maintaining value sequence order. 

 Try this = (vec (reverse [1 2 3]))
 Not this = (apply vector (reverse [1 2 3]))

 As an alternative you can do this = (into [] (reverse [1 2 3]))

 You can always use mapv when calling fun for each coll object.

 Try this = (mapv #(* 2 %) [1 2 3])
 Not this = (apply vector (map (partial * 2) [1 2 3]))
  
  
 01.12.2013, 06:15, Andy Smith the4th...@googlemail.com javascript::

 Hi,

 I am trying to understand the manipulation of vectors from an efficiency 
 point of view. For example if I want to reverse a vector I can do the 
 following 

 (apply vector (reverse [1 2 3]))

 My understanding is that reverse will create a new list object (3 2 1) 
 then this will be used to construct a new vector object [3 2 1]. What can 
 I use to construct a new vector directly instead of having the intermediate 
 list object being constructed?

 I have read about rseq as providing something like a reverse iterator to 
 the same underlying vector, which may be a great solution in this case, but 
 my question is really about the more general case of any function that 
 manipulates a vector e.g. the following also returns a list rather than a 
 vector as desired,

 (map (partial * 2) [1 2 3]) 

 again forcing me to use apply vector e.g.

 (apply vector (map (partial * 2) [1 2 3]))

 Why dont we have a version of map that returns a vector when given a 
 vector? We can do this kind of thing in other languages with 
 templates/generics why not clojure?

 There is obviously some basic principle/understanding that I am missing 
 here. This kind of thing surely cant be very efficient, can it?

 Andy

  
 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com javascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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 unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-01 Thread Andy Smith
Can a seq be thought of as a kind of a list of pointers to the original 
vector elements then? If so, then does an operation on a vector, (e.g. 
reverse), cause clojure to internally generate a seq of pointers to the 
original vector elements? In other words seqs seem to provide a layer of 
indirection to avoid the need to copy elements of the original collection?

On Saturday, 30 November 2013 21:31:34 UTC, Jim foo.bar wrote:

 On Sat, 30 Nov 2013 13:15:33 -0800 (PST) 
 Andy Smith the4th...@googlemail.com javascript: wrote: 

  but 
  my question is really about the more general case of any function 
  that manipulates a vector e.g. the following also returns a list 
  rather than a vector as desired, 

 In Clojure you rarely have to worry about types. All the 
 data-structures fall under a common set of abstractions and in 
 particular the ISeq interface. Strictly speaking map returns a seq not 
 a list. In fact a lazy seq...this is by design so further operations 
 can be applied lazily later...if you use eager operations like mapv 
 exclusively you lose the ability to aggregate operations without cost. 
 hope that clarifies it... 


 Jim 


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-12-01 Thread James Reeves
Seqs in Clojure are very much like iterators in other languages. They're an
abstraction for navigating a sequential data structure.

Also because values in Clojure are immutable, you rarely, if at all,
encounter situations where those objects need to be copied. Why would you,
when you can just reference the original object, secure in the knowledge
that its value cannot change.

- James


On 1 December 2013 20:15, Andy Smith the4thamig...@googlemail.com wrote:

 Can a seq be thought of as a kind of a list of pointers to the original
 vector elements then? If so, then does an operation on a vector, (e.g.
 reverse), cause clojure to internally generate a seq of pointers to the
 original vector elements? In other words seqs seem to provide a layer of
 indirection to avoid the need to copy elements of the original collection?


 On Saturday, 30 November 2013 21:31:34 UTC, Jim foo.bar wrote:

 On Sat, 30 Nov 2013 13:15:33 -0800 (PST)
 Andy Smith the4th...@googlemail.com wrote:

  but
  my question is really about the more general case of any function
  that manipulates a vector e.g. the following also returns a list
  rather than a vector as desired,

 In Clojure you rarely have to worry about types. All the
 data-structures fall under a common set of abstractions and in
 particular the ISeq interface. Strictly speaking map returns a seq not
 a list. In fact a lazy seq...this is by design so further operations
 can be applied lazily later...if you use eager operations like mapv
 exclusively you lose the ability to aggregate operations without cost.
 hope that clarifies it...


 Jim

  --
 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-11-30 Thread Jim
On Sat, 30 Nov 2013 13:15:33 -0800 (PST)
Andy Smith the4thamig...@googlemail.com wrote:

 Why dont we have a version of map that returns a vector when given a 
 vector? We can do this kind of thing in other languages with 
 templates/generics why not clojure?

we do have mapv :)

Jim

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-11-30 Thread Jim
On Sat, 30 Nov 2013 13:15:33 -0800 (PST)
Andy Smith the4thamig...@googlemail.com wrote:

 but 
 my question is really about the more general case of any function
 that manipulates a vector e.g. the following also returns a list
 rather than a vector as desired,

In Clojure you rarely have to worry about types. All the
data-structures fall under a common set of abstractions and in
particular the ISeq interface. Strictly speaking map returns a seq not
a list. In fact a lazy seq...this is by design so further operations
can be applied lazily later...if you use eager operations like mapv
exclusively you lose the ability to aggregate operations without cost.
hope that clarifies it...


Jim

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I need a vector not a list?

2013-11-30 Thread Kelker Ryan
Vectors are mostly for speed and maintaining value sequence order. Try this = (vec (reverse [1 2 3]))Not this = (apply vector (reverse [1 2 3]))As an alternative you can do this = (into [] (reverse [1 2 3]))You can always use mapv when calling fun for each coll object.Try this = (mapv #(* 2 %) [1 2 3])Not this = (apply vector (map (partial * 2) [1 2 3]))  01.12.2013, 06:15, "Andy Smith" the4thamig...@googlemail.com:Hi,I am trying to understand the manipulation of vectors from an efficiency point of view. For example if I want to reverse a vector I can do the following (apply vector (reverse [1 2 3]))My understanding is that reverse will create a new list object (3 2 1) then this will be used to construct a new vector object [3 2 1]. What can I use to construct a new vector directly instead of having the intermediate list object being constructed?I have read about rseq as providing something like a reverse iterator to the same underlying vector, which may be a great solution in this case, but my question is really about the more general case of any function that manipulates a vector e.g. the following also returns a list rather than a vector as desired,(map (partial * 2) [1 2 3]) again forcing me to use apply vector e.g.(apply vector (map (partial * 2) [1 2 3]))Why dont we have a version of map that returns a vector when given a vector? We can do this kind of thing in other languages with templates/generics why not clojure?There is obviously some basic principle/understanding that I am missing here. This kind of thing surely cant be very efficient, can it?Andy --  --  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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.



-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.