Discussion:
[Q] naming convention
Didier Verna
2012-04-04 18:56:16 UTC
Permalink
Content preview: 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... [...]

Content analysis details: (-100.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no
trust
[212.27.42.10 listed in list.dnswl.org]
-100 USER_IN_WHITELIST From: address is in the user's white-list
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/622>


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
Josh Marchán
2012-04-04 19:24:04 UTC
Permalink
Post by Didier Verna
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.
--
Josh Marchán
Pascal J. Bourguignon
2012-04-05 00:15:16 UTC
Permalink
Post by Didier Verna
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 {}.
Pascal Costanza
2012-04-05 05:45:24 UTC
Permalink
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
Post by Pascal J. Bourguignon
Post by Didier Verna
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
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro
Didier Verna
2012-04-05 08:10:34 UTC
Permalink
Content preview: 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...
[...]

Content analysis details: (-100.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no
trust
[212.27.42.1 listed in list.dnswl.org]
-100 USER_IN_WHITELIST From: address is in the user's white-list
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/627>
Post by Pascal Costanza
...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).
--
Resistance is futile. You will be jazzimilated.

Scientific site: http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com
Nikodemus Siivola
2012-04-05 08:35:05 UTC
Permalink
Post by Pascal Costanza
(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
Jean-Philippe Paradis
2012-04-05 13:37:28 UTC
Permalink
Content preview: 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". [...]

Content analysis details: (-0.7 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[209.85.210.54 listed in list.dnswl.org]
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(hexstream[at]gmail.com)
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/632>

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)))))
Nikodemus Siivola
2012-04-05 14:55:44 UTC
Permalink
Post by Jean-Philippe Paradis
"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

Marco Antoniotti
2012-04-05 04:41:54 UTC
Permalink
Content preview: Isn't this a job for DEFINE-COMPILER-MACRO? MA On Apr 4, 2012,
at 20:56 , Didier Verna wrote: [...]

Content analysis details: (-0.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay
domain
-0.0 SPF_PASS SPF: sender matches SPF record
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/625>

Isn't this a job for DEFINE-COMPILER-MACRO?

MA
Post by Didier Verna
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
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.
Didier Verna
2012-04-05 08:23:38 UTC
Permalink
Content preview: 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. [...]

Content analysis details: (-100.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no
trust
[212.27.42.1 listed in list.dnswl.org]
-100 USER_IN_WHITELIST From: address is in the user's white-list
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/628>


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...
--
Resistance is futile. You will be jazzimilated.

Scientific site: http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com
Vsevolod Dyomkin
2012-04-05 08:32:26 UTC
Permalink
Maybe, something like:
FROB - for function
COMPILE-FROB - for macro
Post by Didier Verna
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
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/pro
Continue reading on narkive:
Loading...