teaching.rouxl.es
while
/for
loopsscm> 1
1
scm> 2
2
scm> #t
True
scm> #f
False
Remember this table?
Falsey | Truthy |
---|---|
False |
True |
None |
Everything else |
0 |
|
[] , "" , () , {} |
Falsey | Truthy |
---|---|
#f |
Everything else |
This is something you need to remember
define
(<keyword> [<arguments> ...])
define
keyword in order to bind values to symbols, which work the same way as variables.
(<keyword> [<arguments> ...])
define
keyword in order to bind values to symbols, which work the same way as variables.
>>> x = 3
scm> (define x 3)
x
(<operator> [<operands> ...])
>>> add(1, 2)
3
scm> (+ 1 2)
3
if
)(if <predicate> <if-true> [<if-false>])
<predicate>
and <if-true>
are required, <if-false>
is optional<predicate>
<predicate>
is truthy (don't forget what Scheme does!), evaluate <if-true>
<if-false>
(if it exists)if
)scm> (if (> 4 3) 3 2)
3
scm> (if 0 3 2)
3
scm> (if #f 3 2)
2
scm> (if (= 3 2) (/ 1 0) 3)
3
scm> (if (= 3 3) (/ 1 0) 3)
Error
and
, or
, not
(and 1 2 3)
→ 3
(or 1 2 3)
→ 1
(not 0)
→ #f
Equivalence
=
- used for numberseq?
- is
in Pythonequal?
- ==
in Pythonlambda
functions in scheme.(lambda ([<params> ...]) <body>)
scm> (lambda (x) (+ x 2))
(lambda (x) (+ x 2))
scm> (define f (lambda (x) (+ x 2)))
f
scm> f
(lambda (x) (+ x 2))
(define (<name> [<params> ...]) <body>)
scm> (define (f x) (+ x 2))
f
scm> f
(lambda (x) (+ x 2))
links.rouxl.es/disc
lnk.first
- gets the first elementlnk.rest
- gets the rest of your linked list(car lnk)
- gets the first element(cdr lnk)
- gets the rest of your scheme list>>> Link(1, Link(2), Link(3))
Link(1, Link(2), Link(3))
scm> (cons 1 (cons 2 (cons 3 nil)))
(1 2 3)
scm> (list 1 2 3)
(1 2 3)
scm> '(1 2 3)
(1 2 3)
links.rouxl.es/feedback
Thanks for coming!
Please give me feedback on what to improve!