Home
About
Agents
CGIs
Mac
Macros
Misc
Stories
Suites
Websites
Outline
Frontier
Scripting

A New Keyword in Frontier 5

In version 5, we added a feature that allows you to build code that finds other code and data relative to the position of the script in the object database.

In the rush to get 5 out the door, this feature remains largely unknown. I hope to change that by publishing and explaining a small sample application.

It's called "this"

A new keyword called "this" is defined everywhere. When you use it in an expression, it resolves to the address of the script that contains it.

workspace.thisTest

This fat page contains a table called workspace.thisTest.

The table contains a script named getFavoriteColor and a sub-table called data.

The script is very simple, it's just one line of code:

dialog.ask ("What is your favorite color?", @parentOf (this^)^.data.favoriteColor)

Run the script. A dialog appears asking you to enter your favorite color.

It suggest orange because that is the string that's stored at workspace.thisTest.data.favoriteColor.

Why it's cool

You can move this table and getFavoriteColor will continue to work.

Try copying and pasting it into the scratchpad table and repeat the experiment.

For architects, mainly

I suggest you use this feature sparingly. It can make code harder to read. Only use it when position-independence is important, or when it's necessary to store code and data together in the same table.

Note that we generally discourage people from doing this because it makes it harder to update the code without disturbing the data.

But there are certainly times when position-independence offers flexibility that you can't get any other way.

Let's have fun!

Dave Winer
2/28/98


This is a fat web page containing workspace.thisTest. More info on fat pages here.

© copyright 1997-98 UserLand Software. This page was originally posted on 2/28/98; 5:40:58 AM and it was last built on 9/11/98; 9:23:16 AM. Webmaster: dave@userland.com.