Search notes:

Macro languages

A macro is a program that writes programs (or pieces of programs).
A macro language is also referred to as metaprogramming because they're able to tread code fragments as data.

Ideas, concepts, etc

SAS

SAS distinguishes between statements that are executed at compile time and at execution time.

M5

In the User's Guide to the MS Macro Language, Alan Dain Samples lays out a few features and concepts that he implemented in M5, such as
  • Recursvie macros should be easy to read and write
  • Named parameters
  • Unbounded number of parameters
  • Namespaces (he calls the «pools») to make it easier to create context sensitive macros
  • Scopes
  • Easily debuggable
In M5, the order of processing is (p. 6):
  • Scanning: The input text is scanned for a macro name
  • Argument collection: Once a macro name has been recognized, if that macro was defined to accept arguments, and ifs its name is followed immediately by a left paranthesis, then the arguments are collected in scanning mode and pushed ont a stack (M5 uses positional arguments only)
  • Parameter substitution: Once all of the arguments for a macro are collected, then the body of the macro - also called the replacement text - is scanned for parameter specifications. Each parameter specification is replaced by the corresonding text from the argument stack
  • Macro expansion: the parameter specifications in the body of the macro have been replaced with the corresponding arguments from the argument stack, the resulting text is stuffed back into the input stream aand reread in scanning mode

What Built-Ins should a macro language offer

Processing text (such as SQL)

A percent sign indicates that the following identifier is the name of a macro function.
A list is constructed within curly braces.
List elements are separated by the hash symbol
The quote makes sure that the following special character (%, { and #) are not immediatly evaluated.
Everything else is «text».
select %cols{foo # bar # baz} …
How should foreach be implemented?
Nested invocation of macros:
%mac-one{ %mac-two{arg-1 # arg-2 } # arg-3 }

Read-eval-print loop (REPL)

If used in an SQL shell (such as Oracle's SQL Developer or the SQLite shell), executing SQL statements is a basic form of a read-eval-print loop. Missing is a convenient way to store the result of a select statement or even use the result within a function call.
A macro language should provide such a feature.

See also

C/C++ Preprocessor: Macros
macros

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759408079, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/macro/index(108): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78