Transcript and Dot Notation

Geoff Canyon gcanyon at inspiredlogic.com
Sun Feb 26 04:37:25 EST 2006


On Feb 26, 2006, at 12:33 AM, Jeanne A. E. DeVoto wrote:

> At 12:20 AM -0800 2/26/2006, Geoff Canyon wrote:
>> (g) co-routines
>> (h) anonymous functions
>
> What are co-routines and anonymous functions? (Curious...)

A co-routine is kind of like a thread except that it only yields time  
at certain spots (and under your control). This makes it easier to  
understand and manage.

http://en.wikipedia.org/wiki/Coroutine

<quote>

Coroutines are useful to implement the following:

State machines within a single subroutine, where the state is  
determined by the current entry/exit point of the procedure; this can  
result in more readable code.
Actor model of concurrency, for instance in computer games. Each  
actor has its own procedures (this again logically separates the  
code), but they voluntarily give up control to central scheduler,  
which executes them sequentially (this is a form of cooperative  
multitasking).
Generators, and these are useful for input/output and for generic  
traversal of data structures.

</quote>

Anonymous functions are functions that you declare on the fly to  
accomplish some (usually small) task. They're commonly (most often?)  
used with a map function, which takes a function and a list, and  
applies the function to every item in the list.

So (imagining in transcript) suppose you have a variable that  
contains a bunch of one-line sentences, and you want the last word of  
each line. You could do this:

put empty into tResult
repeat for each line L in tList
   put (the last word of L) & cr after tResult
end repeat
delete char -1 of tResult

With anonymous functions you could do something like this:

put map("lines",(anonfunction (L) (the last word of L)),tList) into  
tResult

Map works on lists, but in transcript there's more than one way to  
delimit a list, so I added an initial argument to set the delimiter.

regards,

Geoff



More information about the use-livecode mailing list