6

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?

1
  • i think i see my misunderstanding. i am only coding in the REPL now. so my question was more along the lines of this (just and example): if i have (defun add-something (x) (+ x 5)) and i wanted to change it to (+ x 9) is there any easy way to do that without RETYPING everything (bc in my case the function is MUCH longer)? i think my ANSWER is to write my code in a FILE instead of the REPL and just do (load-file) or something. Commented Jul 27, 2010 at 13:42

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
3

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.

3 Comments

I am intrigued by your words, "like retrieving the code from the function - when a Lisp IDE supports that." I am sure Lisp Machines were allowing that. Is there any current Lisp implementations with that feature?
@gsl: see the Common Lisp standard function function-lambda-expression .
Wow, I have been searching for such functionality for so long. Even thinking of adding it with defadvice (LispWorks). And it was there all along. This is wonderful. I tested it with a moderately complex function, and it works beautifully. Interestingly, SBCL returns the code, T and name of function, while LispWorks returns code, NIL instead of T, and name of function. Thank you so much, this made my day.
1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.