7
nitwhiz
8y

Why `:=` instead of `=`?

Comments
  • 11
    1970 - Niklaus Wirth creates Pascal, a procedural language. Critics immediately denounce Pascal because it uses "x := x + y" syntax instead of the more familiar C-like "x = x + y". This criticism happens in spite of the fact that C has not yet been invented.

    http://james-iry.blogspot.co.uk/200...
  • 8
    Because := makes it clear that it is an assignement.
    = could be mistaken with a comparison. Also a = in a if clause could easily be overlooked as ==
    ;)
  • 2
    @alyx But doesn't `=` feel much more right?
    I mean maths taught us stuff like that?
  • 8
    I had an "== != =" sticker on my screen.
  • 1
    @TheSamsa okay i can get that.. might be the c-style thing that bothers me there. I guess back in the days such things were understood different.😊
  • 1
    @daintycode x:=y+z is defining x as y+z , while x=y+z is assigning the current value of y+z. Or at least this is what I remember to be taugh.
    So in the second case x would have a fixed value, while with the first you had a function x(y,z) that always changed with it's (implicit) parameters.
    So :
    Z=3
    Y=5
    A:=z+y
    B=z+y
    Z=4
    A has the value of 9.
    B is 8.
  • 1
    Because in math notation, when you want to define something, you use := instead of =.
    = should be used only for equations, when you're defining a variable or a function (still talking of math!) you should use the notation with colon.
  • 2
    Very interesting in this context is metafont/metapost. It makes a big difference between comparisons and assignments. So if you type:
    x=1
    y=3x
    y=4
    It will tell you that y is off by 1.
    Oh, and by the way: mf/mp understands things like: a+3b=c. If you give it more information like a=2 it uses all the relations between your variables to form a solution (or complains because of inconsistency).

    Anyways, it is possible to explicitely assign a value with, guess what, d:=3

    Metafont/metapost is great!
  • 1
    In maths, assignments to variables are :=. 1=1 is basically an if statement which HAS to be right...

    Pascal took this a step Fürther
Add Comment