1

I would like to set aliases in common lisp(clisp to be exact) for commands that are used a lot, such as "defun" and "lambda" etc, is it possible to do this?

This is actually kind of a duplicate of this question, but I can not comment and the solution does not work for defun or lambda in both sbcl and clisp

2 Answers 2

8

Macros:

CL-USER 5 > (setf (macro-function 'dm) (macro-function 'defmethod)) #<Function DEFMETHOD 410009A014> CL-USER 6 > (dm m1+ ((v vector)) (map 'vector #'1+ v)) #<STANDARD-METHOD M1+ NIL (VECTOR) 4130003913> CL-USER 7 > (m1+ #(1 2 3 4)) #(2 3 4 5) 
Sign up to request clarification or add additional context in comments.

Comments

3

The whole point by macros is to provide a source rewriting service.. Thus I want to give you this and you can make that out of it:

(defmacro df (name (&rest arguments) &body body) `(defun ,name ,arguments ,@body)) (df test (x) (+ x x)) (test 5) ; ==> 10 

We have just shortened the name.. Lets make another one:

(defmacro df1 (name &body body) `(defun ,name (_) ,@body)) (df1 test (+ _ _)) (test 5) ; ==> 10 

And so on...

4 Comments

The use of : alone is undefined according to the standard. It seems ABCL, CLisp and ECL accept it as a symbol which name is ""; ACL, CCL, LW and SBCL don't accept that syntax.
@acelent It makes sense that : is special in CL. I've chosen something else.
This is a bit more complicated than I was looking for, as I am still to understand the terminology and macros in general. Any idea how this would translate to (a dialect of ) scheme?
@DiiP A macro is like a function that takes unevaluated code as arguments. (df1 test (+ _ _)) first calls the macro function with name as the symbol test and body as the list ((+ _ _)) the macro function then produces the data structure (defun test (_) (+ _ _)) and that is the actual code that Common Lisp gets to evaluate. Scheme macros, except syntax-rules, are a bit more complex.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.