spdegabrielle
2019-8-21 09:07:00

It’s not official so I’d prefer not to use the racket name. It might be a possibility if it evolves into a successful way of introducing beginners and promoting racket.


vijkum0692
2019-8-21 13:43:59

@vijkum0692 has joined the channel


thongpv87
2019-8-21 14:19:01

@thongpv87 has joined the channel


thongpv87
2019-8-21 14:22:09

I try to run this code from SICP book: (define (count-leaves x) (cond ((null? x) 0) ((not (pair? x)) 1) (else (+ (count-leaves (car x)) (count-leaves (cdr x)))))) (count-leaves '('(1 2) '(3 4))) 6 (count-leaves '((1 2) '(3 4))) 5 How can I explain the result


soegaard2
2019-8-21 14:27:05

@thongpv87 The ' is turned into (quote ...) by the reader. So '(1 2) is short for (quote (1 2)). This means that the symbol quote is counted in the first example.


thongpv87
2019-8-21 14:31:53

I thought the ' is the short cut to construct a list.


sergej
2019-8-21 14:32:43

won’t it be turned into (list 1 2)?


sergej
2019-8-21 14:33:43

or actually (quote (1 2))?


soegaard2
2019-8-21 14:34:08

If I say “simon” you say simon.


soegaard2
2019-8-21 14:34:29

The ’ or quote is the same concept for daturms.


soegaard2
2019-8-21 14:34:47

A ’datum will produce a value that prints as datum.


sergej
2019-8-21 14:35:22

so isn’t (1 2) the datum here?


sergej
2019-8-21 14:35:33

Racket says (quote 1 2) is bad syntax


soegaard2
2019-8-21 14:35:34

The concept is called quotation, but since (quote x) is cumbersome to write, you can abbreviate it as ’x.


soegaard2
2019-8-21 14:35:51

(quote (1 2))



sergej
2019-8-21 14:36:43

yeah, you just said above: > So '(1 2) is short for (quote 1 2).

so I was briefly confused


soegaard2
2019-8-21 14:37:17

Sorry - miswrote. Edited.


soegaard2
2019-8-21 14:37:59

Quotation works with vectors and hashtables too.


thongpv87
2019-8-21 14:43:08

is '(1 2) equivalent to (list 1 2)?


sergej
2019-8-21 14:43:38

no


sergej
2019-8-21 14:43:51

it’s equivalent to (quote (1 2))


sergej
2019-8-21 14:44:45

although (list 1 2) seems to evaluate to the same thing


thongpv87
2019-8-21 14:46:29

So quote is more abstract than list since it can construct vector and hashtable ?


soegaard2
2019-8-21 14:49:03

It is does a different job. If you get some result printed in the repl, then you can copy paste the result into a program and put a ’ before it.


thongpv87
2019-8-21 14:50:11

Thank you for the explanation.


thongpv87
2019-8-21 14:50:54

Why this give me the result 3: (length (cons (list 1 2) (list 3 4)))


thongpv87
2019-8-21 14:51:03

I thing the result should be 2.


sergej
2019-8-21 14:52:08

cons isn’t append, so cons puts the entire (list 1 2) as the first element of a new list


sergej
2019-8-21 14:52:22

so you get a list of (list 1 2), 3, and 4


sergej
2019-8-21 14:52:28

so 3 items


thongpv87
2019-8-21 14:53:54

Ah, I just forgot that. Thanks.