给定LISP eval函数的以下定义 - 添加defmacro函数需要什么?(甚至只是评估一个宏)
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x (cond (y 't) ('t '())))
('t '())))
(defun not. (x)
(cond (x '())
('t 't)))
(defun append. (x y)
(cond ((null. x) y)
('t (cons (car x) (append. (cdr x) y)))))
(defun list. (x y)
(cons x (cons y '())))
(defun pair. (x y)
(cond ((and. (null. x) (null. y)) '())
((and. (not. (atom x)) (not. (atom y)))
(cons (list. (car …Run Code Online (Sandbox Code Playgroud) 可能重复:
构建LISP机器需要多少个原语?十,七,五?
我好奇.什么是最小的LISP,可以在其上构建所有进一步的功能?忽视效率 - 问题来自一个优雅的地方.
如果你在外星球上醒来并被指示构建最小的LISP,你可以在以后建立它来实现你喜欢的任何功能,你会包括什么?
编辑:澄清.我的意图不是开始辩论,而是我正在考虑实施一个最小的LISP,我想要了解我可以去的最小化,同时仍然允许我实施的语言是图灵完整等等.如果这证明是有争议的我我相信我会从观察争议中学到我想学到的东西.:).谢谢!
本网站提出以下声明:http: //hyperpolyglot.wikidot.com/lisp#ten-primitives
McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, these are the only functions which need to be implemented in a lower language. The way the non-primitives of lisp can be constructed from primitives is analogous to the way theorems can be proven from axioms in mathematics. …
是否可以在不使用add1等语言原语的情况下将教堂数字转换为整数表示?
我遇到的所有例子都使用了一个原语来降级到int
例:
plus1 = lambda x: x + 1
church2int = lambda n: n(plus1)(0)
Run Code Online (Sandbox Code Playgroud)
例2:
(define (church-numeral->int cn)
((cn add1) 0))
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用微型lisp内部解释器(仅使用John McCarthy的10条规则),并且想要了解是否可以在不添加原语的情况下完成.
我们可以看到,我们可以使用reduce/ foldl1作为我们可以定义其他更高阶函数的函数,例如map,filter和reverse.
(defn mapl [f coll]
(reduce (fn [r x] (conj r (f x)))
[] coll))
(defn filterl [pred coll]
(reduce (fn [r x] (if (pred x) (conj r x) r))
[] coll))
(defn mapcatl [f coll]
(reduce (fn [r x] (reduce conj r (f x)))
[] coll))
Run Code Online (Sandbox Code Playgroud)
我们似乎也可以这样做foldr.下面是map与filter来讲foldr,从丰富的希基的传感器说话 17:25.
(defn mapr [f coll]
(foldr (fn [x r] (cons (f x) r))
() coll))
(defn filterr [pred …Run Code Online (Sandbox Code Playgroud)