![]() |
Last updated: 8/20/2002; 9:29:52 AM |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The FuzzyBlog! Scotts Radio :: An Excursion into UserTalk
UserTalk: The Radio Scripting Language
UserTalk is the underlying scripting language for Radio. From a technical perspective, UserTalk is an algol derived language with a syntax reminiscent of Pascal. Among UserTalk's unique features are:
The examples below are by no means a full guide to UserTalk. When O'Reilly previously published a book on UserTalk, when it was named Frontier, the guide was 592 pages. Clearly this is more of a taste of UserTalk than a full meal. The UserTalk Development Environment
One of the most distinctive aspects of UserTalk beyond the language itself but actually the environment in which you develop UserTalk scripts. At the heart of Radio is an outliner and an outlining metaphor. This outliner can also be used to structure your code and manage large blocks of code with an expand and collapse approach. To work in the UserTalk development environment, the first step is to go into "Full Radio", the non browser version of Radio, talked about in Chapter 3 under Republishing your entire blog.. Here's how. On Mac OS X: Control click the Radio icon in the Dock and choose Open Radio from the menu. The Radio development environment is displayed. Most of the Radio development features are located on the Tools -> Developers menu as shown below.
Here are the important commands that you need to know to take advantage of this environment.
Although the UserTalk environment has additional tools, Jump Workspace and QuickScript are the one's you use most frequently. A picture of the overall environment including a workspace and the outline based scripting is shown below.
UserTalk Language Examples and Verbs
Now that you have seen the UserTalk development environment, here are some examples of how common programming tasks are accomplished. Please note that these examples were largely referenced from the UserLand documentation on UserTalk. Like every language, UserTalk has conditional statements. An if structure may include an else block. It will be executed if the expression is false. if answer > 6 msg ("Big family!")else msg ("Not such a big family!")
A fileloop structure iterates through every item in a folder or on a disk (or even every disk), assigning the loop variable to each element in turn. The example below will use the message box facility (msg) to display the filename that the script finds. fileloop (f in path) msg (file.fileFromPath (f))
For more UserTalk examples, please see: http://www.fuzzygroup.com/go/?usertalkExamples At the heart of UserTalk are a series of several hundred "verbs" (think statements in another language). All of these are documented online at the url: http://docserver.userland.com/. Shown below is a table of the different categories of verbs that make up UserTalk. My thanks are extended to UserLand who let me use this material with permission.
Beyond the standard UserTalk verbs, UserTalk also has a very sophisticated set of operators for comparisons, evaluation and more.
Hello World Revisited
The classic test for programming languages is always "Hello World" - a simple script that does nothing but write to the screen, console or dialog box "Hello World!". As programming environments get more and more sophisticated, the Hello World application always becomes interesting. In Radio there are two ways to implement Hello World, Quick Script and as a saved script. Radio's Quick Script command is a text editor window where you can enter one or more lines of code and then execute them. A saved script is just that -- a script that has been saved into the Radio environment so that it can be called by another routine. We're going to start with a slight enhancement of our normal Hello World code to illustrate variable assignment and a function call along with just printing to the screen. What we need to do is:
Here's our code for this: s = "Hello World!";s = string.upper ("Hello world!");dialog.notify (s);
This is pretty standard development stuff. Here are some comments: · Line 1 o Line 1 binds the text to the variable s. o Line 1 also shows us that variables in UserTalk are untyped and dynamically converted between types as needed. o The ";" is the delimiter between lines of code. · Line 2 o string.upper is a string function which upper cases text. All UserTalk functions are organized into "categories" and then referenced by "category.specific_function" syntax. o Another example is strong.cleanMailAddress which normalizes an email address (this lowerUpperCase is standard in UserTalk for multiple word type things) o Full documentation on UserTalk string functions is at: http://docserver.userland.com/string/ · Line 3 o dialog.notify pops up a dialog box with a notify icon. o dialog.alert would popup the same dialog box but with a different icon Hello World with Quick Script
Here's how to write Hello World in UserTalk using Quick Script.
s = "Hello World!";s = string.upper ("Hello world!");dialog.notify (s);
Writing Hello World as a Saved Script Here's how to write Hello World in UserTalk as a script saved into the Radio environment. As discussed earlier, Radio has a unique outline based environment tied into its overall object database. The best way to think of Radio's object database is as a hierarchical set of name-value pairs. These are referred to as tables. The Radio object database stores the entire Radio environment including much of Radio's own code (above the level of system primitives, Radio is largely written in Radio). Since the environment is hierarchical, it is very analogous to a class browser based system like SmallTalk or the Common Lisp Object System (CLOS). In Radio the Jump command, CTRL+J, moves you into different sections of the system. For example, if you type CTRL+J and then "callbacks" you are taken to "system.callbacks". Note that Radio will automatically pre-pend "system." to your jump command if it's appropriate. Once you jump to something you can, of course, open the script associated with it. This is shown below in Figure 7-XXX.
In the UserTalk scripting environment, user code is stored in a table called "workspace". What we're going to do is: · Go to workspace · Add a new script · Add our code · Test it by calling it from QuickScript Here are the steps 1. Select Tools -> Developers -> Jump. 2. Type "workspace" (no quotes) and select Ok. 3. Select Table -> New Script. 4. Type "helloWorld" as the script name (again, no quotes) and select Ok. 5. Paste in the text from the Quick Script window (yes, it will still be there). If you click the Run button at the top of the window code editing window, you will get this error message:
What this error message means is that at the context of helloWorld itself, it can't be run. However, if you go to the QuickScript window again and enter "workspace.helloWorld" and then click Run, this executes properly. If you want to run this from the context of the script itself then add the line "helloWorld()" to the end of the script. CopyrightCopyright (c) 2002, J. Scott Johnson. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections being, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "Appendix 1 - Terms of Use". Note: I'm new to writing a Free Documentation statement and the above might not be perfect.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Copyright 2002 © The FuzzyStuff |
![]() |