Commits

seanmcl committed d52d735 Merge
  • Participants
  • Parent commits c2b5bc8, 9a14916

Comments (0)

Files changed (1)

File elisp-for-ocaml-programmers.el

 ;; Lexical defun and let
 
 (defmacro defunl (name arglist &rest body)
-  "Lexical defun"
+  "Lexical defun.  Not for use with interactive functions"
   (declare (indent defun))
-  (let* ((args (remove-if (lambda (s) (equal (substring (symbol-name s) 0 1) "&")) arglist))
-         (args (mapcar (lambda (arg) (list arg arg)) args)))
-  `(defun ,name ,arglist
-     (lexical-let 
-         ,args
-       ,@body))))
+  (let* (;; remove &optional and &rest
+         (args (remove-if 
+                (lambda (s) (equal (substring (symbol-name s) 0 1) "&")) 
+                arglist))
+         (args (mapcar (lambda (arg) (list arg arg)) args))
+         ;; put the doc string before the lexical-let
+         (doc_body (if (and (> (length body) 1) 
+                            (stringp (car body)))
+                       `(,(car body) . ,(cdr body))
+                     `(nil . ,body)))
+         (doc (car doc_body))
+         (body (cdr doc_body)))
+    `(defun ,name ,arglist
+       ,(if doc doc)
+       (lexical-let 
+           ,args
+         ,@body))))
 ;; (macroexpand '(defunl f (x y) (+ x y)))
+;; (macroexpand '(defunl f (x y) "abc" (+ x y)))
 
 (def-edebug-spec defunl
   (&define name lambda-list