0.6.3.-=== Red Compiler 0.6.3 ===- now, but still the same error with do %run-all.red do %run-all.r as stated in the readme%run-all.red?face/para/scroll field.view [text left "line1^/line2^/line3" with [para/scroll: 4x10]]
load/next seems to not catch errors, what am I doing wrong ?>> load/trap ",,"
== [[] ",," make error! [
code: 200
type: 'syntax
id: 'i...
>> load/trap/next ",," 'err
== [[] ",," none]
>> ?? err
err: [[] ",," none]/trap and /next are mutually exclusive, as the doc string for /trap says it loads all values. It works as expected, and doesn't error out, but returns the information about errors to you.>> load/trap ",,"
== [[] ",," make error! [
code: 200
type: 'syntax
id: 'invalid
arg1: 'value
arg2: ",,"
arg3: none
nea...
>> load ",,"
*** Syntax Error: invalid value at ",,"
*** Where: do
*** Stack: load>> print mold load/trap "1 a [] ,, 2 b ()"
[[1 a []] ",, 2 b ()" make error! [
code: 200
type: 'syntax
id: 'invalid
arg1: 'value
arg2: ",, 2 b ()"
arg3: none
near: none
where: 'do
stack: 77957712
]]load/trap is an *alternative* to load/next, where you get 0 or more loaded values, the position to continue from, and whether there was an error or not, to know if you need to continue. load/next allows the loading of a string bit by bit but never throws back errors if any. So, we can’t track the position of a syntax error in the string.load/next does not advance the string position in the case of a syntax error (clearly a bug or a missing feature).Load/trap loads a complete string (like a script) and emits only one syntax error as an object if any (the first encountered one).do to test the interpreter: --assert error? try do [...]>> do/args %run-test.r to-rebol-file "C:\dev\greggirwin\red\tests\source\units\function-test.red"
Script: "Builds and Runs a single Red/System Tests" (none)
Script: {Simple testing framework for Red and Red/System programs} (none)
Script: "Untitled" (none)
Quick-Test v0.12.0
Running under REBOL 2.7.8.3.1
~~~started test~~~ function
~~~finished test~~~ function
Number of Tests Performed: 115
Number of Assertions Performed: 138
Number of Assertions Passed: 138
Number of Assertions Failed: 0signify failure ~~~started test~~~ run-all-interp 1 *** Script Error: invalid function definition: return: *** Where: func *** Stack:
function-test.red in a gist? I can then take a look===start-group=== "function spec validation"
--test-- "fsv1"
--assert function? func [][]
--test-- "fsv2"
--assert function? func [a [integer!] "doc a" b [string!] "doc b" /c d [block!] "doc d" e return: [integer!]][]
--test-- "fsv3"
--assert function? func [a [integer!] "doc a" b [string!] "doc b" /c d [block!] "doc d" e][]
--test-- "fsv4"
--assert function? func [a [integer!] "doc a" b [string!] "doc b" /c d [block!] "doc d"][]
--test-- "fsv5"
--assert function? func [a [integer!] "doc a" b [string!] "doc b" /c d [block!]][]
--test-- "fsv6"
--assert function? func [a [integer!] "doc a" b [string!] "doc b" /c d][]
--test-- "fsv7"
--assert function? func [a [integer!] "doc a" b "doc b"][]
--test-- "fsv8"
--assert function? func [a [integer!] "doc a" b [string!]][]
--test-- "fsv9"
--assert function? func [a [integer!]][]
--test-- "fsv10"
--assert function? func [a "doc a"][]
; DO is used here, because the compiler will correctly catch errors the interpreter doesn't.
; --test-- "fsv11"
; --assert error? try [do [func [a [integer!] returns: [integer!]][]]]
; --test-- "fsv12"
; --assert error? try [do [func [a [integer!] return:][]]]
; --test-- "fsv13"
; --assert error? try [do [func [a return: [integer!] b][]]]
; --test-- "fsv14"
; --assert error? try [do [func [a return: [integer!] /c][]]]
; --test-- "fsv15"
; --assert error? try [do [func [a return: b][]]]
===end-group===Red[] print error? try [do [func [a [integer!] returns: [integer!]][]]]
return: [...] was the last thing in the spec. TYPE_SET_WORD [ w: as red-word! value if words/return* <> symbol/resolve w/symbol [ fire [TO_ERROR(script bad-func-def) w] ] next: value + 1 next2: next + 1 unless all [ next < end TYPE_OF(next) = TYPE_BLOCK next2 = end ;**** This makes it unhappy **** ][ fire [TO_ERROR(script bad-func-def) value] ] value: next ]
/local can follow the return.function.reds, it might be easier to add the check that return: follows the other parameters in calc-arity which is already ignoring anything after it comes across a set-word. return:single responsibility perspective.calc-arity, it won't catch that. Just need to learn how to check the symbol match as /local. return:?text >> f: func [a return: [integer!] /b c] [either b [print c] [print a] ] == func [a return: [integer!] /b c][either b [print c] [print a]] >> f 1 1 >> f/b 1 3 3
function.reds suggests so to me ... but I could be wrong.3 >> f: func [a return: [integer!] /b c return: [float!]] [either b [print c] [pri== func [a return: [integer!] /b c return: [float!]][either b [print ... >> f 1 1 >> f/b 1 3.0 3.0 >> f/b 1 3 3
Red[] f: func [ /int i [integer!] return: [integer!] /flt f [float!] return: [float!] ] [ if int [ return i ] if flt [ return f ] ] print f/int 1 print f/flt 2.0
== func [
/int
i [integer!] return: [integer!] /flt
f [...
>> f/int 1
== 1
>> f/flt 3.0
*** Script Error: f has no refinement called flt
*** Where: f
*** Stack: fred/specs. Are we going towards completely free form, i.e. arguments, refinements and return spec may occur in any order??