最近在看 sicp, 发现 lisp 挺有意思的.
刚刚试着写 leetcode 第二题的答案, 求 v 友帮忙看下那里有问题, 顺便教下怎么 debug
(define (extract p)
(if (null? p)
0
(car(p))))
(define (add x y) (
(+ (extract x)
(extract y)
)
))
(define (add2list l1 l2)
(if (and (null? l1) (null? l2))
()
(cons(
(add l1 l2)
(add2list (cdr l1) (cdr l2))))
))
用的mit-schema解释器
2 error> (add2list (list 1 2 3) (list 2 3 4))
;The object (4) is not applicable.
;To continue, call RESTART with an option number:
; (RESTART 3) => Specify a procedure to use in its place.
; (RESTART 2) => Return to read-eval-print level 2.
; (RESTART 1) => Return to read-eval-print level 1.
输入(debug)
3 error> (debug)
There are 26 subproblems on the stack.
Subproblem level: 0 (this is the lowest subproblem level)
Expression (from stack):
('(4))
There is no current environment.
The execution history for this subproblem contains 1 reduction.
You are now in the debugger. Type q to quit, ? for commands.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.