Serious First Steps In UserTalk Scripting
by Matt Neuburg
Author of the book Frontier: The Definitive Guide

Prev | TOC | Next


Datatypes

Why datatypes are cool

We have several times had occasion to mention datatypes. Every value in UserTalk has some datatype. We've mentioned numbers of various kinds; we've talked about strings; we've distinguished string4s from strings, and characters from both; we've seen that even an outline is a datatype. It's time to take a brief run through the main datatypes UserTalk knows about.

Datatypes are important for several reasons. For one thing, as we've already seen, you can't use the verb "new()" unless you know the datatype of the thing you want to create.

Also, a table entry always tells you what datatype it is (in the "kind" column), and it's nice to be able to appreciate what this means.

Furthermore, every scalar datatype comes with a verb that transforms values with other datatypes into that datatype. For instance, 4 is a number; "4" is a string. To get from the first to the second, you can say string(4). This is called coercion. Of course, not every datatype can be meaningfully coerced to every other datatype, but Frontier tries remarkably hard.

Most verbs are restricted as to the kind of datatype they work on; they are expecting each of their parameters to be of a certain datatype. If you feed a wrong datatype as a parameter, Frontier will make some attempt to coerce it to the right datatype; this is called implicit coercion.

For example, if a verb expects a string4 such as 'TEXT' it will not appear to you to be an error if you hand it instead a string, "TEXT"; that's because it's clear to Frontier how to turn the string "TEXT" into a string4, so it just goes ahead and does it without complaining.

However, such implicit coercion is often not possible, and an error can occur. Also, you need in general to know the datatype you're working with, especially as concerns the result returned from a verb call, so that it doesn't take you by surprise in some way.

You can learn the datatype of any object using the verb typeOf().

Main datatypes

The main datatypes are as follows. (There are others; you can learn what they are and find out more about them from the documentation, but these are the main ones to keep in mind.)

If you want to know the type of the binary's data, use the verb getBinaryType().


Prev | TOC | Next

All text is by Matt Neuburg, phd, matt@tidbits.com.
For information about the book Frontier: The Definitive Guide, see my home page:
http://www.tidbits.com/matt
All text copyright Matt Neuburg, 1997 and 1998. ALL RIGHTS RESERVED.
No one else has any right to copy or reproduce in any form, including electronic. You may download this material but you may not post it for others to see or distribute it to others without explicit permission from the author.
Downloadable versions at http://www.ojai.net/matt/downloads/scriptingTutorial.hqx and http://www.ojai.net/matt/downloads/scriptingTutorial.zip.
Please do not confuse this tutorial with a certain other Frontier 5 tutorial based upon my earlier work.
This page created with Frontier, 2/11/2000; 6:58:58 PM.