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.

.



Relevant Pages

  • Re: Noob to C++, trying to get syntax, etc.
    ... Declarations and definitions aren't too much different from what they ... > WorldGreeter ... > The console stream object, cout, passes into greetby reference. ... Here's a macro, using some of those stream things: ...
    (comp.lang.cpp)
  • Re: Declarations variables, Dim, some guidance please
    ... Back when I was starting with VBE it seemed that double declarations ... >> the macro I was testing. ... >> NOT get a duplicate Dim error? ... The first was a module scope variable, ...
    (microsoft.public.excel.programming)
  • Re: Declarations variables, Dim, some guidance please
    ... The pros and the cons are the same things really, ... placing in Declarations or a procedure. ... > the macro I was testing. ... The first was a module scope variable, ...
    (microsoft.public.excel.programming)
  • Re: Defining structures in METAPOST
    ... I am trying to write a METAPOST macro achieving the following effect: ...    dancingsquare; ... are computed after the coordinates of the pair square0 and the ... After these declarations, I can write: ...
    (comp.text.tex)
  • Re: Can I use a docstring followed by DECLARE in a local function?
    ... Is there an easy way to grab the docstring and declarations from a list ... PARSE-BODY of Alexandria. ...
    (comp.lang.lisp)