-
Notifications
You must be signed in to change notification settings - Fork 3
Transcode
Christopher Ross-Gill edited this page Aug 1, 2016
·
1 revision
The TRANSCODE function translates strings to values one "token" at a time.
In R3, the LOAD function is a mezzanine. This creates a problem for LOAD/next, which is a native operation. To solve the problem, TRANSCODE was added. This is a low level source-to-value translator.
Note that normal translation of source code is performed in LOAD by TO BLOCK!, not by TRANSCODE.
USAGE: TRANSCODE source DESCRIPTION: Translates code/data from string into value. Returns [value next-source]. TRANSCODE is a native value. ARGUMENTS: source -- (Type: string!)
For example:
>> transcode "1 2 3" == [1 " 2 3"]
Notice that TRANSCODE returns a block of the form:
[value rest-of-source]
Where value is the translated value, and rest-of source is where to continue translation for the next value.
Also note that TRANSCODE does not throw syntax errors, it will return them in the block (relaxed translation). The error will be followed with the continuation point in the source code.
For example:
>> probe transcode "1/2 print now" [make error! [ code: 200 type: 'Syntax id: 'invalid arg1: "date" arg2: "1/2" arg3: none near: "(line 1) print 1/2 print now" where: [transcode] ] "/2 print now"]