On 16/05/2011 13:53, Joerg Schuelke wrote:
Am Mon, 16 May 2011 11:11:39 +0100
schrieb Martin<f...@mfriebe.de>:

2) But a macro also weakens the fundamental concept of how a language
is defined. A macro allows you do define a new syntax. To create
something, ...
I do prefer not to make it possible to extend the language, thats why
the explicit syntax:
   {$Macro mac(params)}  and
   {$Expand mac(params)}
I think that completely encapsulates the text manipulation from the
   language level.fo/fpc-devel

It still allows to do thinks one shouldn't do. It already does today.

Macros can contain structural elements such as begin/end. Therefore a macro can be used to change the fundamental structure of a language (never mind if you see, that it is a macro or not)
The example at the end of my mail does compile (fpc trunc).

Yes you will say, no one should or ever would do that. But the think is: people might (and people do thinks you and I would never dream of)

Even simple tasks like translating "begin" to "anfang" are evil enough.

But with params you could change language structure, in ways that actually are tempting
something like
  {$MyProc (Name) := procedure %Name%; begin}
and then code like:
  MyProc(Foo) writeln(1); end;
or if you want (no better)
  {$Expand MyProc(Foo)} writeln(1); end;

And the argument "it shouldn't be used for thinks like this" is no good. Trust me it will.


Example that works with todays fpc already (NEVER do this):

program Project1;
{$mode objfpc}{$H+}
{$MACRO ON}
{$define X := end; function foo: integer; begin}

procedure bar;
begin
  X;
end;

begin
  writeln(foo);
end.



_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to