08-10-2011, 04:01 AM,
(This post was last modified: 08-10-2011, 04:27 AM by RobertShiplett.)
|
|||||
|
|||||
Curl macros introduction (part 3)
From ndash to n-Soup
The {ndash } macro was very basic. It only has one {return } expression and no logical branches in the code block. Now for a variant named {ndashi } which only accepts Curl identifiers such as variable names. The only change in the new macro will be its declaration as Code: {define-macro public {ndashi ?t1:identifier - ?t2:identifier} A typical expression using the macro might be Code: {let public str1:String = "this",str2:String = "these"} Now for an interesting point: {ndash } would work with the two String variables. But {ndashi } will fail if used in place of {ndash } Code: {paragraph ndash'd {ndash str1 - str2} } and it fails with an error stating that an identifier was expected but "that" was received. In the case of {ndash } being passed str1 and str2 the macro expander receives a token in the first case and is content that the value of str2 is characters. But that does not mean that the following could succeed: Code: FAILS {paragraph ndash'd {ndash str1 - {value str2} } } It is essential to test macros and for that there is a Curl mechanism in the form of a macro named {expand-to-string }. When applied to our unintended use of {ndash } Code: {def str1:String = "this"} we see in our test web page On web page Curl Wrote:ndash'd this–these and for Code: {paragraph ndashi'd {ndashi str1 - str2 } } we see in the test page On web page Curl Wrote:ndashi'd this–these Note: Identifier is the name of a Curl class and its instances have a name field. Next we will build {ndashe } to accept expressions.
Robert Shiplett, Curlr
Fredericton NB Canada |
|||||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Curl macros introduction (part 3) - by RobertShiplett - 08-10-2011, 04:01 AM
RE: Curl macros introduction (part 3) - by hokada - 08-10-2011, 08:56 AM
RE: Curl macros introduction (part 3) - by RobertShiplett - 08-13-2011, 07:00 AM
RE: Curl macros introduction (part 3) - by hokada - 08-16-2011, 08:48 AM
|
Users browsing this thread:
2 Guest(s)
2 Guest(s)