Showing posts with label macro. Show all posts
Showing posts with label macro. Show all posts

Friday, December 10, 2010

Curl pragma

Chris Barber's Zuzu Curl testing package is a sort of Curl goldmine.

Here is one snippet:

{getter public inline {size}:int

  {pragma suppress SyntaxRequiresInteger}
  {return {bit-count self.mask}}
  {pragma unsuppress SyntaxRequiresInteger}
}
There is very little documentation on pragmas in Curl other than the documentation page for pragma in the package CURL.LANGUAGE.PRAGMA

Here is a short exerpt:
This syntax allows the developer to specify directives in the source code to affect the behavior of advanced versions of the Curl IDE that support real-time error checking. Pragmas are ignored by the Curl RTE and have no effect on the runtime behavior of Curl programs.
That snippet is followed by the caveat that pragmas are only processed by the Curl plugin for Eclipse
One use that I think terrific is {pragma info|warning|error message}An example would be
{pragma info FIX_THIS really klunky and hard to test}

But how to keep these out of code commits (let there be no TODO in thy code escrow....) ?

Wednesday, November 18, 2009

Learning Curl: {value expr} and Curl as an expression-based language

One thing that I have noticed in C# and Java programmers learning Curl is that if they rely on one of the available books (and even to some extent if they use the on-line Curl resources) there is a puzzle about {value some-expression} code blocks.

Here is an example from a book on Curl:
{value 2fortnights + 1day}
This an example of a Curl expression in which quantities are added (note the optional use of the plural for the user-defined quantity.)

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
time in seconds is {value 2fortnights + 1day}
 
In keeping with the Gentle Slope approach to reduce the steepness of the Curl learning-curve, the text
time in seconds is
appears in the browser as text.
We say that this bit of text is at the top-level.
What follows, however, is an expression within curly braces and what we want to display is the result of that addition of the two Time quantities. We could have written this expression using optional parentheses as
{value (2fortnights + 1day) }
The {value } macro has been used to return a value: that is all.
To show that this is so, consider this alternative:
{String (2fortnights + 1day) }
The default constructor for the String class also returns a value (an instance of a String.)
Here is another alternative using assignment to a variable named tos:

{let tos:Time = 2fortnights + 1day}
The Time value held in the variable is {String tos}

And finally a complete alternative applet:

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
{let tos:Time = 2fortnights + 1day}

The time in seconds equals {value 2fortnights + 1day}

Time quantity in the variable is {String tos}

Number of days: {format "%.0f", (tos / 1day)}

which displays in the browser as follows:

The time in seconds equals 2.5056e+006s

Time quantity in the variable is 2.5056e+006s

Number of days: 29

A more compact version of the applet using explicit {br} line formatting rather than relying on Curl to display the extra new lines might have been:

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
{let tos:Time = 2fortnights + 1day}
The time in seconds equals {value 2fortnights + 1day} {br}
Time quantity in the variable is {String tos} {br}
Number of days: {format "%.0f", (tos / 1day)}

And so we proceed to wend our way up the 'Gentle Slope' of Curl.

Saturday, July 18, 2009

Tagging content with Curl macros

Curl was thought of as a web content language before getting some attention as an RIA platform, but Curl macros are of interest for markup because Curl files are Curl data and macros are expanded based on the package reading that file. So in different contexts, the same markup can be used to obtain different results with no conversion.
Here is an example from an outline of mine on microformats:

{topic "microformats",

{wp "http://en.wikipedia.org/wiki/Microformats", Lang.en},

{home "http://microformats.org/"},

{intro "http://www.digital-web.com/articles/microformats_primer/"},

{blog "http://garrettdimon.com/", BlogType.personal },

{cf "http://microformatique.com/optimus/"}
}

The commas are an option that I chose for the {topic} macro, but the Curl macro format is very open and the punctuation is wholly arbitrary on my part.
Curl also offers a more extensive {define-syntax} option which is even more suited to treating Curl as data than the friendly {define-macro} with its many template or pattern options.
In the elements {wp} and {blog} the final attributes are themselves optional and in some contexts might be ignored altogether. Here they are simply my enums Lang and BlogType.

Monday, May 25, 2009

Surge, the RIA platform; Curl, the language

As an enterprise RIA vendor, Curl, Inc. might well opens its platform even further than its recent embrace of SQLite, JSON and AMF.

At that point the Curl language would be just one aspect of their RIA offering.

When a Java developer is learning Curl, I often have occasion to make the reminder that a procedure or a method return is an expression, that is, we use {return} or {return result} or {return asset, valuation}. But I also remind developers to select a word and tap the F1 key in order to take advantage of the Curl Documentation Viewer to take advantage of its live code examples.

If you use Help to open a search in the docs viewer for return you may miss what you would have seen with a simple F1 on a return word in your code. The return word is a macro.

The return macro is defined in the package CURL.LANGUAGE.COMPILER

It may well be that the time is coming when ordinary Curl developers will be able to look at that macro implementation code in that package.

With the new Curl 7.0 library access modifier, it should be possible to expose much more of the implementation of the Curl language to interested Curl developers.

In the long-term, the Curl language should move into the public domain. The return could be macro.

Saturday, July 28, 2007

Example is the Curl developer's example macro


This little Curl script could be the web developer's best friend.
As a web content language, Curl 5.0 provides a powerful RIA platform. This applet using the macro 'example' might convince you.
The macro 'example' creates a live code example in your browser which will open a child applet window.
First we run the following code snippet as an applet in the Curl IDE, embed it as a web applet or launch it with the Curl RTE with a dbl-click in a file explorer.
{curl 5.0 applet}
{applet license="development"}
{curl-file-attributes character-encoding = "windows-latin-1"}
{import * from CURL.DOC.CONTENT.ACCESSORIES}
{example 
{bold Hello {italic there}! }
}

Example is a Curl macro. The result is a web page in which to execute Curl, revert and save Curl applets. It you know something slicker than this, I would want to see it.
You may notice that in my example I have thrown in a {VBox }
I could hit REVERT and I would be back at the original. Here is the result:



If I like my changes, I can save the code from the web page with 'Save Applet'.
In practical terms this also means the ability to create web-based developer documentation with 'live' code snippets. And the eample maco nests: you can have a nippet which is used to demonstrate another snippet.
Curl comes with a visual test framework, but this little 'example' macro should give you a hint of what is possible in Curl 5.0
Note that 'example' is made available by importing the Curl package
CURL.DOC.CONTENT.ACCESSORIES