在此代码片段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
and关键字的东西?val