【发布时间】:2010-07-31 13:29:33
【问题描述】:
在这段代码sn-p中,fields-types最后被to-camel-case函数修改,而不是作为局部变量传递给父函数:
fields-types: ["First Name" "string" "Last Name" "string" "Age" "int"]
to-camel-case: function [name] [
name/1: lowercase name/1
replace/all name space ""
]
fill-template-body: func [
field-labels-types [block!] /local vars fields-names-types
] [
vars: [member-name member-type]
field-names-types: copy []
foreach [field-label field-type] field-labels-types [
append field-names-types to-camel-case field-label
append field-names-types field-type
]
]
fill-template-body fields-types
执行给出:
>> fill-template-body fields-types
== ["firstName" "string" "lastName" "string" "age" "int"]
>> fields-types
== ["firstName" "string" "lastName" "string" "age" "int"]
>>
而我希望字段类型保持不变:
fields-types: ["First Name" "string" "Last Name" "string" "Age" "int"]
当然,我可以尝试通过修改 to-camel-case 以使用名称副本来规避这一点,但我认为我不应该这样做。
Scala 中有类似 var 和 val 关键字的东西吗?
【问题讨论】: