符号表和namespace的理解与疑惑


#21

你说的对,这里我打错了。

flet的实现类似于

(cl-letf (((symbol-function 'a)
           (lambda (x) (+ 1 x))))
  (a 3))

#22

噢,我以前不了解 fletcl-flet 的这个区别,所以说老 flet 默认就会污染全局的函数定义(虽然常常这是故意的),怪不得新 cl-flet 改了。


#23

问个入门问题,ELISP下如何回车改到下一行,直接回车就执行了


#24

M-j紫薯布丁


indent-new-comment-line is a function alias for
comment-indent-new-line, defined in newcomment.el.gz.

Signature
(indent-new-comment-line &optional SOFT)

Documentation
Break line at point and indent, continuing comment if within one.

This indents the body of the continued comment
under the previous comment line.

This command is intended for styles where you write a comment per line,
starting a new comment (and terminating it if necessary) on each line.
If you want to continue one comment across several lines, use M-x newline-and-indent.

If a fill column is specified, it overrides the use of the comment column
or comment indentation.

The inserted newline is marked hard if variable use-hard-newlines is true,
unless optional argument SOFT is non-nil.

#25
(cl-flet ((a (x) (1+ x)))
     (apply #'a '(3)))

这段代码,若让我来写,会是下面的样子。cl-flet的目的是为了简化下面的写法?

(let ((a (lambda (x) (1+ x))))
  (apply a '(3)))

#26
ELISP> (cl-flet ((plus (&rest numbers)
                       (apply #'+ numbers)))
         (plus 3 4 5 6 7))

cl-flet定义的函数在flet块内可以当作一般函数调用。

所以一般用来遮盖全局函数的定义。用let就没法遮盖按正常方式调用的函数定义了。


抱歉,关闭了词法作用域才能遮蔽

等我研究一下

是没法覆盖的,因为cl-flet设置的是symbol的value slot。如你所说,是(let ((a (lambda (x) ...))))的语法糖。

突然降智了


#27
(defun a (x) (* 2 x))
(a 4)   ;; => 8
(let ((a (lambda (x) (1+ x))))
  (message (int-to-string (a 4))) ;; => 8 没覆盖
  (apply a '(3)))  ;; => 4

(cl-flet ((a (x) (1+ x)))
  (message (int-to-string (a 4))) ;; => 5 覆盖
  (apply #'a '(3)))  ;; => 4

#28

你这样用lambda和let写的函数要用funcall或者apply调用。正常调用函数都用(func ...)