|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I dunno - I'm not really a computer language person, but the pro's and cons of
> each approach ought to be hashed out with an eye towards Pov-Ray 4.0
>
Just as an example how it works in an other language. In the Nim programming
language the following will not work as all proc parameters are immutable int
types. With Nim procs immutable arguments is the default, unless one uses "var":
proc dothing(a: int, b: int): int =
a = a + b
return a
let
a = 1
b = 2
let res = dothing(a, b)
This one will work as c is declared and assigned a value, c is immutable (let)
proc dothing(a: int, b: int): int =
let c = a + b
return c
let
a = 1
b = 2
let res = dothing(a, b)
This will work as a is now of type var int, a mutable variable:
proc dothing(a: var int, b: int): int =
a = a + b
return a
var a = 1
let b = 2
a = dothing(a, b)
In the last example 'a' is 'var' in the proc and 'a' has to be "declared" as
'var', else the Nim compiler nags.
Changing a variable "declared" using 'let' into a 'var', or the other way
around, is not possible.
N.B. the last two examples can coexist next to each other in one file/program.
Depending on whether 'a' is a 'var' or not, the compiler chooses the proper
proc.
ingo
Post a reply to this message
|
|