There is an example by Chris Barber here.
The IDE docs example is in a Curl live-docs {example } macro for running/editing/saving doc code snippets and goes like this
{define-proc {not-odd-error i:int}:never-returnsIt is not at all the same as the language primitive named void.
{error {format "%s is not odd", i}}
}
{define-proc {assert-odd val:int}:int
{return
{if {bit-and val, 1} == 1 then
val
else
{not-odd-error val}
}
}
}
Which somehow brings me round to JavaScript and new.
In Curl, the programmer is not required to use the {new } macro - and using it requires another comma in a declaration.
So why ever use {new MyObject, my_args} ?
It might be this: what MyObject is specifying for the macro is a type - and that type may be determined at runtime. This is not what you usually expect in a language that is "typed" - but this is a language which also has an any type.
So one step further: in Smalltalk the issue is to know who should implement new and basicNew and new:
But in Curl, new is also a method: it is a method of 3 classes in the package CURL.LANGUAGE.REFLECTION
ConstructorHere is what the docs say about InstanceMaker:
Factory
InstanceMaker
public abstract sealed InstanceMaker {inherits ClassMember}Note that the {new } macro is from the package: CURL.LANGUAGE.COMPILER
Package: CURL.LANGUAGE.REFLECTION
Direct Known Subclasses: Factory, Constructor
The representation of a Constructor or Factory for objects of some class.
Notes
See ClassType.
Which somehow brings me to {let ...} {set ...} and {def ...} ... and {value ...}
I recently posted a Rebol tyro puzzler
p: 42 lst: [p ] what: first lst ; What is the value of :what ?
There is a great little bit in Icon about assignments which do not occur and assignments which reverse when an expression does not succeed. Like Rebol and Curl, Icon is expression-based. But what huge differences in the paradigms of these three unusual languages. Icon has the prefix dot for de-referencing and Rebol has the word reduce.
let and def are primitives of the Curl language; set, however, is a macro - as are {value ...} and {do ...}.
In some ways, the Curl docs articles on let and value are a great introduction to the language ( def came to Curl only recently.)
What I have found is that it is not all so very clear to neophytes just what is meant by "top-level" code.
Let's take the case of a Curl applet intended for a web browser. The content of the Curl applet is found in a document which will be one of 3 possible types. the default type need not be declared and is DefaultDocument.
Someone new to Curl places a {VBox } as declarative Curl in a pristine applet, runs it and nothing appears in the browser. Or is that so? This is why I always have my windowing environment on an OS flip my default window backgrounds to some pleasant shade of green: when a browser pane shows me that green background - even if just in some text entry field - I know that something is missing. The default Curl document background is white. My demo strategy is this: make things explicitly and declare things explicitly.
{curl 7.0 applet}|| end of applet comment =====================
{curl-file-attributes character-encoding = "utf8"}
{applet
name="top level demo",
notes="like rebol, add most any metadata tag - this one is called notes"}
{document-style DefaultDocument}
{set-document-properties background =
{Background.from-string "blue"}}
{title heading? = false, Demo}
{VBox
{text {value 65535 + 42}},
{paragraph btw, 6782865577 is prime},
{text So, what was the question?},
{new HBox, {paragraph this is just some text ...}}
}
|tagged-comment#
[ to be continued ... ]
#tagged-comment|
No comments:
Post a Comment