-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathlet.lisp
62 lines (59 loc) · 2.09 KB
/
let.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;;; Copyright 2013 Google Inc.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.
(define-test let
;; The LET form establishes a lexical extent within which new variables are
;; created: a symbol that names a variable becomes bound to a value.
(let ((x 10)
(y 20))
(assert-equal ____ (+ x y))
;; It is possible to shadow previously visible bindings.
(let ((y 30))
(assert-equal ____ (+ x y)))
(assert-equal ____ (+ x y)))
;; Variables bound by LET have a default value of NIL.
(let (x)
(assert-equal ____ x)))
(define-test let-versus-let*
;; LET* is similar to LET, except the bindings are established sequentially,
;; and a binding may use bindings that were established before it.
(let ((x 10)
(y 20))
(let ((x (+ y 100))
(y (+ x 100)))
(assert-equal ____ x)
(assert-equal ____ y))
(let* ((x (+ y 100))
(y (+ x 100)))
;; Which X is used to compute the value of Y?
(assert-equal ____ x)
(assert-equal ____ y))))
(define-test let-it-be-equal
;; Fill in the LET and LET* to get the tests to pass.
(let ((a 1)
(b :two)
(c "Three"))
(let ((____ ____)
(____ ____)
(____ ____))
(assert-equal a 100)
(assert-equal b 200)
(assert-equal c "Jellyfish"))
(let* ((____ ____)
(____ ____)
;; In this third binding, you are allowed to use the variables bound
;; by the previous two LET* bindings.
(____ ____))
(assert-equal a 121)
(assert-equal b 200)
(assert-equal c (+ a (/ b a))))))