In this code snippet fields-types in the end is modified by to-camel-case function whereas it was passed as a local variable to the parent function:
fields-types: ["First Name" "string" "Last Name" "string" "Age" "int"]
to-camel-case: funct[name][
name/1: lowercase name/1
replace/all name " " ""
]
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
This is a side effect that I wouldn't expect. Couldn't something done in a next rebol version ?
Execution gives:
>> fill-template-body fields-types
== ["firstName" "string" "lastName" "string" "age" "int"]
>> fields-types
== ["firstName" "string" "lastName" "string" "age" "int"]
>>
whereas I would want that fields-types stays invariant:
fields-types: ["First Name" "string" "Last Name" "string" "Age" "int"]
Of course I can try to circumvent this by modifying to-camel-case to use a copy of name but this is not clean and bullet-proof for a language feature.
Maybe something like var and val keywords like in scala could exist.