Page 2 of 2

Re: How to turn function into a list?

PostPosted: Tue Oct 07, 2008 3:35 pm
by etlerant
methusala wrote:Since I'm somewhat rambling on about my idealized development environment, I may as well add that it seems to me that Lisp should have some kind of built in replacement for SQL also. Having this would get rid of another time waster in web app development, having to switch back and forth to the mysql command line.


I'd say that for a lot of projects SQL is a tad overkill (people commonly use what they know). Consider having a look at and; persistence libraries. They're both relatively easy to use (elephant has quite a few dependencies though; rucksack is written in mostly portable CL). And they're both relatively fast. They don't, however, come with any pre-built GUI's or fancy command-line tools (that I know of).

My two cents.

Re: How to turn function into a list?

PostPosted: Fri Oct 10, 2008 6:34 am
by implausibleusername
methusala wrote:Hello,
My nick is Methusala and I am a recovering Javaholic.

I would like to be able to turn a function into a list at the repl, so I can experiment with meta programming in the REPL. I know how to use a list like a function:

CL-USER> (setf g '(+ 2 2))
(+ 2 2)
(+ 2 2)
CL-USER> (eval g)

But how do you use a function like a list?

No one actually answered your question,as you are probably asking how to do the wrong thing.
However, if you happen to be right about what you want to do, it is possible in portable common lisp.

You just have to create an alternative to defun that stores code as well as defining it, and use that instead.

Code: Select all
(let ((functions (make-hash-table)))
   (defmacro redef (fn args &rest body)
      (setf (gethash fn functions) (cons args body))
      `(defun ,fn ,args ,@body))       
   (defun def (fn)
    `(defun ,fn ,@(gethash fn functions))))
* (redef plus (a b) (+ a b))

* (plus 1 2)

* (def 'plus)

(DEFUN PLUS (A B) (+ A B))
 * (fourth (def 'plus))

(+ A B)

Remember to rerun redef with the edited code to compile it again (You'd probably need to use eval :twisted: ).