Define macro alias?

Discussion of Common Lisp

Define macro alias?

Postby G-Brain » Wed Aug 06, 2008 5:49 am

I just switched my terminal to UTF-8 and got UTF-8 working in emacs and slime with SBCL. Now I want to write some funny lisp. I want λ to be interpreted as lambda, like an alias or something. I already figured out how to "alias" functions:

Code: Select all
(setf (symbol-function 'add) #'+)

or
Code: Select all
(setf (symbol-function 'add) (symbol-function '+))


I know that just redefines the function under a new name, but that's fine by me.

Now, I'd like to do the same thing for macros. Any ideas?
G-Brain
 
Posts: 16
Joined: Sat Jun 28, 2008 3:48 am

Re: Define macro alias?

Postby qbg » Wed Aug 06, 2008 8:14 am

Why not something like
Code: Select all
(defmacro <name> ((&body lambda-list) &body body)
  `(lambda ,lambda-list ,@body))
qbg
 
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: Define macro alias?

Postby Geoff Wozniak » Sat Aug 09, 2008 10:12 am

It sounds like you want to be able to write something like

Code: Select all
(<-> 45 my-list)


where "<->" is some funky character, instead of

Code: Select all
(push 45 my-list)


Is that correct? If so, you can just define another macro or transfer the macro function.

Code: Select all
;; Wrapper macro which may provide nicer contextual help in something like SLIME
(defmacro <-> (value place) `(push ,value ,place))

;; Transfer the macro function, analogous to your previous work with symbol-function
(setf (macro-function '<->) (macro-function 'push))


In the latter case, you should make sure there is no symbol-function defined for the symbol. You can't have a symbol name both a symbol and a function.
Geoff Wozniak
 
Posts: 9
Joined: Wed Jul 16, 2008 5:38 pm
Location: Canada

Re: Define macro alias?

Postby G-Brain » Sat Aug 09, 2008 10:23 am

Perfect! Thank you Geoff.

I actually tried that last method, but I suppose I already setf'd that funky character to a function before, so I couldn't setf it to a macro.
G-Brain
 
Posts: 16
Joined: Sat Jun 28, 2008 3:48 am

Re: Define macro alias?

Postby nuntius » Sat Aug 09, 2008 10:48 am

If you just want a nice display, emacs provides a few solutions. e.g. http://www.emacswiki.org/cgi-bin/wiki/PrettyLambda
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 2 guests