What to call "variables"

classic Classic list List threaded Threaded
34 messages Options
12
Reply | Threaded
Open this post in threaded view
|

What to call "variables"

L Boyd
I see multiple question from those new to OpenSCAD about what we call variables. They are confused because they are different from the variables used in many programming languages. They don't understand why the can't do a=a+1.

They are not really constants either, because they can be overridden locally within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing the manual.
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

Alan Cox
On Tue, 30 Aug 2016 05:09:39 -0700 (MST)
L Boyd <[hidden email]> wrote:

> I see multiple question from those new to OpenSCAD about what we call
> variables. They are confused because they are different from the variables
> used in many programming languages. They don't understand why the can't do
> a=a+1.
>
> They are not really constants either, because they can be overridden locally
> within inner scopes.
>
> Perhaps we should use an unfamiliar name, so that they have to read the
> definition for how to use them.
>
> I don't have any suggestions, but we need to discuss this before changing
> the manual.

They are constants but they are scoped. No different to C

const x = 1

static void foo(void)
{
        const x = 4;

        blah;
}



Or perhaps think of them as functions or macros, they are really just an
expansion.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

L Boyd
Alan Cox wrote
On Tue, 30 Aug 2016 05:09:39 -0700 (MST)
L Boyd <[hidden email]> wrote:

> I see multiple question from those new to OpenSCAD about what we call
> variables. They are confused because they are different from the variables
> used in many programming languages. They don't understand why the can't do
> a=a+1.
>
> They are not really constants either, because they can be overridden locally
> within inner scopes.
>
> Perhaps we should use an unfamiliar name, so that they have to read the
> definition for how to use them.
>
> I don't have any suggestions, but we need to discuss this before changing
> the manual.

They are constants but they are scoped. No different to C

const x = 1

static void foo(void)
{
        const x = 4;

        blah;
}



Or perhaps think of them as functions or macros, they are really just an
expansion.

Alan

True, but they are also more

for (a =[3:5])echo(a);     // 3 4 5

The question is what word should be used in the manual.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

frankv
In reply to this post by L Boyd
Why NOT make them behave like variables in other languages and allow a = a + 1 ?


On Wed, Aug 31, 2016 at 12:09 AM, L Boyd <[hidden email]> wrote:
I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the variables
used in many programming languages. They don't understand why the can't do
a=a+1.

They are not really constants either, because they can be overridden locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.



-----
Larry
--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

DanS
In reply to this post by L Boyd

"Constants within a scope"?

That would describe them.

On Aug 30, 2016 8:10 AM, "L Boyd" <[hidden email]> wrote:
I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the variables
used in many programming languages. They don't understand why the can't do
a=a+1.

They are not really constants either, because they can be overridden locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.



-----
Larry
--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

Michele
In reply to this post by frankv
On 08-30-2016 2:18 PM, Frank van der Hulst wrote:
> Why NOT make them behave like variables in other languages and allow a
> = a + 1 ?
I second that.

             - Michele


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

Ronaldo
In reply to this post by frankv
Why NOT make them behave like variables in other languages and allow a = a + 1 ?
Because there is no assignment in OpenSCAD. When you write:
     a = 10;
in OpenSCAD, this is a definition, like in math, not an assignment. Assignments are the cause of many misleading code and many languages restrict their effects. Functional programming languages have no variables neither assignments. We don't need them.
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

jdawgaz

On Tue, Aug 30, 2016 at 12:06 PM, Ronaldo <[hidden email]> wrote:
> Why NOT make them behave like variables in other languages and allow a = a
> + 1 ?

Because there is no assignment in OpenSCAD. When you write:

>      a = 10;

in OpenSCAD, this is a definition, like in math, not an assignment.
Assignments are the cause of many misleading code and many languages
restrict their effects. Functional programming languages have no variables
neither assignments. We don't need them.

excuse me? There are assignments in Functional programming languages.
And yes, we really could use them. Functional programming languages in simple terms make a 
difference between where the variable (in memory) is, and the value that points
to it.

So, why have true variables only in certain circumstances (like for loops, arguments in module calls, functions, etc), and not in others.
If a value could be assigned to a "variable" at any time, then the controversy would just go away.

Jerry




--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

doug.moen
In reply to this post by L Boyd
OpenSCAD is a mathematical notation for describing geometric shapes. It's not a general purpose programming language.

OpenSCAD's use of the term "variable" is consistent with the meaning of "variable" in mathematics, and in pure functional programming languages. The word "variable" in mathematics and formal logic has a distinguished history going back hundreds of years, and I don't think there's a problem using that word with its traditional meaning.

The terminology I'd get rid of instead is "assignment statement". I consider `x = 1;` to be a "definition" of `x`. It's a mathematical equation that defines the meaning of `x` within its scope. The underlying mathematical reason that `x = x + 1;` is invalid is because this is not a valid equation defining `x`. There is no number `x` that is equal to itself plus 1.

On 30 August 2016 at 08:09, L Boyd <[hidden email]> wrote:
I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the variables
used in many programming languages. They don't understand why the can't do
a=a+1.

They are not really constants either, because they can be overridden locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.



-----
Larry
--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

Don Wooton-2
How about having a warning message something like
    WARNING Value reassigned: line 6
and a preferences to turn this one warning off.  If the warning
is on by default, it may cause the new user to notice that this
procedure is not expected and to look in the manual.

    - Don

On Aug 30, doug moen propounded certain bytes, to wit:

> Subject: Re: [OpenSCAD] What to call "variables"
>
> OpenSCAD is a mathematical notation for describing geometric shapes. It's
> not a general purpose programming language.
>
> OpenSCAD's use of the term "variable" is consistent with the meaning of
> "variable" in mathematics, and in pure functional programming languages.
> The word "variable" in mathematics and formal logic has a distinguished
> history going back hundreds of years, and I don't think there's a problem
> using that word with its traditional meaning.
>
> The terminology I'd get rid of instead is "assignment statement". I
> consider `x = 1;` to be a "definition" of `x`. It's a mathematical equation
> that defines the meaning of `x` within its scope. The underlying
> mathematical reason that `x = x + 1;` is invalid is because this is not a
> valid equation defining `x`. There is no number `x` that is equal to itself
> plus 1.
>
> On 30 August 2016 at 08:09, L Boyd <[hidden email]> wrote:
>
> > I see multiple question from those new to OpenSCAD about what we call
> > variables. They are confused because they are different from the variables
> > used in many programming languages. They don't understand why the can't do
> > a=a+1.
> >
> > They are not really constants either, because they can be overridden
> > locally
> > within inner scopes.
> >
> > Perhaps we should use an unfamiliar name, so that they have to read the
> > definition for how to use them.
> >
> > I don't have any suggestions, but we need to discuss this before changing
> > the manual.
> >
> >
> >
> > -----
> > Larry
> > --
> > View this message in context: http://forum.openscad.org/
> > What-to-call-variables-tp18260.html
> > Sent from the OpenSCAD mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > [hidden email]
> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >
> >
> >

> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

>-- End of excerpt from doug moen'

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

jon_bondy
In reply to this post by doug.moen

While "variable" may have a long history in math and logic, we are dealing with a programming language here, and the term "variable" has a common meaning that is, unfortunately, different than what is intended in OpenSCAD.  I think calling those beasts "named constants" is the closest we will come, and it will be much less confusing (to a programmer) than "variable".  We need to document for the intended audience.

IMHO, of course.  Goes without saying

Jon


On 8/30/2016 4:14 PM, doug moen wrote:
OpenSCAD is a mathematical notation for describing geometric shapes. It's not a general purpose programming language.

OpenSCAD's use of the term "variable" is consistent with the meaning of "variable" in mathematics, and in pure functional programming languages. The word "variable" in mathematics and formal logic has a distinguished history going back hundreds of years, and I don't think there's a problem using that word with its traditional meaning.

The terminology I'd get rid of instead is "assignment statement". I consider `x = 1;` to be a "definition" of `x`. It's a mathematical equation that defines the meaning of `x` within its scope. The underlying mathematical reason that `x = x + 1;` is invalid is because this is not a valid equation defining `x`. There is no number `x` that is equal to itself plus 1.

On 30 August 2016 at 08:09, L Boyd <[hidden email]> wrote:
I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the variables
used in many programming languages. They don't understand why the can't do
a=a+1.

They are not really constants either, because they can be overridden locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

Ronaldo
In reply to this post by jdawgaz
On Tue, Aug 30, 2016, 16:28 —  jdawgaz  wrote:
excuse me? There are assignments in Functional programming languages.
And yes, we really could use them. Functional programming languages in simple terms make a
difference between where the variable (in memory) is, and the value that points
to it.
I am far from being an expert in programming languages and I don't want to start a controversy.

According to wikipedia:
Any assignment that changes an existing value (e.g. x := x + 1) is disallowed in purely functional languages.[4] In functional programming, assignment is discouraged in favor of single assignment, also called initialization. Single assignment is an example of name binding and differs from assignment as described in this article in that it can only be done once, usually when the variable is created; no subsequent reassignment is allowed.
Named constant seems fair to me.
On Tue, Aug 30, 2016, 16:28 —  jdawgaz  wrote:
So, why have true variables only in certain circumstances (like for loops, arguments in module calls, functions, etc), and not in others.
If a value could be assigned to a "variable" at any time, then the controversy would just go away.
In none programming language I know, function and procedure arguments are called variables. They are a way to reference values. In OpenSCAD for statements, the identifier that index the iteration is just a named reference of a value in a list or range inside a specific scope. It is not a true variable.

Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

MichaelAtOz
Administrator
In reply to this post by L Boyd
L Boyd wrote
True, but they are also more

for (a =[3:5])echo(a);     // 3 4 5
Remember this is not an iterative language, the for() does not loop in the programmatic sense, it builds a tree of objects one branch for each representation of the loop 'identifier', inside each of which the 'variable' is a specific and seperate instantiation of that 'identifier'.

So:

for (i=[0:3])
        translate([i*10,0,0])
                cube(i+1);

Produces:

group() {
        group() {
                multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [1, 1, 1], center = false);
                }
                multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [2, 2, 2], center = false);
                }
                multmatrix([[1, 0, 0, 20], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [3, 3, 3], center = false);
                }
                multmatrix([[1, 0, 0, 30], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [4, 4, 4], center = false);
                }
        }
}

All instances of the for() exist at the same time, they do not iterate sequentially.


In imperative programming languages 'variable' by definition can vary, thus they also have 'constants' which can't. {corollary to Murphy's law: variable won't & constants aren't}
{wikipedia} "In pure functional and logic languages,variables{*1} are bound to expressions and keep a single value during their entire lifetime due to the requirements of referential transparency", but it is common to use the term 'variable' even tho they don't, and they don't generally have the concept of 'constants'.

So technically, as a declarative language, 'variable' as a term IS appropriate, but for imperative programmers 'constant' would be better.

{*1} I'd argue that wikipedia definition is wrong, it should be " 'identifiers' are bound to ..."

So how about, in the manual, we use the term 'identifier', and expunge 'variable'? Also any reference to 'assignment' changes to 'binding'.

?
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

L Boyd
I know how OpenSCAD variables work and don't personally have a problem with the name.

Having said that, imperative programmers, new to OpenSCAD, stumble on this. They assume the terms variable and constant have the meaning they are use to.

In their view, our variables are neither, but fall somewhere in between.

Perhaps semiconstant?
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

DanS

What's wrong with "scoped constant" . Only uses two words and it describes the behavior.  Variables is definitely extremely misleading.

On Aug 31, 2016 9:23 AM, "L Boyd" <[hidden email]> wrote:
I know how OpenSCAD variables work and don't personally have a problem with
the name.

Having said that, imperative programmers, new to OpenSCAD, stumble on this.
They assume the terms variable and constant have the meaning they are use
to.

In their view, our variables are neither, but fall somewhere in between.

Perhaps semiconstant?



-----
Larry
--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18281.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

L Boyd
In reply to this post by MichaelAtOz
Interesting possibility.

MichaelAtOz wrote
So how about, in the manual, we use the term 'identifier', and expunge 'variable'? Also any reference to 'assignment' changes to 'binding'.?
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

lhartmann
In reply to this post by DanS
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

L Boyd
In reply to this post by DanS
DanS wrote
What's wrong with "scoped constant" . Only uses two words and it describes
the behavior.  Variables is definitely extremely misleading.
 
Excellent idea. It correctly describes their behavior, while flagging the difference from constants in many imperative programming languages.

That makes 2 votes, how about anyone else?
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

L Boyd
In reply to this post by MichaelAtOz
Good description, better than what I wrote in the manual.

MichaelAtOz wrote
Remember this is not an iterative language, the for() does not loop in the programmatic sense, it builds a tree of objects one branch for each representation of the loop 'identifier', inside each of which the 'variable' is a specific and seperate instantiation of that 'identifier'.

So:

for (i=[0:3])
        translate([i*10,0,0])
                cube(i+1);

Produces:

group() {
        group() {
                multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [1, 1, 1], center = false);
                }
                multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [2, 2, 2], center = false);
                }
                multmatrix([[1, 0, 0, 20], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [3, 3, 3], center = false);
                }
                multmatrix([[1, 0, 0, 30], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
                        cube(size = [4, 4, 4], center = false);
                }
        }
}

All instances of the for() exist at the same time, they do not iterate sequentially.
Larry
Reply | Threaded
Open this post in threaded view
|

Re: What to call "variables"

runsun
In reply to this post by lhartmann
lhartmann wrote
Why not call them symbols, as in symbolic math?
+1
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
12