What is known about UTYPE! in REBOL 3?

The only information I can find in the UTYPE data type! "not yet documented for R3" and "user data type", still giving the hope that I can break out of the Rebol canon from predefined data types and formulate the polymorphism of my functions in a simpler way. Just ... I don't know how to deal with UTYPE !. Attempt:

make utype! <2nd-arg> 

with several types of arguments (including an object) invariably leads to the error "Script: invalid argument: <2nd-arg>".

So how to work with it? Is this feature implemented at all? And if not, is there any information on how it should work?

By the way, I know well that home valid data types can be modeled with constructs like:

 make object! [ class: ... value: ... ] 

Supplement written on November 8th:

A game with UTYPE effects! HELP:

 >> foo!: make utype! [[] [random: func [value] [42]]] >> type? foo! == utype! >> ? echo USAGE: ECHO target DESCRIPTION: Copies console output to a file. ECHO is a native value. ARGUMENTS: REBOL System Error: REBOL System Error #1224: assertion failed Program terminated abnormally. This should never happen. Please contact www.REBOL.com with details. 

(2.101.0.2.5 on the lion). Of course, something happens under the hood.

+4
types rebol rebol3
source share
2 answers

If you look at the source code of Rebol on github ( https://github.com/rebol/rebol/blob/25033f897b2bd466068d7663563cd3ff64740b94/src/core/t-utype.c ), then it is clear that this function has not yet been built.

Comment from the file header:

 ** Notes: NOT IMPLEMENTED 

A search for curecode.org returns a few comments that show the direction that is planned for the utype! data utype! .

There is a plan for adding custom data types β€” we even have a built-in type reserved for this, utype !. This will allow us to add new types of data that respond to actions that will even allow us to support their mathematical operations, if necessary. The only thing you won’t get is custom (non-tuning) syntax for the type or the ability to insert into the value slot. - BrianH

Source: http://curecode.org/rebol3/ticket.rsp?id=2137

+4
source share

You can try the experimental implementation here

Utypes are implemented as objects containing action methods and some natives. These methods are grouped into a sub-object .methods

 fraction!: make utype! [ num: 0 den: 1 .methods: object [ .multiply: func [ab] [ make fraction! [ num: a/num * b/num den: a/den * b/den ] ] .add: .... ] ] 

You can control the rendering through .form and .mold and compare through .compare . Math functions are also supported.

Full example complex module with relative demo

Any comments or suggestions are welcome!

+1
source share

All Articles