User Tools

Site Tools


at:tutorial:metaprogramming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:metaprogramming [2007/07/27 07:21] jdedeckerat:tutorial:metaprogramming [2007/07/31 16:46] jdedecker
Line 25: Line 25:
  
 ==== Quasiquoting and splicing ==== ==== Quasiquoting and splicing ====
 +Quasiquoting and splicing are an advanced and powerful metaprogramming techniques that control the evaluation process and allow one to manipulate the evaluation process of the abstract syntax tree.
  
-=== Qouting ===+=== Quoting ===
  
 Any valid AmbientTalk expression can be quoted. This prevents the expression from being evaluated. Instead, it is returned literally. Any valid AmbientTalk expression can be quoted. This prevents the expression from being evaluated. Instead, it is returned literally.
Line 59: Line 60:
 </code> </code>
  
-Note that in ''`foo.text'', the quoted expression is ''foo'' and //not// ''foo.text''. The selection is performed on the result of the quotation, in this case a symbol.+Note that in ''`foo.text'', the quoted expression is ''foo'' and //not// ''foo.text''. The selection of the field //text// is performed on the result of the quotation, in this case a symbol.
  
 == Expressions ==  == Expressions == 
Line 78: Line 79:
 == Statements == == Statements ==
  
-Statements (definitions, assignments, ...) can also be quoted, but only inside a quoted statement list. Trying to quote a statement in the same way as an expression will cause a parse error.+Statements (definitions, assignments, ...) can also be quoted, but only inside a quoted statement list. Trying to quote a statement in the same way as an expression will cause a parse error.  Instead it is necessary to wrap the statements in a closure using ``{'' and ``}''.
  
 <code> <code>
Line 127: Line 128:
 >[ 7, 8, 9, @upTo(4) ] >[ 7, 8, 9, @upTo(4) ]
 >>[7, 8, 9, 1, 2, 3, 4] >>[7, 8, 9, 1, 2, 3, 4]
 +>[ 7, 8, 9, upTo(4) ]
 +>>[7, 8, 9, [1, 2, 3, 4]]
 </code> </code>
 +In the example above the elements of the table returned by invoking **upTo(4)** are added in place to the table in which the expression was spliced.  Evaluating the same expression without the splice operator adds the table rather than the elements of the table.  Hence, the use of the splice operator removes a level of nesting and adds the elements //in place// to the table.
  
 Splicing can also be used in combination with quoting and unquoting. AmbientTalk provides the //unquote-splice// operator ''#@'' that can be used to splice the value of an unquotation into a quoted expression. Splicing can also be used in combination with quoting and unquoting. AmbientTalk provides the //unquote-splice// operator ''#@'' that can be used to splice the value of an unquotation into a quoted expression.
at/tutorial/metaprogramming.txt · Last modified: 2009/11/21 07:44 by tvcutsem