Curl neophytes are sometimes confused by the use of {value } macros in the examples in the Curl doc's.
I have placed an alternative example style below.
Curl at the top-level is rather like minimalist HTML: if you place a value in a page then the value gets displayed.
But usually a Curl applet is not a {value } expression at the top-level in a .curl file and this adds to unfamiliarity.
The example does include one use of a {value } expression - the macro is used in a {paragraph } text‑proc.
{value } is used in the live code doc's because we are passing our example value into a macro such as {example }.
In my variant example, a {do } expression is used with a top-level global public var instead. The macro {value } is used in {paragraph } as it might be used in a typical applet.
My revision:
The Curl docs on String Files for the scheme curl://some‑text‑resource has a live code {example } using {string-url }
Here is a variant of that example which uses the Curl macro {with-open-streams do }
The example is not wrapped in a {value } macro as neophytes find this confusing and it is not required for this example at the 'price' of a public global var in the example code. The text‑proc paragraph preserves our whitespace for our lines as read.
|| Note: we do not need to {set } myinput in this variant of the example.
{def result:StringBuf = {StringBuf}}
{do
|| create a string to be read as a stream
def mystring:String = "This is some string data I want to read as a stream \nin order to test a macro"
|| Construct a Url under the curl://string directory, using the
|| string we want to read as the filename.
def myurl:Url = {string-url mystring}
|| Now, read from it as if it were a normal file.
let myinput:#TextInputStream
{with-open-streams myinput = {read-open myurl} do
{until myinput.end-of-stream? do
{result.concat {myinput.read-one-line}}}
}
}
{paragraph text-preserve-whitespace?=true, {value result}}
Notes on the Curl web programming language and Curl markup using the Curl Surge Runtime Engine (RTE), the expression-based Curl language and Curl's macro facilities and class libraries
Pages
on the Curl Web Content Markup Language
on the Curl Web Content Markup and Programming Language from www.curl.com and www.curlap.com
Showing posts with label do expression. Show all posts
Showing posts with label do expression. Show all posts
Tuesday, June 21, 2011
Subscribe to:
Posts (Atom)