Origin for Clojure using the term 'vector' instead of 'array'?

162 views
Skip to first unread message

Daniel Compton

unread,
Oct 2, 2015, 10:49:57 PM10/2/15
to Clojure List
I recently had someone learning Clojure ask me why Clojure used the term 'vector' when many other languages used the term 'array'. I thought for a bit, and the only reason I could come up with was that it clearly differentiated Clojure's array-like data structures from Java's array data structures. I had a search online and couldn't find anything discussing this.

Does anyone know if there is an official reason for this?
--
Daniel

James Reeves

unread,
Oct 2, 2015, 11:19:39 PM10/2/15
to clo...@googlegroups.com
In a number of languages, arrays are typically a fixed size, whereas vectors are typically a variable size.

I imagine Clojure adopts this for the same reason, and also because "array" already refers to Java arrays.

- James

--
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/d/optout.

Mars0i

unread,
Oct 2, 2015, 11:46:26 PM10/2/15
to Clojure
I have no idea about the official reason, but outside of certain programming languages that use "array" for one-dimensional data structures, an array often has two (or more) dimensions.  In R, for example, arrays can have an arbitrary number of dimensions.  Honestly, when I'm away from Java for a while and then encounter the term "array" in Java, I have to stop and remember that it's 1-D, or check some documentation, because "array" doesn't automatically mean 1-D to me.

On the other hand, I believe that vectors are always one-dimensional, as in linear algebra.

So maybe Rich Hickey just decided that "vector" was a better, less ambiguous name.

Gary Verhaegen

unread,
Oct 3, 2015, 3:32:13 AM10/3/15
to clo...@googlegroups.com
For people with a C/Java-style background, array typically designates a contiguous piece of memory that has been allocated at once, is thus fixed-size, and can be accessed randomly (i.e. by index). Vectors are typically structures or objects at a higher level, that still present a random-access collection, but can also for example change size.

With that Background, Clojure's choice makes perfect sense. Please also consider that Clojure does not use vector instead of array, but in addition to; see make-array, geta, seta, et al.
--

Tj Gabbour

unread,
Oct 3, 2015, 5:20:38 AM10/3/15
to Clojure
Yep:

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
https://docs.oracle.com/javase/7/docs/api/java/util/Vector.html
“The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created.”


On Saturday, October 3, 2015 at 9:32:13 AM UTC+2, Gary Verhaegen wrote:
For people with a C/Java-style background, array typically designates a contiguous piece of memory that has been allocated at once, is thus fixed-size, and can be accessed randomly (i.e. by index). Vectors are typically structures or objects at a higher level, that still present a random-access collection, but can also for example change size.

With that Background, Clojure's choice makes perfect sense. Please also consider that Clojure does not use vector instead of array, but in addition to; see make-array, geta, seta, et al.

On Saturday, 3 October 2015, Mars0i <mars...@logical.net> wrote:
I have no idea about the official reason, but outside of certain programming languages that use "array" for one-dimensional data structures, an array often has two (or more) dimensions.  In R, for example, arrays can have an arbitrary number of dimensions.  Honestly, when I'm away from Java for a while and then encounter the term "array" in Java, I have to stop and remember that it's 1-D, or check some documentation, because "array" doesn't automatically mean 1-D to me.

On the other hand, I believe that vectors are always one-dimensional, as in linear algebra.

So maybe Rich Hickey just decided that "vector" was a better, less ambiguous name.

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

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+unsubscribe@googlegroups.com.

Erik Price

unread,
Oct 3, 2015, 10:44:35 AM10/3/15
to clo...@googlegroups.com

I always assumed it was because vectors have similar properties to the classic java.util.Vector: they’re variable-length, contain heterogenous objects accessible by integer index, and safe for concurrent access from multiple threads: http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html

e


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

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.

Daniel Barlow

unread,
Oct 3, 2015, 12:18:52 PM10/3/15
to clo...@googlegroups.com

Common Lisp also has multi dimensional arrays and one - dimensional vectors.  I believe Rich was pretty familiar with that language in a former life

http://clhs.lisp.se/Body/t_array.htm

Reply all
Reply to author
Forward
0 new messages