Rebol 编程/闭包
外观
< Rebol 编程
CLOSURE spec body
定义闭包函数。
CLOSURE 是一个函数值。
- spec -- 帮助字符串(可选)后跟参数词(以及可选类型和字符串)(类型:块)
- body -- 函数的主体块(类型:块)
- 捕捉
closure: func [ "Defines a closure function." [catch] spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] "The body block of the function" /local spc bdy word ][ spc: make block! 1 + (2 * length? spec) insert/only spc [throw] bdy: make block! 5 + length? spec insert bdy reduce [:do :make :function! spc body] parse spec [any [ set-word! | set word any-word! ( insert tail bdy to word! :word insert tail spc to get-word! :word insert/only tail spc [any-type!] ) | skip ]] throw-on-error [make function! spec bdy] ]