Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Vectors and lists" - wording in tutorial #33

Open
mindplay-dk opened this issue Jan 10, 2013 · 1 comment
Open

"Vectors and lists" - wording in tutorial #33

mindplay-dk opened this issue Jan 10, 2013 · 1 comment

Comments

@mindplay-dk
Copy link

At one point in the tutorial, it states "Vectors and lists are sequential and ordered collections" - but the preceding example does not show anything called "lists", just vectors, maps and sets.

Maybe vectors and lists are the same thing? I don't know Clojure yet.

@harshadsabne
Copy link

@mindplay-dk : Following examples already nicely explained in the tutorial by @Raynes 👍 are lists:

(+ 3 3) // A list containing an operator and then operands.
(/ 10 3) // A list containing an operator and then operands.
(defn square [x] (* x x) ) //A "square" function that takes a single number and squares it. This entire defn block is a list. Here [x] is a vector while (* x x) is a list.

Coming back to your question:

  1. NO, Vectors and Lists are not the same.
  2. Both "Vectos" and "Lists" belong to Clojure "Collections" and all Clojure collections are immutable and persistent.

About Lists:

  1. Lists are used for sequential processing of data items.
  2. Lists are linked-list data structures.
  3. (class '(1 2 3)); => clojure.lang.PersistentList

About Vectors:

  1. Vectos are indexed by contiguous integers, meaning you can access vector items by index.
  2. Vectors are array based.
  3. (class [1 2 3]); => clojure.lang.PersistentVector

Hope this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants