我正在写一个Lisp程序,并试图对类型有点认真.我想有性能改进,但我更感兴趣的是使用类型注释来提高文档和安全性.问题是nil.到目前为止我遇到了两个问题.
图表A:
>(defmethod foo ((bar bar-class) (quux quux-class))
...)
>(foo (make-instance 'bar-class) nil)
ERROR: No applicable method, etcetera etcetera, because nil is not of type quux-class
Run Code Online (Sandbox Code Playgroud)
图表B:
(defmethod initialize-instance :after ((f foo) &rest args)
"Initialize the grid to be the right size, based on the height and width of the foo."
(declare (ignorable args))
(setf (slot-value f 'grid) (make-array (list (width f) (height f))
:element-type 'foo-component
:adjustable nil
:initial-element nil)))
style-warning:
NIL is not a FOO-COMPONENT.
Run Code Online (Sandbox Code Playgroud)
这里的最佳做法是什么?到目前为止,我所拥有的唯一具有远程洞察力的想法是使用空对象模式 …
这是代码:
(defun my-random (max &optional least)
(setf max (+ max 1))
(if (null least)
(random max)
(if (numberp least)
(if (numberp max)
(let ((x (random (- max least))))
(+ x least))
(format t "~%?my-random???????: ????????????!~%"))
(format t "~%?my-random???????: ????????????!~%"))))
Run Code Online (Sandbox Code Playgroud)
;我的随机100 1
(defun prozentual (probability command)
(if (numberp probability)
(if (listp command)
(if (> 101 probability)
(if (> probability (my-random 101 1))
command)
(format t "~%?prozentual???????: ??????100!~%))
(format t "~%?prozentual???????: ???????????!~%))
(format t "~%?prozentual???????: ???????????!~%)))
Run Code Online (Sandbox Code Playgroud)
; prozentual 100(格式为"as")
This is the …Run Code Online (Sandbox Code Playgroud) 我无法找到时间复杂度分析cdr.它是在恒定时间还是线性时间运行?如果答案取决于lisp的实现,假设我使用的是Racket.
我试图将一个简单的替换方法作为一个新的Lisp用户,但无法理解为什么这不能正常工作.
;replace element e1 with element e2 in a list L
(defun my-replace (e1 e2 L)
(cond
;if the first of L is e1, cons e2 & rest L
((equal (car L) (e1)) (cons (e2) (my-replace (e1 e2 (cdr L)))))
;else cons e1 & rest L
(t (cons (e1) (my-replace (e1 e2 (cdr L)))))))
Run Code Online (Sandbox Code Playgroud) 如何package-list-package在Emacs中查看键绑定?我知道只能通过Enter打开一个程序包,然后输入Install文本进行安装。
我想在.dir-locals.el中定义一些变量,然后在python-mode-hook中添加一个钩子,在该钩子中,我想读取.dir-locals中定义的变量。问题是在加载.dir-locals.el之前调用了模式挂钩
有什么想法可以交换加载顺序吗?
我想知道如何将键用作其他键的前缀和命令本身。
我可以key-chord.el通过将琴弦和第一个琴键后面的命令绑定在一起来进行排序,但是它有几个问题
一些软件包(例如easy-kill和)expand-region支持此功能,但是它们具有复杂的代码库,而我的Lisp技能也不是很出色。
我将如何做到这一点?我真的很想<menu>被绑定evil-ex,但是我也想绑定<menu>为所有将标记设置为无弦的动作(如箭头键)的前缀cua-selection-mode。
由于evil-ex后面没有动作,也没有动作自我插入,所以这将是一个完美的用例。<menu>之所以完美,是因为它就在箭头键和其他运动键(例如,结束,主页等)的旁边,并且未经修改。
我经常遇到这样的代码块:
enum class MyEnum {
first = 1,
second_really_long_line = 2,
third = 3
};
Run Code Online (Sandbox Code Playgroud)
我希望看起来像这样:
enum class MyEnum {
first = 1,
second_really_long_line = 2,
third = 3
};
Run Code Online (Sandbox Code Playgroud)
在emacs中,有没有办法让我可以=在同一列中获取所有内容enum?
我使用以下代码片段在Emacs启动时设置主题.
(load-theme 'sanityinc-tomorrow-eighties)
Run Code Online (Sandbox Code Playgroud)
但是它还要求我确认这将加载一些lisp代码,我该如何关闭此确认?
有没有办法告诉Emacs在打开文件时自动滚动到文件的末尾?
请注意,我不需要为每个文件使用此文件,仅针对其中一些文件.理想情况下,我希望能够为特定类型/模式下的所有文件设置此行为.M-x end-of-buffer打开文件后每次打字都会有点烦人.