POV-Ray : Newsgroups : povray.pov4.discussion.general : Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0) : Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0) Server Time
27 Jul 2024 07:46:08 EDT (-0400)
  Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)  
From: ingo
Date: 28 Jun 2024 05:25:00
Message: <web.667e80794bc5dc7517bac71e8ffb8ce3@news.povray.org>
"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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.