Metaprogramming: Difference between revisions

Added Arturo implementation
(Added Arturo implementation)
Line 148:
kXXc some
</pre>
 
=={{header|Arturo}}==
 
Arturo has been designed with flexibility in mind (see: DSL creation) and as different languages of the same heritage (e.g. REBOL, Red, etc) has meta-programming capabilities as part of the language itself.
 
Let's see some examples:
 
===Infix Operators===
 
<lang rebol>sumThemUp: function [x,y][
x+y
]
 
alias.infix '--> 'sumThemUp
 
do [
print 3 --> 4
]</lang>
 
{{out}}
 
<pre>7</pre>
 
===Runtime Code Evaluation===
 
<lang rebol>code: "print 123"
do code</lang>
 
{{out}}
 
<pre>123</pre>
 
===Symbol Creation & Access at Runtime===
 
<lang rebol>myvar: "iAmAVariable"
 
let myvar 2
 
print myvar ; print the name of the variable
 
print var myvar ; print the value of the variable
print iAmAVariable ; the same</lang>
 
{{out}}
 
<pre>iAmAVariable
2
2</pre>
 
===Data as Code & Code as Data===
 
<lang rebol>block: [print]
block: block ++ to :integer "34"
 
print "Here is our code:"
print as.code block
 
print ""
print "And here's its result:"
do block</lang>
 
{{out}}
 
<pre>Here is our code:
[print 34]
 
And here's its result:
34</pre>
 
=={{header|C}}==
1,532

edits