-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassessment.lisp
More file actions
83 lines (72 loc) · 2.13 KB
/
Copy pathassessment.lisp
File metadata and controls
83 lines (72 loc) · 2.13 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(defun lisp-is-awesome ()
;; Dynamic scoping issues
(defvar *dynamic-var* 10)
(defun dynamic-scope-func ()
(format t "Dynamic variable: ~a~%" *dynamic-var*))
(dynamic-scope-func)
(let ((*dynamic-var* "Now I'm a string!"))
(dynamic-scope-func))
(dynamic-scope-func)
;; Type errors
(defun type-error-func (x)
(+ x "string")) ; This will cause a type error
(handler-case
(type-error-func 10)
(type-error (e)
(format t "Caught type error: ~a~%" e)))
;; Variable shadowing
(let ((var 42))
(dotimes (i 1)
(let ((var "Shadowed variable"))
(format t "Inside block: ~a~%" var)))
(format t "Outside block: ~a~%" var))
;; Package system issues
(defpackage :mypackage
(:use :cl)
(:export :my-function))
(in-package :mypackage)
(defun my-function ()
(format t "Hello from mypackage~%"))
(in-package :cl-user)
(use-package :mypackage)
(my-function)
;; Macro pitfalls
(defmacro with-my-macro ((var val) &body body)
`(let ((,var ,val))
,@body))
(with-my-macro (x 10)
(format t "Macro value: ~a~%" x))
;; Error handling
(defun error-handling-func ()
(error "An error occurred"))
(handler-case
(error-handling-func)
(error (e)
(format t "Caught error: ~a~%" e)))
;; Circular dependencies
(defvar *circular-list* nil)
(setf *circular-list* (list 'a 'b 'c))
(setf (cdr (last *circular-list*)) *circular-list*)
(handler-case
(length *circular-list*)
(error (e)
(format t "Caught circular list error: ~a~%" e)))
;; Unreadable code with macros
(defmacro unreadable-code (&body body)
`(progn
,@(loop for form in body collect
`(format t "Executing form: ~a~%" ',form)
,form)))
(unreadable-code
(format t "This is a test~%")
(1+ 2)
(* 3 4))
;; Incomplete error messages
(defun incomplete-error-message ()
(handler-case
(error "This is an incomplete error message")
(error (e)
(format t "Caught error with message: ~a~%" (error-message e)))))
(incomplete-error-message)
(format t "End of wildly awesome function.~%"))
(lisp-is-awesome)