tags:

views:

67

answers:

3

I wrote a Lisp function earlier that had an error. The first challenge was to figure out how to view the function again. That challenge is solved. Now that I see WHAT I have done wrong, I want to modify the contents of the defined function without rewriting the whole thing?

Seems like as intelligent as Lisp is, there HAS to be a way to do this, I just don't know what it is because I am fairly new to the language. Can this be done?

A: 

There is the advice functionality in many Lisps, which lets you run additional code before or after or around an existing function. But the comment is right, why wouldn't you rewrite a function if you're still learning and trying things out? Do they charge you by the compile cycle?

Kilian Foth
+2  A: 

Judging from the question, I think that you have a strange setup. It seems to indicate that you are writing your functions directly at the REPL. Don't do that.

The usual setup is to have an IDE (for example, Emacs with Slime) where you edit a source file, and then "send" top-level forms (like function definitions) to the REPL.

Svante
Yep. To add to this you can then edit it in place and resend it, rather than having to rewrite the whole thing from scratch. Use the REPL only for stuff you won't need again.
T Duncan Smith
exactly... im an idiot! (or at least i feel like one :), perhaps we'll just call it 'beginner' instead... haha). def a face/palm moment. thanks anyways for the quick help.
Toddeman
+2  A: 

Every useful REPL has a history functionality. It allows you to move in the history of your input backwards and forwards.

When I write code in the REPL simple keystrokes like m-p gets back earlier code. Some IDEs might even be able to locate source code in a Lisp listener with m-. .

In most REPLS you can also search incrementally backwards.

If you want a log of your input use the function DRIBBLE..

There are some more options, like retrieving the code from the function - when a Lisp IDE supports that.

Rainer Joswig