[slime-devel] defining LISP functions in Emacs

Joe Corneli jcorneli at planetmath.org
Wed Jun 20 06:30:11 UTC 2007


I am trying to continue on the quest I described before --

 "I want to create a variant of `defun' that takes arguments from
 Emacs and assembles a body to be evaluated by SLIME."

I think I am most of the way there.

Dan McCarthy pointed out:

   You probably want to quote the argument to slime-eval; that error is b/c the
   (progn...) is being evaluated in Emacs, not CL.

Oops -- yes that I should be sure SLIME is doing the evalution, not
Emacs -- but note, I also need to make sure that in the data I am
sending to SLIME contains the values of the arguments, not just their
names!

Here is a macro that accomplishes this:

(defmacro lefun (name arglist &rest body)
  `(defun ,name ,arglist 
     (slime-eval (list (append (list 'lambda ',arglist) ',body) , at arglist))))

Unfortunately, it still produces an error when I test it with the
following code:

(lefun myplus (a b) (+ a b))
(myplus 2 3)

Specifically, the above triggers SLDB with the following message:

Execution of a form compiled with errors.
Form:
  ((LAMBDA (A B) (+ A B)) 2 3)
Compile-time error:
  illegal function call

I do not know what this means.

It seems there is a work-around using Vladimir's suggestion on how
to interact programmatically with the REPL:

(defmacro lefun (name arglist &rest body)
  `(defun ,name ,arglist 
     (setq argument-values (list ))
     (second
      (slime-eval
       (list 'swank:eval-and-grab-output
	     (format "%S" 
		     (list (append (list 'lambda ',arglist) ',body)
			   , at arglist)))))))
Testing:

(lefun current-package ()
       *package*)

(current-package)

(lefun elephant-toy ()
  (elephant::open-store '(:bdb "/home/joe/musndb"))
  (elephant::add-to-root "foo" 2)
  (elephant::close-store))

(elephant-toy)

In conclusion, I seem to have tentatively solved the problem --
but I would appreciate it if someone could explain why I am
seeing the error mentioned above!



More information about the slime-devel mailing list