Sunday, July 15, 2007

a note on Polymorphism in Rebol and Oz

I have put a page on Polymorphism in Rebol and Oz with some mention of Strongtalk at eclectic-pencil

It really does not do justice to the richness of Rebol and may presuppose some familiarity with Smalltalk. All are available as freeware on the web.

If you work in JavaScript or C# there will be a lot to interest you in the trio of Oz, Strongtalk and Rebol. TiScript, for example, is a JavaScript variant which rejects prototype-based in favor of simple modules.
If you are looking at the new languages coming available for .NET and VisualStudio and want to see multi-paradigm programming then Oz is the place to start.
If you find you don't quite get Oz and the whole Emacs thing, start with Rebol.
If you don't want another way to think about web programming, just an alternative to JavaScript+CSS+HTML+whatever, download the Curl RTE and IDE.
I had been almost sold on XUL + JavaScript or XAML + C# and then I took a look at both Rebol and Curl.
In the next few days I will post something on the beauty of "Quick" Tk in Oz. If you were ever taken with Logtalk+Prolog or Datalog+RDF you will appreciate td(...) and lr( ...) as td( lr( ... )) i.e. layout of widgets is top-down and left-right...

4 comments:

Andrew Fedoniouk said...

TIScript does not reject prototypes.

Consider this:

type Foo // a.k.a. class Foo
{
function this(x) { this.x = x; }
}

type Bar
{
function do_something() { ... }
}

var v = new Foo(1);
// v is a Foo now

v.prototype = Bar;
// and now v is an object of class Bar

So (v instanceof Bar) is true and
call of v.do_something() will do something.

So TIScript is a prototype based language.

KanjiRecog said...

But with the critical difference that the prototype is a type [ aka class or module ]
Dynamically changing superclass is not enough to be 'prototype-based' even if that dynamic super type is called the 'prototype'.
To quote your web site,
"This schema of instance-of relationship is simpler and thus different from the one used in JavaScript"
This is not a cloned object serving as a prototype, which is the accepted meaning of 'prototype-based'. That said, the TiScript direction seems to be where ECMAScript is headed ... to being type-based and not prototype- based.

Andrew Fedoniouk said...

Robert, let's put it this way: TIScript is prototype based at the same extent as JavaScript is.

Difference is in this:

var s = "something";

In JS following is true:

s.__proto__ = String.prototype;

And in TIS we have simply:

s.prototype = String;

So in TIS field 'prototype' is just a reference to object's class object.

JS uses special __proto__ object that points to special prototype "rack" (object) that is attached to "class" object.

I simplified this schema in TIS so it looks more human comprehensible and traditional if you wish - you have class and you have ctor function there for constructing instances. And each instance has reference to the class (that is object too).

Andrew Fedoniouk said...

"This is not a cloned object serving as a prototype, which is the accepted meaning of 'prototype-based'."

In modern JS following:

var foo = new Bar();

is not cloning anything, it does following (roughly):

foo = new Object();
foo.__proto__ = Bar.prototype;
Bar(foo [as this variable]);