Hello,
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
Thanks.
On Wed, Apr 04, 2012 at 08:56:16PM +0200, Didier Verna wrote:
Hello,
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
Thanks.
In CLOS/MOP, there's ensure-generic-function/defgeneric and ensure-class/defclass, for example. If the definitions are global, that's my preferred convention, too.
Didier Verna didier@lrde.epita.fr writes:
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
DEF or DEFINE- and MAKE- are used in CL (eg. DEFPACKAGE and MAKE-PACKAGE).
If the macros are just a wrapping of the functions for compilation-time invocation, their names may vary only by one *.
For example in my HTML generator package, the element macros are named after the tag, and the element functions after the tag*.
(defun p* (…) …) (defmacro p (…) (p* …)
In this case, I assume clients of the package will use the macro in general (p compilation-time-data) but they may also need to call the function at run-time (mapcar (function p*) …) or just (p* run-time-data).
For a single functionality, DEFINE-FROB and MAKE-FROM sound good.
Hi,
Here is another example. When I present macros to non-Lispers, the while loop macro seems to work best. I first introduce a functional version:
(defun while (predicate body) (when (funcall predicate) (funcall body) (while predicate body)))
...and then I show the macro that expands into this:
(defmacro while* (predicate &rest body) '(while (lambda () ,predicate) (lambda () ,@body)))
...except I would like to use the name 'while for the macro, and some other name for the function (while/f, or so). Any suggestions? Everything I can come up with is kind of ugly...
Pascal
Sent from my iPad
On 5 Apr 2012, at 02:15, "Pascal J. Bourguignon" pjb@informatimago.com wrote:
Didier Verna didier@lrde.epita.fr writes:
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
DEF or DEFINE- and MAKE- are used in CL (eg. DEFPACKAGE and MAKE-PACKAGE).
If the macros are just a wrapping of the functions for compilation-time invocation, their names may vary only by one *.
For example in my HTML generator package, the element macros are named after the tag, and the element functions after the tag*.
(defun p* (…) …) (defmacro p (…) (p* …)
In this case, I assume clients of the package will use the macro in general (p compilation-time-data) but they may also need to call the function at run-time (mapcar (function p*) …) or just (p* run-time-data).
For a single functionality, DEFINE-FROB and MAKE-FROM sound good.
-- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.
pro mailing list pro@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro
Pascal Costanza wrote:
...except I would like to use the name 'while for the macro, and some other name for the function (while/f, or so). Any suggestions? Everything I can come up with is kind of ugly...
Exactly. There's the Other Pascal (tm)'s suggestion to use a star, which I thought of as well (except that I'm using that convention for something else). DEF(INE)? vs. MAKE doesn't work because I'm not doing any kind of instantiation. I also thought of FROBF vs. FROBM but a trailing F doesn't get the same historical meaning as in e.g. printf. I could also use FFROB / MFROB, FROB / DO-FROB, or hell, COMPILE-TIME-FROB / RUN-TIME-FROB, but yuck :-/
Maybe I'll retract my current use of * and follow PB's idea. Or maybe I'll finally move back to compiler macros (see next message).
On 5 April 2012 08:45, Pascal Costanza pc@p-cos.net wrote:
(defun while (predicate body)
(defmacro while* (predicate &rest body)
...except I would like to use the name 'while for the macro, and some other name for the function (while/f, or so). Any suggestions? Everything
How about CALL-WHILE?
Cheers,
-- Nikodemus
How about something like this?
This may neither be suitable in the context of teaching newbies nor appeal to your sense of aesthetics, however I like this general approach as a way of cleanly (?) "overlaying" a new family of operators on top of already established symbols as an alternative to "let's shadow 100 symbols and have tons of package conflicts later" and "let's 'duplicate' 100 symbols by adopting some naming convention based on the original names".
(Also pasted to http://paste.lisp.org/display/128782 for formatting and future reference.)
(in-package #:cl-user)
(defvar *functionals* (make-hash-table :test 'eq))
(defun find-functional (name &key (errorp t)) (or (gethash name *functionals*) (when errorp (error "There is no functional named ~S." name))))
(defun (setf find-functional) (new name &key (errorp t)) (declare (ignore errorp)) (setf (gethash name *functionals*) new))
(defmacro functional (operator-or-form) (etypecase operator-or-form (symbol `(find-functional ',operator-or-form)) (cons `(funcall (functional ,(car operator-or-form)) ,@(cdr operator-or-form)))))
(defmacro define-functional (name args &body body) `(setf (find-functional ',name) (lambda ,args ,@body)))
(define-functional while (predicate body) (when (funcall predicate) (funcall body) (functional (while predicate body))))
(defmacro while (predicate &body body) `(functional (while (lambda () ,predicate) (lambda () ,@body))))
;;; And then:
(let ((counter 0)) (while (< counter 3) (print (incf counter)))) == (let ((counter 0)) (functional (while (lambda () (< counter 3)) (lambda () (print (incf counter)))))) == (let ((counter 0)) (funcall (functional while) (lambda () (< counter 3)) (lambda () (print (incf counter))))) == (let ((counter 0)) (funcall (find-functional 'while) (lambda () (< counter 3)) (lambda () (print (incf counter)))))
On 5 April 2012 16:37, Jean-Philippe Paradis hexstream@gmail.com wrote:
"let's shadow 100 symbols and have tons of package conflicts later"
Packages that shadow symbols are generally not meant to be (indiscriminately or at all) USE-PACKAGED.
Cheers,
-- Nikodemus
Isn't this a job for DEFINE-COMPILER-MACRO?
MA
On Apr 4, 2012, at 20:56 , Didier Verna wrote:
Hello,
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
Thanks.
-- Resistance is futile. You will be jazzimilated.
Scientific site: http://www.lrde.epita.fr/~didier Music (Jazz) site: http://www.didierverna.com
pro mailing list pro@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro
-- Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01 DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY
Please note that I am not checking my Spam-box anymore. Please do not forward this email without asking me first.
About the use of compiler macros that you and Scott suggested, I originally refrained from using them because I wanted the user to choose explicitely between the run-time and compile-time version, and also because the standard does not mandate the use of compiler macros even when they are defined.
But now that I've given it more thought, I may actually change my mind...
1/ Amongst the the current major implementations, are there any that would *not* use my compiler macro ?
2/ Assuming that the answer to 1/ is "no", something that I hadn't realized before is that I could provide the user with a compile-time option specifying whether to use the compiler macro version. The macro could then test this option and simly decline to expand by returning the original form.
This might actually be the best way to go...
Maybe, something like: FROB - for function COMPILE-FROB - for macro
On Wed, Apr 4, 2012 at 9:56 PM, Didier Verna didier@lrde.epita.fr wrote:
Hello,
I have a FROB functionality that I would like to make available both at run-time via a function and at compile-time via a macro (which in turn will call the function).
Are there any general conventions (apart from DEFINE- / MAKE-) for this kind of thing ? I'm having a hard time finding nice names for FROB the function and FROB the macro...
Thanks.
-- Resistance is futile. You will be jazzimilated.
Scientific site: http://www.lrde.epita.fr/~didier Music (Jazz) site: http://www.didierverna.com
pro mailing list pro@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro