Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you define your own datatype in Rebol?

Tags:

rebol

Seeing as you can limit the parameters of functions to specific datatypes, it stands to reason that you might want to define your own datatype, yet I cannot see anything in the Rebol docs that suggests this as a feature of the language (unless I didn't look very well).

What I am expecting is the ability to do something like the following:

mytype!: make datatype! ... ; some spec here

Is this possible? The following does not fill me with much hope:

http://www.rebol.it/giesse/custom-types.r

From the link:

Purpose: { Allows the programmer to define custom REBOL datatypes }

It is a rather lengthy piece of code. Not what I was hoping for.

like image 473
mydoghasworms Avatar asked Jan 19 '15 13:01

mydoghasworms


1 Answers

Tried an implementation of utypes in https://github.com/giuliolunati/rebol/tree/utype

As an example, I implemented complex! utype

Basically, utypes are implemented as objects with special methods in dotted form: so, .add implements the + op etc.

For now you can overload all actions (but make), and some natives (math functions, comparison, form, mold, print, probe)

like image 190
giuliolunati Avatar answered Sep 23 '22 11:09

giuliolunati