Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Curl macros introduction (part 1)
08-10-2011, 03:02 AM, (This post was last modified: 08-10-2011, 05:12 AM by RobertShiplett.)
#1
Brick  Curl macros introduction (part 1)
This series is about Curl macros

Macros allow you to create both very simple and very complex results in Curl web pages, in Curl applications, and in Curl scripts. Most often they hide complexity from the user of the macro and keep markup simple.

You use a macro in Curl just as you would use any other Curl expression.
Examples: are any macros? Suppose We Wrote:{paragraph This is a text procedure }
{my-para This might be a macro or a user-defined text-format or text-proc }
{ml-para "Using quotes is a clue that it might be a proc, but it could be a macro"}
{paragraph Usually only by looking in the docs or user code will you know.}

Default Curl expressions (from the Curl library packages) which begin with {define- are macros. The Curl documentation clearly indicates which expression prefixes are macros both in the index and the respective macro pages. The live-code in the docs in built using the {example } macro.

Expressions with arguments not separated by commas or separated by other characters would be macros (but I suggest using commas in your macros and in what follows I try to show why.)

A macro is used to define new macros: it is {define-macro } and it gets its power from two other macros, those being {syntax-switch } and {expand-template }.

A macro call is replaced by the source code corresponding to the value which the macro returns (although macros do not declare a return value, they use {return } expressions.

In a package write:
Code:
{define-macro public {uc ?txt:text}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

In an applet write:
Code:
{import uc from MY.MACROS}
{uc "this quoted text will print in caps without the quotes"}

In the browser we see Curl Wrote:THIS QUOTED TEXT WILL PRINT IN CAPS WITHOUT THE QUOTES

Note: Curl is an expression-based language, but macros may identify some expressions as statements. Examples are let and set expressions which were not surrounded by curly-braces for your convenience or other expressions where curl-braces were not required. Macro pattern case logic can recognize MyClass.myClassProc as a BinaryOp. But we will set all these details to one side for now.

Robert Shiplett, Curlr
Fredericton NB

Canada
08-10-2011, 05:42 AM, (This post was last modified: 08-10-2011, 05:43 AM by RobertShiplett.)
#2
RE: Curl macros introduction (part 1)
When passed quoted characters, all of these variants have the same effect:
Code:
{define-macro public {uc ?txt:text}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

{define-macro public {ucv ?txt:verbatim}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

{define-macro public {uctk ?txt:token}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

{define-macro public {uce ?txt:expression}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

{define-macro public {ucs ?txt:statement}
    {return {expand-template {{String ?txt}.to-upper-clone}}}
}

When called as
Code:
{uc  "this quoted text will print in caps without the quotes"}
{br}
{ucv  "this quoted text will print in caps without any quotes"}
{br}
{uctk "this quoted text will print in caps without any quotes"}
{br}
{uce  "this quoted text will print in caps without any quotes"}
{br}
{ucs  "this quoted text will print in caps without any quotes"}
Robert Shiplett, Curlr
Fredericton NB

Canada
08-10-2011, 05:57 AM,
#3
RE: Curl macros introduction (part 1)
When passed a String identifier, all of these variants have the same effect (the proc is the clue that these simple macros are examples only):
Code:
{define-proc {up s:String}:String
    {return {s.to-upper-clone}}
}

{define-macro public {uc ?txt:text}
    {return {expand-template {up ?txt}}}
}

{define-macro public {ucv ?txt:verbatim}
    {return {expand-template {up ?txt}}}
}

{define-macro public {uctk ?txt:token}
    {return {expand-template {up ?txt}}}
}

{define-macro public {uce ?txt:expression}
    {return {expand-template {up ?txt}}}
}

{define-macro public {ucs ?txt:statement}
    {return {expand-template {up ?txt}}}
}

when called as
Code:
{def str:String = "testing macros"}

{uc   str}
{br}
{ucv  str}
{br}
{uctk str}
{br}
{uce  str}
{br}
{ucs  str}
Robert Shiplett, Curlr
Fredericton NB

Canada
08-10-2011, 06:04 AM,
#4
RE: Curl macros introduction (part 1)
But what happens if you attempt

Code:
{br}
{uc   "test " & str}
{br}
{ucv "test " & str}
{br}
{uce "test " & str}
{br}
{ucs "test " & str}
{br}
{uctk "test " & str}
{br}

???
Robert Shiplett, Curlr
Fredericton NB

Canada
04-25-2015, 05:28 PM,
#5
RE: Curl macros introduction (part 1)
The difficulty for understanding {value} is especially obvious when using at the top level of a curl applet file. To understand this, a user must know a DefaultDocument or PlainDocument will add an object without being defined with a varirable to it's layout container (a TextFlowBox) by default , while a variable definition will be kept as a variable only and value of this variable won't be added to it's layout container implicitly. So when you want a variable to be added to a DefaultDocument or PlainDocument, eithier use {value var} at the top level of the *Document, or wrap this variable with another Graphical container like a Fill or Frame or anything else, which is then instantiated directly at the top level of *Document without being assigned to any variable.
Our
excellent online cert
killer 640-461
training programs will lead you
2V0-621 to success in the We also offer latest.


Possibly Related Threads...
Thread Author Replies Views Last Post
  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
  Curl as flashcard markup RobertShiplett 1 4,819 03-09-2013, 01:58 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('195')