[p-dev] Variable scoping

Paul Bone paul at bone.id.au
Tue May 21 11:02:43 AEST 2019


On Mon, May 20, 2019 at 02:18:54PM +0000, Gert Meulyzer wrote:
> My thoughts on this:
> 
> On Mon, May 20, 2019 at 2:03 PM Paul Bone <paul at bone.id.au> wrote:
> 
> >
> >     if (...) {
> >         x = ...
> >     } else {
> >         x = ...
> >     }
> >     print!(x)   % We can use x here.
> >
> > This is indeed not what you expect for this kind of syntax.
> All other languages that have this syntax will throw you an error.
> People will indeed expect this to be the case.

Yeah, I think this decision is pretty clear.  I guess it was a bias that
held me to Mercury style for longer.


> The main counter-proposal I have is:
> >
> >     var x
> >     if (...) {
> >         x = ...
> >     } else {
> >         x = ...
> >     }
> >     print!(x)   % We can use x here.
> >
> >
> 
> Bad: More verbose than necessary
> >
> 
> More verbose, yes, but perhaps more clear what is happening.

True.

> Interesting: "var" is a weird keyword for something that doesn't vary.  But
> >              I think here's where we make another pragmatic choice and do
> >              call them variables.
> >
> 
> Why not call them 'val' then? As in values?
> There are languages that do this. (Scala, iirc)
> That makes it super clear, but not sure if this is 'in theme' for the
> current Plasma vocabulary?

I think when describing these things we're still likely to slip and say
"variables".  But the "save" icon is still a floppy disk so *shrug*.  Let's
try the "val" keyword and see how that works.

I also considered:

 * let, but it's not really a let expression.
 * const, I think this is more familiar at the time that you're setting the
          value.  And when non-const is the default.


-- 
Paul Bone
http://paul.bone.id.au


More information about the dev mailing list