基本上,我什么时候应该使用Emacs Lisp的function程序?我还没有发现其中有行为上的差异,如果你函数作为参数传递的任何实例'like-this或#'like-this.事实上,如果我评估(eq 'goto-char #'goto-char)它返回t.
我遇到的Emacs Lisp代码很少使用function/ #'; 作者只是quote/ '一切.
例:(add-hook 'emacs-lisp-hook 'turn-on-eldoc-mode)
但是,我可以找到一些反例.这是Emacs 24.3源代码中的一个electric.el:
(add-hook 'post-self-insert-hook
#'electric-indent-post-self-insert-function
'append)
Run Code Online (Sandbox Code Playgroud)
(do-something '(lambda … (do-something (lambda …'和#',只要我使用一个版本的Emacs超过最近X?我正在寻找类似于select-keys的东西:
(desired-fn {:a 1, :b 2, :c 3, :d 4} [:a :d])
;= [1 4]
;; N.B. the order of the keys in the argument seq is preserved
(= (desired-fn (array-map :a 1, :b 2, :c 3, :d 4)
[:b :c])
(desired-fn (array-map :d 4, :c 3, :a 1, :b 2)
[:b :c]))
;= true
Run Code Online (Sandbox Code Playgroud)
虽然我还没有想出一个好名字,但实施起来并不是特别难:
(defn select-values-corresponding-to-keys [m ks]
(for [k ks]
(get m k)))
Run Code Online (Sandbox Code Playgroud)
我不知道满足这种需求的标准功能吗?如果没有,其他语言-eg,Python,Ruby,Haskell-是否有此功能的名称?
我的Emacs设置中有几行:
;; swap defaults
(define-key prog-mode-map (kbd "RET") 'newline-and-indent)
(define-key prog-mode-map (kbd "C-j") 'newline)
Run Code Online (Sandbox Code Playgroud)
这在我尝试的其他编程模式中可以正常工作.但在Emacs Lisp模式下,RET仍然受到约束newline并C-j仍然受到约束newline-and-indent.即使在将键绑定代码移动到我的Emacs初始化的最开始之后,我仍然观察到这种令人困惑的行为.如果我为Emacs Lisp的模式创建单独的键绑定语句,我没有任何问题.
;; swap defaults for most programming modes
(define-key prog-mode-map (kbd "RET") 'newline-and-indent)
(define-key prog-mode-map (kbd "C-j") 'newline)
;; swap defaults in Emacs Lisp mode too
(define-key emacs-lisp-mode-map (kbd "RET") 'newline-and-indent)
(define-key emacs-lisp-mode-map (kbd "C-j") 'newline)
Run Code Online (Sandbox Code Playgroud)
为什么是这样?如果重要,我在OS X 10.8.3上使用Emacs 24.3.
PS我最近了解到electric-indent-mode,这可能会完成与这些键绑定非常相似的东西.然而,这个谜团仍然存在.
鉴于随后的代码片段,example-func-A和之间有什么有意义的区别example-func-B吗?
#lang racket/base
(require (only-in racket/function curry))
(define (((example-func-A x) y) z)
(+ x y z))
(define example-func-B
(curry
(lambda (x y z)
(+ x y z))))
Run Code Online (Sandbox Code Playgroud)