Re: Different syntax for declarations.



Ari Johnson wrote:
"Kaz Kylheku" <kkylheku@xxxxxxxxx> writes:
(define-decl-macro declarative-let
(let &var-list &body))

;;; Now use the macro

(declarative-let ((x integer 3) (y string) z)
(setf y "abc")
(push x z))

I don't have time to read your entire post, but does it allow for an
initial value without a type declaration?

Not in the way you might be thinking, but of course you can use the
type T to effectively express the same thing:

(x t 3)

means that we are giving X the initial value 3, but not committing it
to a type.

I thought about this issue, and rationalized it like this: a user of
these macros is probably interested in heavy use of declarations, where
it doesn't matter if the occasional need for an undeclared variable
with an initial value requires extra syntax.

I don't see how it can even be designed otherwise. If you just want a
simple three-element syntax where the variable name is first, it has to
be either followed by the type and then the initial value or vice
versa. To allow either orders you need some additional in-band signal
to distinguish which is which. Any such scheme is going to be at least
as syntactically complex as writing that T.

BTW, version 9 doesn't handle docstrings properly. I have a fix for
that already, but I need a better fix which will handle bodies where
the docstring is placed after declarations. e.g

(decl-defun abc ((arg integer)) integer (declare (optimize ...))
"docstring" expr ...)

The transformer should recognize and skip any initial declarations and
docstring, and generate a body which looks like

(declare (optimize ...)) "docstring" (the integer (progn expr ...))

I will also develop a way to be able to express global declaim's for
functions. An easy way would be to support the keywords
@lambda-signature and @result-type, which are references to the
&lambda-list and &result-type. Also @param-1 trough @param-9 to refer
to &param's. The @lambda-signature will expand to the argument
signature gathered from a &lambda-list, and the @result-type will play
back a type expression collected from a &resulit-type position. So with
these elements, you could write something like:

(declare-decl-macro decl-defun
(progn
(declaim (ftype (function @lambda-signature @result-type)
@param-1)
(defun &param &lambda-list &result-type &body)))

Because of the empty-structure squashing logic in the expander,
decl-defun would still end up as a macro having the signature

(defmacro decl-defun <sym> (&rest <lambda-list>) <type> &body <body>)

in spite of the wrapping progn and declaim material.

.