viktor
viktor

Reputation: 1297

Lisp initialize variable with list

I'm learning Lisp. I'm implementing solution to some relatively simple problem. I'm thinking of list that represents initial state of problem like this

((0 1) (2 3) (5 4))

I want to create variable and assign that list to it. I've tried

(let ((initial-state ((0 1) (2 3) (5 4)))))

but this won't compile. After that I've tried

(let ((initial-state list (list 0 1) (list 2 3) (list 5 4))))

this works, but it's too long. Is there better way to do this?

Upvotes: 0

Views: 1754

Answers (2)

Elias Dorneles
Elias Dorneles

Reputation: 23796

Do you mean this?

(let ((initial-state '((0 1) (2 3) (5 4)))) ...)

That single quote is a quote. :) More about quoting here:

Upvotes: 3

mange
mange

Reputation: 3212

(let ((initial-state '((0 1) (2 3) (4 5))))
  ...)

The ' expands to (quote ...) which basically means "don't evaluate this, just return it to me as a list". It's used to separate data from code (which in lisp are related concepts).

Upvotes: 5

Related Questions