
![]() |
HomePage |
![]() |
JW Davidson |
![]() |
Show Changes |
![]() |
Edit |
![]() |
|
![]() |
Recent Changes |
![]() |
Subscriptions |
![]() |
Lost and Found |
![]() |
Find References |
| Local Search |
History
| 9/12/2007 3:23:21 PM |
| -10.10.192.22 |
| 7/20/2007 10:55:03 PM |
| -10.10.192.236 |
![]() |
List all versions |
WikiTalk members are similar to members in .NET programming language as well as many other object-oriented languages.
Members can be either properties or methods. The only difference is whether they take parameters; properties don't and methods do.
Methods "take" arguments. Consider, for example, this use of the Substring method:
"hello".Substring(1,3)
The Substring method extracts a substring from another string. It takes two arguments (both integers). The first argument is the zero-relative index of the first character you want to extract and the second the number of characters you want to extract.
Arguments can be arbitrarily-complex expressions, so the following is valid:
"hello".Substring(1,"dogfood".SubString(0,3).Reverse.Length)
This expression will produce the same result as the previous one (i.e., the string "ell"). It'll get there in a more round-about way, though
First it takes the seven-character string "dogfood". Then it takes the substring from that that starts at index 0 and continues for three characters: "dog". It then reverses this string (producing "god") and then takes the length of that (producing 3).
Some methods allow for optional arguments. For example, the Substring method on strings allows you to leave off the second argument (the number of characters you want). In cases where a method allows for optional arguments, all of the optional arguments are stacked up at the end of the list of arguments.
Some methods allow for a variable number of arguments. For example, the InterWikiBehavior takes a few required arguments followed by an unlimited number of additional (optional) arguments. In cases where a method allows for a variable number of arguments, all of the optional variable arguments are stacked up at the end of the list of arguments.
One of the most powerful elements of WikiTalk is the WikiTalkBlock. A Block is a chunk of WikiTalk that can do something and can be treated as a first-class object in the language. For example, consider this WikiTalk:
["hello", "dogfood", "cat"].Collect
{ each |
each.Length
}
This will produce an Array of three numbers (5, 7 and 3 -- the lengths of the three strings). The block being used here is:
{ each |
each.Length
}
Blocks are delineated by curly-braces ({ and }). Unlike many program languages that treat blocks as a special syntactic element, WikiTalk treats them as object -- just like everything else. There's a bit of syntactic sugar that allows you to use blocks in a way that feels naturals, but they're really just more objects.
To be clear about this, look at this rewitten version of the WikiTalk above:
["hello", "dogfood", "cat"].Collect({ each | each.Length})
The interesting thing about this is that the block appears as an argument of the Collect method. In fact, this is how WikiTalk really handle things: you can specify a block either way. In the WikiTalk interpreter, the Collect() method takes a Block as an argument. When you write WikiTalk, you can specify the block either way.
To generalize, the following two forms of WikiTalk are absolutely identical in meaning and behavior:
function(arg1, arg2, {some block here})
and
function(arg1, arg2)
{
some block here
}
This principle applies across any function that takes a block as an argument. For example:
topic.LastModifiedBy.IfNull
{
"I have no idea who modified this topic last"
}
is identical to:
topic.LastModifiedBy.IfNull( {
"I have no idea who modified this topic last"
} )
To complete the picture, let's look at a further example:
topic.LastModifiedBy.IfNull
{
"I have no idea who modified this topic last"
}
Else
{
"Ah ha! I know who modified this; do something different"
}
This is actualy an invocation of a method called IfNullElse with two arguments (each a block). This way to specify more than one block as an argument carries generall through the WikiTalk language. While there aren't any examples of it yet, you could have ten blocks (with 9 intervening keywords). All the keywords would be slammed together to make the full name of the method and the blocks woul dbe passed along as arguments.
It would be handy if a property containing an appropriately defined block could be used in place of a block in argument lists.
For example, if we defined the property FooTopic:
Then we could collect these pages as follows:
allTopics.Collect(FooTopic)
You can get around this by enclosing the property function call in a block. Here's an example:
1 2 3 101 1001-- JimmySieben [2005-09-11]

| Not logged in. | Log in | |
The wiki for all things Objective Design Solutions
| Recent Topics | |
![]() |
WikiTalkMember |
![]() |
List all versions |
![]() |
| Change Style |
| Powered by Flexwiki v2.0.0.218 |