Talk:Metaprogramming

message: :The basic definition is not about functional programming. Nor is it a requirement to be able to modify itself while running.
::"It means that a program could be designed to read, generate, analyse and/or transform other programs, and even modify itself while running."
:A compiler would be an example of metaprogramming. It reads a programs source and generates an object program.
:I would note that some metacompiler metalanguages are special purpose functional programming languages.
term = factor $(('*':MPY|'/':DIV) factor!2);
:is a boolean function, calling other boolean (factor) functions, returning success or failure. Its input is the program source character stream.  On success the input advances over characters matched transforming them into an abstract syntax tree on the pares stack. The term rule calls the factor rule that also creates an abstract syntax sub-tree. I.e. 
 MPY[factor,factor]     DIV[factor,factor]  or simply a  factor
         MPY                    DIV
       /    \                 /    \
   factor  factor         factor  factor
:The term rule defines (recognizes and parses) a part of a programming language construct  building an abstract syntax tree of the language construct recognized. This, tree building, side effect is a strictly defined part of the rule.  making it more readable. "term" is part of an arithmetic. expression. The output sub-tree is pushed on the parse stack on a successful return. Above factor would be a sub-tree recognized by the factor rule. The :MPY or :DIV operations create the tree node and the ! operator builds the tree. The number following ! is the number of branches. !2 creates a two branch tree.
:The syntax rules are metaprogramming. Not because they can change them selves while running. But because they operate on a source program transforming it into something else functionally equivelvent.
Steamerandy (talk) 18:44, 12 December 2014 (UTC)
thread_title: Metalanguage metaprogramming

message: Metaprogramming is quite a subtle concept.  Sometimes it depends on the intention of the programmer rather than the form of the program. For instance, writing a program like:
:DIM Radius AS Single
:DIM Area AS Single
:PRINT "Calculating the area of a circle"
:INPUT "Enter radius of the circle: ", Radius
:LET Area = 3.141592 * Radius * Radius
:PRINT "The area of the circle is "; Area
:END
is not an example of metaprogramming when the program is fed to an interpreter.  However it is, when the program is fed to a compiler.  
Note also that other programming methods can be thought of as metaprogramming.  For instance, the genetic programming method or the automatic generation of a DB front end viewer/editor utility from the data model. --Derek Ross
:I don't understand how the above program can ever be a metaprogram.  My understanding is that a metaprogram is a program that manipulates or reasons about other programs.  The program above does not do that.  The compiler or interpreter, on the otehr hand are metaprograms.
::Is dll use Metaprogramming? is threading Metaprogramming? --Tim32 09:28, 1 November 2007 (UTC)
thread_title:  Subtleties of Metaprogramming- what is and not 

message: This is a good article, congratulations to all the authors!
One useful addition might be a history of meta-programming. I came here interested to learn when the idea first started to surface (the idea of human-oriented meta-programming that is: not the compiler itself). E.g., the C++ article states that templates were added some point after 1990 (and I'm sure C++ was not the first language to provide explicit support for meta-programming either). -- Jon Dowland 09:18, 8 September 2005 (UTC)
replies: text: Lisp is a much earlier example (sixties). --MarSch 12:46, 12 December 2006 (UTC)
thread_title:  history of meta-programming 

message: There ought to be some discussion of the Forth programming language which has native support for metaprogramming through CREATE and DOES> and other words. The functions used to build functions are generally made available to the user and it's straightforward to flag newly defined words to act as compile-time metaprograms rather than as words to be compiled. sigfpe Dec 5 2005
:Actually sense the FORTH language is made up of words in it's dictionary. Defining new words is extending the language, making a new dialect of the language, would be (I think) metaprogramming. FORTH freaks think FORTH is a metacompiler just because it compiles it's self. (creating a new instance of it's self) Totally ignoring that compiling it's self is just a self-hosting compiler. No different then a C compiler written in C. And thus if accepted would mean every self-hosted compiler would be a metacompiler. But on the other hand programming in forth is extending the language. Creating a dialect  (or derivatives) of FORTH. So in essence programming in FORTH is metaprogramming and forth would be a metaprogramming language. I would never have considered forth a metacompiler. I have gotten into a argument with the creator of the metacompiler topic because of the use of the FORTH metacompiler definition he used. I have written a very advanced metacompiler that extended CWIC adding a machine assembler defining language allowing the defining of an assembly instruction operand syntax and the expansion of instruction into bit fields. Instruction or generated into bit addressable memory sections. It was used to write a COBOL cross compiler running on a DEC-System-10 (36 bit word machine) producing code for TI-990 a (8 bit) byte addressable, 16 bit word minicomputer. So you can understand my bias as to the definition of metacompiler. Looking at FORTH in metaprogramming terms it is a specialized metalanguage compiler/interpreter that extends it's self with every new defining of a word to it's vocabulary it creates a new dialect of FORTH.--Steamerandy (talk) 18:02, 19 November 2014 (UTC)
thread_title:  Forth 

message: It seems to me that PHP, ASP, JSP, HTML::Mason, and the like, usually referred to as "Web templating systems", are a form of metaprogramming.  The programmer writes code in one language - PHP, VB, Java, Perl, and the like - that generates HTML, instead of writing the HTML directly.  You may argue that HTML is not a programming language, just a markup language.  Nevertheless, the process is largely the same.  Also, these tools can also insert JavaScript into the HTML, and that is definitely a programming language.
Note that the file they create may start with the "high-level language" at the outermost level, and escape into the markup language, or vice-versa.  These two approaches are essentially equivalent.
I'm going to think about adding something to the page that describes this common example.
:I would tend to agree with this.  Its quite often that one needs to incorporate some javascript generation in an asp.net application, and in fact if one does some research, the technique is fairly common...  But in fact I think its a touch overused.  Often you can find asp.net code that generates javascript that might be better generated as calls to specific javascript functions included in separate javascript files.  It is much easier to define the functionality you need, place the functionality behind a few functions, test said functions, and then invoke or place calls where needed.   Unless you already have a huge javascript library to use, javascript generation does not always make sense.
:These days, any javascript generated is pretty low level and hidden behind few abstractions.  But it is still generated. Root4(one) 05:24, 26 November 2006 (UTC)
thread_title:  PHP and the like 

message: I would like to suggest this article as a relevant external link.  But, well, I'm the author of it, so I fell like it would be more appropriate for someone else to actually add it (if you find it relevant) LotLE×talk 06:53, 29 June 2006 (UTC)
replies: text: other than the word "meta" this seem totally unrelated to metaprogramming. --MarSch 11:33, 1 November 2007 (UTC)
thread_title:  An external link? 

message: Shouldn't computer viruses be included in the article, as they manipulate executables to copy themselves?--Theodore Kloba (talk) 21:24, 28 April 2008 (UTC)
thread_title:  Viruses 

message: Can "Qt's meta object compiler (moc)" be added as an example of meta programming? It generates more C++ code based on the contents of a .h file. Vdboor (talk) 10:33, 17 September 2009 (UTC)
thread_title:  Metaprogramming in C++ with Qt 

message: Metacompiler have long been defined as taking a matalanguage program and translating it into a compiler.
metacompiler from the XDS 940 TREEMETA manual(1968):
:A metacompiler, in the most general sense of the term, is a program that reads a metalanguage program as input and translates that program into a set of instructions. If the input program is a complete description of a formal language, the translation is a compiler for the language.
Metacompiler definition as stated in CWIC (Compiler for Writing and Implementing Compilers) documents(1969-1985):
:A metacompiler is a program whose input is a description of the syntax of a programming language, plus a description of its semantics, i.e., or its equivalent in terms of a machine language. The language in which such a description is coded is called a metalanguage. The output of a metacompiler is a compiler for the described language. This compiler can then be used to process a program written in that language: i.e., to examine it for syntactic correctness and to translate it into a machine language or its equivalent.
Now in the metaprogramming topic we have:
:The ability of a programming language to be its own metalanguage is called reflection or reflexivity.
Now that fits a metacompiler written in it's own metalanguage compiling itself. It seams a special case of reflection equivalent to self-hosting compiler. Am I right in explaining a metacompiler compiling itself as:
:The process of a metacompiler, written in it's own metalanguage, compiling it's self is called reflection, a metaprogramming term that in this case is equivalent to self-hosting compiler.
I have been programming sense 1965 and written many commercial compilers. My computer lingo is a bit old school. Could someone here check out the metacompiler topic. I have redid it based on metaprogramming terminology (I hope).
I made an RFC because the original author defined metacompiler way to much like the FORTH definition of "Written in it's own language, compiling itself this way" making it a metacompiler. When historically some metacompilers have been written on other languages (assembly, LISP, CL/1 and PL/1) and of course did not compile themselves. When I last looked at FORTH it was not being called a metacompiler. 
--Steamerandy (talk) 22:29, 19 November 2014 (UTC)
thread_title:  Metacompiler 

message: ...is quite poor.  And it's consistent throughout the entire article, not just a few things here and there.  Unfortunately, I don't know anything about the subject, so I'm just going to tag it and run.  Deacon Vorbis (talk) 01:57, 22 January 2017 (UTC)
thread_title:  Article Quality 

message: R allows meta programming, it don't have macros and templates but it have substitute function that all to get expression being passed to function and prevent evaluation.
I think you can write macro system in that language. In R everything is evaluated in reverse order (lazy evaluation) function get expressions as arguments and only when they are used, they get evaluated. That's why you can stop evaluation, modify the code and evaluate in your own way. This is powerful meta programming were you can define whole new syntax or new operators that are not supported by the language. (this is how purrr, dplyr etc. libraries define new syntax to process data).
jcubic (talk) 14:23, 22 April 2020 (UTC)
thread_title:  [[:R (programming language)|R]] 

message: Many script languages with run-time interpretation have the ability to produce a text string containing valid code in the same language and then interpret this string and execute it. Many of the examples mentioned belong to this category. Other categories are:
* Programs that produce programs, in the same or a different programming language
* Macros
* preprocessing  — Preceding unsigned comment added by Agnerf (talk • contribs) 06:58, 15 July 2022 (UTC)
thread_title:  Script languages versus other categories of metaprogramming 

message: constexpr functions and "if constexpr" are used in C++ to explicitly specify that certain calculations and decisions are done at compile time.
An example of such compile-time calculations is the C++ Vector Class Library which is using compile-time calculations to find the optimal instruction sequence to implement a particular algorithm. 
Agnerf (talk) 06:36, 15 July 2022 (UTC)
thread_title:  Compile-time calculations in C++