用于生成编程的非C ++语言?

时间:2021-10-28 15:04:41

C++ is probably the most popular language for static metaprogramming and Java doesn't support it.

C ++可能是静态元编程最流行的语言,Java不支持它。

Are there any other languages besides C++ that support generative programming (programs that create programs)?

除了C ++之外还有其他语言支持生成编程(创建程序的程序)吗?

14 个解决方案

#1


32  

The alternative to template style meta-programming is Macro-style that you see in various Lisp implementations. I would suggest downloading Paul Graham's On Lisp and also taking a look at Clojure if you're interested in a Lisp with macros that runs on the JVM.

模板样式元编程的替代方法是在各种Lisp实现中看到的宏样式。我建议下载Paul Graham的On Lisp,如果你对使用在JVM上运行的宏的Lisp感兴趣,还可以看看Clojure。

Macros in Lisp are much more powerful than C/C++ style and constitute a language in their own right -- they are meant for meta-programming.

Lisp中的宏比C / C ++风格强大得多,并且本身构成了一种语言 - 它们用于元编程。

#2


24  

let me list a few important details about how metaprogramming works in lisp (or scheme, or slate, or pick your favorite "dynamic" language):

让我列出一些关于元编程如何在lisp(或方案,或平板,或选择你最喜欢的“动态”语言)中工作的重要细节:

  • when doing metaprogramming in lisp you don't have to deal with two languages. the meta level code is written in the same language as the object level code it generates. metaprogramming is not limited to two levels, and it's easier on the brain, too.
  • 在lisp中进行元编程时,您不必处理两种语言。元级别代码使用与其生成的对象级代码相同的语言编写。元编程不仅限于两个层次,而且在大脑上也更容易。

  • in lisp you have the compiler available at runtime. in fact the compile-time/run-time distinction feels very artificial there and is very much subject to where you place your point of view. in lisp with a mere function call you can compile functions to machine instructions that you can use from then on as first class objects; i.e. they can be unnamed functions that you can keep in a local variable, or a global hashtable, etc...
  • 在lisp中,您可以在运行时使用编译器。事实上,编译时/运行时的区别在那里感觉非常人为,并且很大程度上取决于你的观点。在lisp中只需要一个函数调用,就可以将函数编译为机器指令,然后可以将它作为第一类对象使用;即它们可以是未命名的函数,可以保存在局部变量或全局哈希表等中......

  • macros in lisp are very simple: a bunch of functions stuffed in a hashtable and given to the compiler. for each form the compiler is about to compile, it consults that hashtable. if it finds a function then calls it at compile-time with the original form, and in place of the original form it compiles the form this function returns. (modulo some non-important details) so lisp macros are basically plugins for the compiler.
  • lisp中的宏非常简单:一堆函数填充在哈希表中并提供给编译器。对于编译器即将编译的每个表单,它会查询该哈希表。如果它找到一个函数然后在编译时用原始表单调用它,并且代替原始表单,它将编译此函数返回的表单。 (模数一些非重要的细节)所以lisp宏基本上是编译器的插件。

  • writing a lisp function in lisp that evaluates lisp code is about two pages of code (this is usually called eval). in such a function you have all the power to introduce whatever new rules you want on the meta level. (making it run fast is going to take some effort though... about the same as bootstrapping a new language... :)
  • 在lisp中编写一个评估lisp代码的lisp函数大约是两页代码(通常称为eval)。在这样的功能中,您可以在元级别上引入所需的任何新规则。 (让它快速运行需要付出一些努力......就像引导一种新语言一样...... :)

random examples of what you can implement as a user library using lisp metaprogramming (these are actual examples of common lisp libraries):

使用lisp元编程实现用户库的随机示例(这些是常见lisp库的实际示例):

  • extend the language with delimited continuations (hu.dwim.delico)
  • 用分隔的连续扩展语言(hu.dwim.delico)

  • implement a js-to-lisp-rpc macro that you can use in javascript (which is generated from lisp). it expands into a mixture of js/lisp code that automatically posts (in the http request) all the referenced local variables, decodes them on the server side, runs the lisp code body on the server, and returns back the return value to the javascript side.
  • 实现一个js-to-lisp-rpc宏,你可以在javascript中使用它(从lisp生成)。它扩展为js / lisp代码的混合,自动发布(在http请求中)所有引用的局部变量,在服务器端解码它们,在服务器上运行lisp代码体,并将返回值返回给javascript侧。

  • add prolog like backtracking to the language that very seamlessly integrates with "normal" lisp code (see screamer)
  • 添加prolog就像回溯到与“普通”lisp代码无缝集成的语言(参见screamer)

  • an XML templating extension to common lisp (includes an example of reader macros that are plugins for the lisp parser)
  • 公共lisp的XML模板扩展(包括作为lisp解析器插件的读取器宏的示例)

  • a ton of small DSL's, like loop or iterate for easy looping
  • 大量的小型DSL,如循环或迭代,以便轻松循环

#3


13  

Template metaprogramming is essentially abuse of the template mechanism. What I mean is that you get basically what you'd expect from a feature that was an unplanned side-effect --- it's a mess, and (although tools are getting better) a real pain in the ass because the language doesn't support you in doing it (I should note that my experience with state-of-the-art on this is out of date, since I essentially gave up on the approach. I've not heard of any great strides made, though)

模板元编程实质上是滥用模板机制。我的意思是你基本上得到了你所期望的功能,这是一个无计划的副作用 - 它是一团糟,(尽管工具越来越好)是一个真正的痛苦,因为语言没有支持你这样做(我应该注意到,我对这方面的最新经验已经过时了,因为我基本上已经放弃了这种方法。虽然我没有听说过任何重大进展)

Messing around with this in about '98 was what drove me to look for better solutions. I could write useful systems that relied on it, but they were hellish. Poking around eventually led me to Common Lisp. Sure, the template mechanism is Turing complete, but then again so is intercal.

在大约98年左右解决这个问题是驱使我寻找更好解决方案的原因。我可以编写依赖它的有用系统,但它们是地狱般的。四处寻找最终导致我使用Common Lisp。当然,模板机制是Turing完成,但是同样是intercal。

Common Lisp does metaprogramming `right'. You have the full power of the language available while you do it, no special syntax, and because the language is very dynamic you can do more with it.

Common Lisp做元编程“正确”。你可以使用该语言的全部功能,没有特殊的语法,并且因为语言非常动态,你可以用它做更多的事情。

There are other options of course. No other language I've used does metaprogramming better than Lisp does, which is why I use it for research code. There are lots of reasons you might want to try something else though, but it's all going to be tradeoffs. You can look at Haskell/ML/OCaml etc. Lots of functional languages have something approaching the power of Lisp macros. You can find some .NET targeted stuff, but they're all pretty marginal (in terms of user base etc.). None of the big players in industrially used languages have anything like this, really.

当然还有其他选择。没有其他语言我使用的元编程比Lisp更好,这就是我将它用于研究代码的原因。你可能想要尝试别的东西有很多原因,但这都是权衡利弊。您可以查看Haskell / ML / OCaml等。许多函数式语言都具有接近Lisp宏的强大功能。你可以找到一些.NET目标的东西,但它们都非常边缘(在用户群等方面)。在工业上使用的语言中,没有一个大玩家真的有这样的东西。

#4


11  

Nemerle and Boo are my personal favorites for such things. Nemerle has a very elegant macro syntax, despite its poor documentation. Boo's documentation is excellent but its macros are a little less elegant. Both work incredibly well, however.

Nemerle和Boo是我个人最喜欢的东西。 Nemerle有一个非常优雅的宏语法,尽管它的文档很差。 Boo的文档非常好,但它的宏不太优雅。然而,两者都工作得非常好。

Both target .NET, so they can easily interoperate with C# and other .NET languages -- even Java binaries, if you use IKVM.

两者都以.NET为目标,因此如果您使用IKVM,它们可以轻松地与C#和其他.NET语言(甚至Java二进制文件)进行互操作。

Edit: To clarify, I mean macros in the Lisp sense of the word, not C's preprocessor macros. These allow definition of new syntax and heavy metaprogramming at compiletime. For instance, Nemerle ships with macros that will validate your SQL queries against your SQL server at compiletime.

编辑:澄清一下,我的意思是Lisp意义上的宏,而不是C的预处理器宏。这些允许在编译时定义新语法和繁重的元编程。例如,Nemerle附带的宏将在编译时针对您的SQL服务器验证您的SQL查询。

#5


9  

Nim is a relatively new programming language that has extensive support for static meta-programming and produces efficient (C++ like) compiled code.

Nim是一种相对较新的编程语言,它对静态元编程有广泛的支持,并产生高效的(类似C ++)编译代码。

http://nim-lang.org/

It supports compile-time function evaluation, lisp-like AST code transformations through macros, compile-time reflection, generic types that can be parametrized with arbitrary values, and term rewriting that can be used to create user-defined high-level type-aware peephole optimizations. It's even possible to execute external programs during the compilation process that can influence the code generation. As an example, consider talking to a locally running database server in order to verify that the ORM definition in your code (supplied through some DSL) matches the schema of the database.

它支持编译时功能评估,通过宏进行类似lisp的AST代码转换,编译时反射,可以使用任意值进行参数化的泛型类型,以及可用于创建用户定义的高级类型感知的术语重写窥视孔优化。甚至可以在编译过程中执行可能影响代码生成的外部程序。例如,考虑与本地运行的数据库服务器通信,以验证代码中的ORM定义(通过某些DSL提供)是否与数据库的模式匹配。

#6


6  

The "D" programming language is C++-like but has much better metaprogramming support. Here's an example of a ray-tracer written using only compile-time metaprogramming:

“D”编程语言就像C ++一样,但有更好的元编程支持。以下是仅使用编译时元编程编写的光线跟踪器示例:

Ctrace

Additionally, there is a gcc branch called "Concept GCC" that supports metaprogramming contructs that C++ doesn't (at least not yet).

此外,还有一个名为“Concept GCC”的gcc分支,它支持C ++没有的元编程结构(至少还没有)。

Concept GCC

#7


5  

Common Lisp supports programs that write programs in several different ways.

Common Lisp支持以多种不同方式编写程序的程序。

1) Program data and program "abstract syntax tree" are uniform (S-expressions!)

1)程序数据和程序“抽象语法树”是统一的(S表达式!)

2) defmacro

3) Reader macros.

3)读者宏。

4) MOP

Of these, the real mind-blower is MOP. Read "The Art of the Metaobject Protocol." It will change things for you, I promise!

其中,真正令人兴奋的是MOP。阅读“元对象协议的艺术”。我保证,这会改变你的想法!

#8


4  

I recommend Haskell. Here is a paper describing its compile-time metaprogramming capabilities.

我推荐Haskell。这是一篇描述其编译时元编程功能的论文。

#9


3  

Lots of work in Haskell: Domain Specific Languages (DSL's), Executable Specifications, Program Transformation, Partial Application, Staged Computation. Few links to get you started:

Haskell的大量工作:领域特定语言(DSL),可执行规范,程序转换,部分应用程序,分阶段计算。很少有链接可以帮助您入门:

#10


2  

The ML family of languages were designed specifically for this purpose. One of OCaml's most famous success stories is the FFTW library for high-performance FFTs that is C code generated almost entirely by an OCaml program.

ML系列语言专门为此目的而设计。 OCaml最着名的成功案例之一是用于高性能FFT的FFTW库,它是几乎完全由OCaml程序生成的C代码。

Cheers, Jon Harrop.

干杯,Jon Harrop。

#11


2  

Most people try to find a language that has "ultimate reflection" for self-inspection and something like "eval" for reifying new code. Such languages are hard to find (LISP being a prime counterexample) and they certainly aren't mainstream.

大多数人试图找到一种对自我检查具有“终极反射”的语言,以及用于实现新代码的“eval”之类的语言。这些语言很难找到(LISP是一个主要的反例),它们肯定不是主流。

But another approach is to use a set of tools that can inspect, generate, and manipulate program code. Jackpot is such a tool focused on Java. http://jackpot.netbeans.org/

但另一种方法是使用一组可以检查,生成和操作程序代码的工具。 Jackpot是一个专注于Java的工具。 http://jackpot.netbeans.org/

Our DMS software reengineering toolkit is such a tool, that works on C, C++, C#, Java, COBOL, PHP, Javascript, Ada, Verilog, VHDL and variety of other languages. (It uses production quality front ends to enable it to read all these langauges). Better, it can do this with multiple languages at the same instant. See http://www.semdesigns.com/Products/DMS/DMSToolkit.html

我们的DMS软件再造工具包就是这样一个工具,适用于C,C ++,C#,Java,COBOL,PHP,Javascript,Ada,Verilog,VHDL和各种其他语言。 (它使用生产质量前端使其能够读取所有这些语言)。更好的是,它可以在同一时刻使用多种语言。请参阅http://www.semdesigns.com/Products/DMS/DMSToolkit.html

DMS succeeds because it provides a regular method and support infrastructure for complete access to the program structure as ASTs, and in most cases additional data such a symbol tables, type information, control and data flow analysis, all necessary to do sophisticated program manipulation.

DMS之所以成功,是因为它提供了一个常规的方法和支持基础设施,可以像AST一样完全访问程序结构,并且在大多数情况下还可以使用其他数据,如符号表,类型信息,控制和数据流分析,这些都是进行复杂程序操作所必需的。

#12


2  

'metaprogramming' is really a bad name for this specific feature, at least when you're discussing more than one language, since this feature is only needed for a narrow slice of languages that are:

'metaprogramming'对于这个特定的功能来说真的是一个坏名字,至少当你讨论多种语言时,因为这个功能只需要一小段语言:

  • static
  • compiled to machine language
  • 编译成机器语言

  • heavily optimised for performance at compile time
  • 在编译时针对性能进行了大量优化

  • extensible with user-defined data types (OOP in C++'s case)
  • 可扩展的用户定义数据类型(C ++中的OOP)

  • hugely popular

take out any one of these, and 'static metaprogramming', just doesn't make sense. therefore, i would be surprised if any remotely mainstream language had something like that, as understood on C++.

取出其中任何一个,并且'静态元编程',只是没有意义。因此,如果任何远程主流语言具有类似的东西,我会感到惊讶,正如C ++所理解的那样。

of course, dynamic languages, and several functional languages support totally different concepts that could also be called metaprogramming.

当然,动态语言和几种函数式语言支持完全不同的概念,也可称为元编程。

#13


1  

Lisp supports a form of "metaprogramming", although not in the same sense as C++ template metaprogramming. Also, your term "static" could mean different things in this context, but Lisp also supports static typing, if that's what you mean.

Lisp支持一种“元编程”形式,虽然与C ++模板元编程不同。此外,你的术语“静态”在这种情况下可能意味着不同的东西,但Lisp也支持静态类型,如果这就是你的意思。

#14


1  

The Meta-Language (ML), of course: http://cs.anu.edu.au/student/comp8033/ml.html

元语言(ML),当然:http://cs.anu.edu.au/student/comp8033/ml.html

#1


32  

The alternative to template style meta-programming is Macro-style that you see in various Lisp implementations. I would suggest downloading Paul Graham's On Lisp and also taking a look at Clojure if you're interested in a Lisp with macros that runs on the JVM.

模板样式元编程的替代方法是在各种Lisp实现中看到的宏样式。我建议下载Paul Graham的On Lisp,如果你对使用在JVM上运行的宏的Lisp感兴趣,还可以看看Clojure。

Macros in Lisp are much more powerful than C/C++ style and constitute a language in their own right -- they are meant for meta-programming.

Lisp中的宏比C / C ++风格强大得多,并且本身构成了一种语言 - 它们用于元编程。

#2


24  

let me list a few important details about how metaprogramming works in lisp (or scheme, or slate, or pick your favorite "dynamic" language):

让我列出一些关于元编程如何在lisp(或方案,或平板,或选择你最喜欢的“动态”语言)中工作的重要细节:

  • when doing metaprogramming in lisp you don't have to deal with two languages. the meta level code is written in the same language as the object level code it generates. metaprogramming is not limited to two levels, and it's easier on the brain, too.
  • 在lisp中进行元编程时,您不必处理两种语言。元级别代码使用与其生成的对象级代码相同的语言编写。元编程不仅限于两个层次,而且在大脑上也更容易。

  • in lisp you have the compiler available at runtime. in fact the compile-time/run-time distinction feels very artificial there and is very much subject to where you place your point of view. in lisp with a mere function call you can compile functions to machine instructions that you can use from then on as first class objects; i.e. they can be unnamed functions that you can keep in a local variable, or a global hashtable, etc...
  • 在lisp中,您可以在运行时使用编译器。事实上,编译时/运行时的区别在那里感觉非常人为,并且很大程度上取决于你的观点。在lisp中只需要一个函数调用,就可以将函数编译为机器指令,然后可以将它作为第一类对象使用;即它们可以是未命名的函数,可以保存在局部变量或全局哈希表等中......

  • macros in lisp are very simple: a bunch of functions stuffed in a hashtable and given to the compiler. for each form the compiler is about to compile, it consults that hashtable. if it finds a function then calls it at compile-time with the original form, and in place of the original form it compiles the form this function returns. (modulo some non-important details) so lisp macros are basically plugins for the compiler.
  • lisp中的宏非常简单:一堆函数填充在哈希表中并提供给编译器。对于编译器即将编译的每个表单,它会查询该哈希表。如果它找到一个函数然后在编译时用原始表单调用它,并且代替原始表单,它将编译此函数返回的表单。 (模数一些非重要的细节)所以lisp宏基本上是编译器的插件。

  • writing a lisp function in lisp that evaluates lisp code is about two pages of code (this is usually called eval). in such a function you have all the power to introduce whatever new rules you want on the meta level. (making it run fast is going to take some effort though... about the same as bootstrapping a new language... :)
  • 在lisp中编写一个评估lisp代码的lisp函数大约是两页代码(通常称为eval)。在这样的功能中,您可以在元级别上引入所需的任何新规则。 (让它快速运行需要付出一些努力......就像引导一种新语言一样...... :)

random examples of what you can implement as a user library using lisp metaprogramming (these are actual examples of common lisp libraries):

使用lisp元编程实现用户库的随机示例(这些是常见lisp库的实际示例):

  • extend the language with delimited continuations (hu.dwim.delico)
  • 用分隔的连续扩展语言(hu.dwim.delico)

  • implement a js-to-lisp-rpc macro that you can use in javascript (which is generated from lisp). it expands into a mixture of js/lisp code that automatically posts (in the http request) all the referenced local variables, decodes them on the server side, runs the lisp code body on the server, and returns back the return value to the javascript side.
  • 实现一个js-to-lisp-rpc宏,你可以在javascript中使用它(从lisp生成)。它扩展为js / lisp代码的混合,自动发布(在http请求中)所有引用的局部变量,在服务器端解码它们,在服务器上运行lisp代码体,并将返回值返回给javascript侧。

  • add prolog like backtracking to the language that very seamlessly integrates with "normal" lisp code (see screamer)
  • 添加prolog就像回溯到与“普通”lisp代码无缝集成的语言(参见screamer)

  • an XML templating extension to common lisp (includes an example of reader macros that are plugins for the lisp parser)
  • 公共lisp的XML模板扩展(包括作为lisp解析器插件的读取器宏的示例)

  • a ton of small DSL's, like loop or iterate for easy looping
  • 大量的小型DSL,如循环或迭代,以便轻松循环

#3


13  

Template metaprogramming is essentially abuse of the template mechanism. What I mean is that you get basically what you'd expect from a feature that was an unplanned side-effect --- it's a mess, and (although tools are getting better) a real pain in the ass because the language doesn't support you in doing it (I should note that my experience with state-of-the-art on this is out of date, since I essentially gave up on the approach. I've not heard of any great strides made, though)

模板元编程实质上是滥用模板机制。我的意思是你基本上得到了你所期望的功能,这是一个无计划的副作用 - 它是一团糟,(尽管工具越来越好)是一个真正的痛苦,因为语言没有支持你这样做(我应该注意到,我对这方面的最新经验已经过时了,因为我基本上已经放弃了这种方法。虽然我没有听说过任何重大进展)

Messing around with this in about '98 was what drove me to look for better solutions. I could write useful systems that relied on it, but they were hellish. Poking around eventually led me to Common Lisp. Sure, the template mechanism is Turing complete, but then again so is intercal.

在大约98年左右解决这个问题是驱使我寻找更好解决方案的原因。我可以编写依赖它的有用系统,但它们是地狱般的。四处寻找最终导致我使用Common Lisp。当然,模板机制是Turing完成,但是同样是intercal。

Common Lisp does metaprogramming `right'. You have the full power of the language available while you do it, no special syntax, and because the language is very dynamic you can do more with it.

Common Lisp做元编程“正确”。你可以使用该语言的全部功能,没有特殊的语法,并且因为语言非常动态,你可以用它做更多的事情。

There are other options of course. No other language I've used does metaprogramming better than Lisp does, which is why I use it for research code. There are lots of reasons you might want to try something else though, but it's all going to be tradeoffs. You can look at Haskell/ML/OCaml etc. Lots of functional languages have something approaching the power of Lisp macros. You can find some .NET targeted stuff, but they're all pretty marginal (in terms of user base etc.). None of the big players in industrially used languages have anything like this, really.

当然还有其他选择。没有其他语言我使用的元编程比Lisp更好,这就是我将它用于研究代码的原因。你可能想要尝试别的东西有很多原因,但这都是权衡利弊。您可以查看Haskell / ML / OCaml等。许多函数式语言都具有接近Lisp宏的强大功能。你可以找到一些.NET目标的东西,但它们都非常边缘(在用户群等方面)。在工业上使用的语言中,没有一个大玩家真的有这样的东西。

#4


11  

Nemerle and Boo are my personal favorites for such things. Nemerle has a very elegant macro syntax, despite its poor documentation. Boo's documentation is excellent but its macros are a little less elegant. Both work incredibly well, however.

Nemerle和Boo是我个人最喜欢的东西。 Nemerle有一个非常优雅的宏语法,尽管它的文档很差。 Boo的文档非常好,但它的宏不太优雅。然而,两者都工作得非常好。

Both target .NET, so they can easily interoperate with C# and other .NET languages -- even Java binaries, if you use IKVM.

两者都以.NET为目标,因此如果您使用IKVM,它们可以轻松地与C#和其他.NET语言(甚至Java二进制文件)进行互操作。

Edit: To clarify, I mean macros in the Lisp sense of the word, not C's preprocessor macros. These allow definition of new syntax and heavy metaprogramming at compiletime. For instance, Nemerle ships with macros that will validate your SQL queries against your SQL server at compiletime.

编辑:澄清一下,我的意思是Lisp意义上的宏,而不是C的预处理器宏。这些允许在编译时定义新语法和繁重的元编程。例如,Nemerle附带的宏将在编译时针对您的SQL服务器验证您的SQL查询。

#5


9  

Nim is a relatively new programming language that has extensive support for static meta-programming and produces efficient (C++ like) compiled code.

Nim是一种相对较新的编程语言,它对静态元编程有广泛的支持,并产生高效的(类似C ++)编译代码。

http://nim-lang.org/

It supports compile-time function evaluation, lisp-like AST code transformations through macros, compile-time reflection, generic types that can be parametrized with arbitrary values, and term rewriting that can be used to create user-defined high-level type-aware peephole optimizations. It's even possible to execute external programs during the compilation process that can influence the code generation. As an example, consider talking to a locally running database server in order to verify that the ORM definition in your code (supplied through some DSL) matches the schema of the database.

它支持编译时功能评估,通过宏进行类似lisp的AST代码转换,编译时反射,可以使用任意值进行参数化的泛型类型,以及可用于创建用户定义的高级类型感知的术语重写窥视孔优化。甚至可以在编译过程中执行可能影响代码生成的外部程序。例如,考虑与本地运行的数据库服务器通信,以验证代码中的ORM定义(通过某些DSL提供)是否与数据库的模式匹配。

#6


6  

The "D" programming language is C++-like but has much better metaprogramming support. Here's an example of a ray-tracer written using only compile-time metaprogramming:

“D”编程语言就像C ++一样,但有更好的元编程支持。以下是仅使用编译时元编程编写的光线跟踪器示例:

Ctrace

Additionally, there is a gcc branch called "Concept GCC" that supports metaprogramming contructs that C++ doesn't (at least not yet).

此外,还有一个名为“Concept GCC”的gcc分支,它支持C ++没有的元编程结构(至少还没有)。

Concept GCC

#7


5  

Common Lisp supports programs that write programs in several different ways.

Common Lisp支持以多种不同方式编写程序的程序。

1) Program data and program "abstract syntax tree" are uniform (S-expressions!)

1)程序数据和程序“抽象语法树”是统一的(S表达式!)

2) defmacro

3) Reader macros.

3)读者宏。

4) MOP

Of these, the real mind-blower is MOP. Read "The Art of the Metaobject Protocol." It will change things for you, I promise!

其中,真正令人兴奋的是MOP。阅读“元对象协议的艺术”。我保证,这会改变你的想法!

#8


4  

I recommend Haskell. Here is a paper describing its compile-time metaprogramming capabilities.

我推荐Haskell。这是一篇描述其编译时元编程功能的论文。

#9


3  

Lots of work in Haskell: Domain Specific Languages (DSL's), Executable Specifications, Program Transformation, Partial Application, Staged Computation. Few links to get you started:

Haskell的大量工作:领域特定语言(DSL),可执行规范,程序转换,部分应用程序,分阶段计算。很少有链接可以帮助您入门:

#10


2  

The ML family of languages were designed specifically for this purpose. One of OCaml's most famous success stories is the FFTW library for high-performance FFTs that is C code generated almost entirely by an OCaml program.

ML系列语言专门为此目的而设计。 OCaml最着名的成功案例之一是用于高性能FFT的FFTW库,它是几乎完全由OCaml程序生成的C代码。

Cheers, Jon Harrop.

干杯,Jon Harrop。

#11


2  

Most people try to find a language that has "ultimate reflection" for self-inspection and something like "eval" for reifying new code. Such languages are hard to find (LISP being a prime counterexample) and they certainly aren't mainstream.

大多数人试图找到一种对自我检查具有“终极反射”的语言,以及用于实现新代码的“eval”之类的语言。这些语言很难找到(LISP是一个主要的反例),它们肯定不是主流。

But another approach is to use a set of tools that can inspect, generate, and manipulate program code. Jackpot is such a tool focused on Java. http://jackpot.netbeans.org/

但另一种方法是使用一组可以检查,生成和操作程序代码的工具。 Jackpot是一个专注于Java的工具。 http://jackpot.netbeans.org/

Our DMS software reengineering toolkit is such a tool, that works on C, C++, C#, Java, COBOL, PHP, Javascript, Ada, Verilog, VHDL and variety of other languages. (It uses production quality front ends to enable it to read all these langauges). Better, it can do this with multiple languages at the same instant. See http://www.semdesigns.com/Products/DMS/DMSToolkit.html

我们的DMS软件再造工具包就是这样一个工具,适用于C,C ++,C#,Java,COBOL,PHP,Javascript,Ada,Verilog,VHDL和各种其他语言。 (它使用生产质量前端使其能够读取所有这些语言)。更好的是,它可以在同一时刻使用多种语言。请参阅http://www.semdesigns.com/Products/DMS/DMSToolkit.html

DMS succeeds because it provides a regular method and support infrastructure for complete access to the program structure as ASTs, and in most cases additional data such a symbol tables, type information, control and data flow analysis, all necessary to do sophisticated program manipulation.

DMS之所以成功,是因为它提供了一个常规的方法和支持基础设施,可以像AST一样完全访问程序结构,并且在大多数情况下还可以使用其他数据,如符号表,类型信息,控制和数据流分析,这些都是进行复杂程序操作所必需的。

#12


2  

'metaprogramming' is really a bad name for this specific feature, at least when you're discussing more than one language, since this feature is only needed for a narrow slice of languages that are:

'metaprogramming'对于这个特定的功能来说真的是一个坏名字,至少当你讨论多种语言时,因为这个功能只需要一小段语言:

  • static
  • compiled to machine language
  • 编译成机器语言

  • heavily optimised for performance at compile time
  • 在编译时针对性能进行了大量优化

  • extensible with user-defined data types (OOP in C++'s case)
  • 可扩展的用户定义数据类型(C ++中的OOP)

  • hugely popular

take out any one of these, and 'static metaprogramming', just doesn't make sense. therefore, i would be surprised if any remotely mainstream language had something like that, as understood on C++.

取出其中任何一个,并且'静态元编程',只是没有意义。因此,如果任何远程主流语言具有类似的东西,我会感到惊讶,正如C ++所理解的那样。

of course, dynamic languages, and several functional languages support totally different concepts that could also be called metaprogramming.

当然,动态语言和几种函数式语言支持完全不同的概念,也可称为元编程。

#13


1  

Lisp supports a form of "metaprogramming", although not in the same sense as C++ template metaprogramming. Also, your term "static" could mean different things in this context, but Lisp also supports static typing, if that's what you mean.

Lisp支持一种“元编程”形式,虽然与C ++模板元编程不同。此外,你的术语“静态”在这种情况下可能意味着不同的东西,但Lisp也支持静态类型,如果这就是你的意思。

#14


1  

The Meta-Language (ML), of course: http://cs.anu.edu.au/student/comp8033/ml.html

元语言(ML),当然:http://cs.anu.edu.au/student/comp8033/ml.html