Raynes / tryclojure

A little web-based Clojure REPL powered by clojail.
400 stars 112 forks source link

"Vectors and lists" - wording in tutorial #33

Open mindplay-dk opened 11 years ago

mindplay-dk commented 11 years ago

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 commented 11 years ago

@mindplay-dk : Following examples already nicely explained in the tutorial by @Raynes :+1: 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 :)