Emacs 是否可能在相等性检查中有两个以上的值?(>;NUM1 NUM2)ELISP
函数“greaterthan”(Emacs 是否可能在相等性检查中有两个以上的值?(>;NUM1 NUM2)ELISP,emacs,lisp,elisp,Emacs,Lisp,Elisp,函数“greaterthan”((var2
(
)只允许在比较2个值时返回t/nil
我想测试一下(var1>var2
(和(
并不难读,你的。>最好的程序是不要麻烦:(和(
不难读,你的。。。(defun以下是variadic的宏实现以下是variadic的宏实现(defmacro(defmacro)我认为可以分3个步骤完成。不过,想象一下必须做几个类似的测试,例如(var1var3cl
,就没有办法做到这一点吗?添加了一个不需要cl
的变体。一般来说,没有cl
的情况下编写要困难得多,而我们正在做的是ing在这里添加了一个常见的Lispish是的,我认为它可以通过3个步骤来完成。不过,想象一下必须要做几个类似的测试,比如(var1var3cl
,就没有办法做到这一点吗?添加了一个不需要cl
的变体。一般来说,没有cl
的情况下编写要困难得多,而我们正在做的是ing在这里添加了一个公共Lispish@wvxvw:注意在公共Lisp#@wvxvw:注意在公共Lisp#中
(require 'cl)
(defun cl-< (&rest args)
(every '< args (cdr args))
(defun cl-< (arg &rest more-args)
(or (null more-args)
(and (< arg (first more-args))
(apply #'cl-< more-args))))
(defun << (arg1 arg2 arg3 arg4)
(when (and (< arg1 arg2) (< arg2 arg3) (< arg3 arg4)))
)
(<< 1 2 3 4)
(defmacro << (x y &rest args)
(if args
(if (or (symbolp y)
(numberp y))
`(and (< ,x ,y) (<< ,y ,@args))
(let ((ys (make-symbol "y")))
`(let (,ys)
(and (< ,x (setq ,ys ,y))
(<< ,ys ,@args)))))
`(< ,x ,y)))
(<< x y z) ==> (and (< x y) (< y z))
(<< (f x) (g y) (h z)) ==> (let ((gy)) (and (< (f x) (setq gy (g y)))
(< gy (h z))))
(setq foo (list))
nil
(defun call (x) (push x foo) x)
call
(<< (call 1) (call 2) (call 5) (call 4) (call 0))
nil
foo
(4 5 2 1)
(defmacro << (&rest args)
(let ((first (car args))
(min (gensym))
(max (gensym))
(forms '(t)) iterator)
(setq args (reverse (cdr args))
iterator args)
`(let ((,min ,first) ,max)
,(or
(while iterator
(push `(setq ,min ,max) forms)
(push `(< ,min ,max) forms)
(push `(setq ,max ,(car iterator)) forms)
(setq iterator (cdr iterator))) `(and ,@forms)))))
(macroexpand '(<< 10 20 30 (+ 30 3) (* 10 4)))
(let ((G99730 10) G99731)
(and (setq G99731 20)
(< G99730 G99731)
(setq G99730 G99731)
(setq G99731 30)
(< G99730 G99731)
(setq G99730 G99731)
(setq G99731 (+ 30 3))
(< G99730 G99731)
(setq G99730 G99731)
(setq G99731 (* 10 4))
(< G99730 G99731)
(setq G99730 G99731) t))