Hos*_*ork 5 rebol object rebol3
而不是通过编写创建对象:
obj: object [
name: "Fork"
id: 1020
]
Run Code Online (Sandbox Code Playgroud)
我想写点像......
obj: something-or-another [name id] ["Fork" 1020]
Run Code Online (Sandbox Code Playgroud)
......并获得相同的结果.理想的解决方案还允许:
obj: something-or-another [name: id:] ["Fork" 1020]
Run Code Online (Sandbox Code Playgroud)
很容易写一个something-or-another,但这适合已经"在盒子里"的东西?
我不相信有一种现成的方法可以做到这一点。不过并不难:
func [words values][
set words: context append map-each word words [to set-word! word] none values
words
]
Run Code Online (Sandbox Code Playgroud)
我想我可以稍微分解一下:
func [
"Creates an Object From a Block of Words, Assigns Values"
words [block!] "Words used to create object"
values "Value(s) to assign"
][
words: map-each word words [to set-word! word] ; The requisite set-words
append words none ; Initial value for all words
words: context words ; Create our object
set words values ; Assigns our value(s) to the object
words ; returns the object
]
Run Code Online (Sandbox Code Playgroud)
您可以采用不同的方法来交错块,例如:
func [words [block!] values [block!]][
collect [
repeat index max length? words length? values [
keep words/:index
keep values/:index
]
]
]
Run Code Online (Sandbox Code Playgroud)