This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
at:tutorial:metaprogramming [2007/04/19 17:06] stimberm |
at:tutorial:metaprogramming [2009/11/21 07:44] tvcutsem |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | ||
- | ===== Metaprogramming ===== | ||
- | |||
- | ==== AT Zero - AmbientTalk without syntactic sugar ==== | ||
- | |||
- | In AmbientTalk, | ||
- | < | ||
- | > | ||
- | >>6 | ||
- | >if: 1 == 2 then: { 13 } else: { 42 } | ||
- | >>42 | ||
- | >1 + 2 * 3 | ||
- | >>7 | ||
- | </ | ||
- | However, these constructs are all **syntactic sugar**. Behind the scenes, they all perform message sends. The following code shows the equivalents of the previous code, but with the actual message sends: | ||
- | < | ||
- | >[5, 6, 7].at(2) | ||
- | >>6 | ||
- | >(1 == 2).ifTrue: { 13 } ifFalse: { 42 } | ||
- | >>42 | ||
- | > | ||
- | >>7 | ||
- | </ | ||
- | |||
- | ==== Quasiquoting and splicing ==== | ||
- | |||
- | In AmbientTalk, | ||
- | |||
- | Quoting and expression is done with the '' | ||
- | < | ||
- | >`3 == 3 | ||
- | >> | ||
- | >`3 + 8 | ||
- | >>11 | ||
- | > | ||
- | >> | ||
- | </ | ||
- | |||
- | Quoting an identifer results in a symbol: | ||
- | < | ||
- | >foo | ||
- | Undefined variable access: foo | ||
- | >`foo | ||
- | >>foo | ||
- | </ | ||
- | |||
- | < | ||
- | >def o := object: { def m() { 5 } } | ||
- | >>< | ||
- | >o.m() | ||
- | >>5 | ||
- | > | ||
- | >> | ||
- | </ | ||
- | |||
- | ==== First-class abstract grammar ==== |