Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Curl macros introduction (part 3)
08-10-2011, 04:01 AM, (This post was last modified: 08-10-2011, 04:27 AM by RobertShiplett.)
#1
Brick  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"}
{paragraph ndashi'd {ndashi str1 - str2} }

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} }

  FAILS   {paragraph ndashi'd {ndashi str1 - "that"} }

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} } }
|| as does
FAILS {paragraph ndashi'd {ndashi str1 - {value str2} } }  || Neither can accept an expression

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"}
{def str2:String = "these"}
{paragraph ndash'd {ndash str1 - str2 } }

{expand-to-string {ndash str1 - str2}}


we see in our test web page
On web page Curl Wrote:ndash'd this–these

str1 & n-dash & str2

and for
Code:
{paragraph ndashi'd {ndashi str1 - str2 } }
{expand-to-string {ndashi str1 - str2}}

we see in the test page
On web page Curl Wrote:ndashi'd this–these
str1 & n-dash & str2

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
Reply
08-10-2011, 08:56 AM, (This post was last modified: 08-10-2011, 09:00 AM by hokada.)
#2
RE: Curl macros introduction (part 3)
Robert, Thank you for your good instruction.

You can use {CurlSource.get-text} instead of {expand-to-string} if you want to debug in macro.

For instance,
Code:
{def n-dash = {String c-dash}}

{define-macro public {ndash ?t1:token, ?t2:text}
   def v = {expand-template
                  {value
                     ?t1 & n-dash & ?t2
                  }
               }
   {output {v.get-text}}
   {return v}
}
Reply
08-13-2011, 07:00 AM,
#3
RE: Curl macros introduction (part 3)
(08-10-2011, 08:56 AM)hokada Wrote: Thanks for adding the note on this.
(08-10-2011, 08:56 AM)hokada Wrote: Yes, this is useful. And we have {if-debuggable } to wrap that {output } but with some restrictions when Pcurl'ing code. I haven't tried using it in a Pcurl file. Can you comment?
Robert Shiplett, Curlr
Fredericton NB

Canada
Reply
08-16-2011, 08:48 AM,
#4
RE: Curl macros introduction (part 3)
You should generate the pcurl including a debuggable information if you want to use {if-debuggable} with pcurl.

You can do it on Curl IDE.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Brick Curl macros introduction (part 1) RobertShiplett 4 6,993 04-25-2015, 05:28 PM
Last Post: glennmcgrath
  server-side Curl issue : TocDocument RobertShiplett 3 5,691 02-09-2015, 02:11 PM
Last Post: Sumeraxe
  Curl with HTML widget + CintaNotes RobertShiplett 0 4,444 09-08-2014, 07:42 AM
Last Post: RobertShiplett
  Curl for the new Kodansh kanji books RobertShiplett 0 3,032 09-07-2014, 08:51 PM
Last Post: RobertShiplett
  Curl on Facebook - another page RobertShiplett 0 3,737 02-01-2014, 02:29 AM
Last Post: RobertShiplett
  Curl for CoffeeScript folks RobertShiplett 0 4,758 06-29-2013, 02:52 AM
Last Post: RobertShiplett
  Curl JavaScript bytecodes RobertShiplett 0 4,939 06-19-2013, 10:33 PM
Last Post: RobertShiplett
  jinja2 templates for Curl RobertShiplett 0 4,147 06-14-2013, 08:33 AM
Last Post: RobertShiplett
  Curl and QNX RobertShiplett 0 4,932 04-24-2013, 11:38 PM
Last Post: RobertShiplett
  WikizPad Curl personal wiki RobertShiplett 0 4,115 03-11-2013, 01:09 AM
Last Post: RobertShiplett
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('197')