26

The section entitled Algorithmic Implementation has the following code:

// Return RC low-pass filter output samples, given input samples,
 // time interval dt, and time constant RC
 function lowpass(real[0..n] x, real dt, real RC)
   var real[0..n] y
   var real α := dt / (RC + dt)
   y[0] := x[0]
   for i from 1 to n
       y[i] := α * x[i] + (1-α) * y[i-1]
   return y

what does := mean?

  • 2
    I learned that it was from philosophy and logic notation, which defines it as ":= defined to be" so x := 1 is x is defined to be 1. – Patrick Hughes Jan 19 '12 at 06:13
  • 3
    When I took AP computer science in 1990, we used Pascal as our learning language. I always pronouced `:=` as "becomes equal to". I actually prefer this over `=` and `==` since "=" in natural language is a comparison operator (or at least a statement of truth.) – TecBrat Feb 14 '14 at 14:05

4 Answers4

61

:= is the assignment operator for languages that use single equals sign equality testing. The most well known of those languages is Pascal. Due to C's influence most languages switched to = for assignment and == for testing. Some older texts and authors that were trained in such styles use := for pseudocode. You sometimes see arrows <- as well for assignment.

From the article:

input: an array a of length n with array elements numbered 0 to n − 1

inc ← round(n/2)
while inc > 0 do:
    for i = inc .. n − 1 do:
        temp ← a[i]
        j ← i
        while j ≥ inc and a[j − inc] > temp do:
            a[j] ← a[j − inc]
            j ← j − inc
        a[j] ← temp
    inc ← round(inc / 2.2)

Some modern languages use arrows for assignment; most notably R, which uses it for global assignment whilst using the single equals ( = ) for local assignment.

From Sebesta's Concepts of Programming Languages and the class notes of Dr. K. N. King we learn that the assignment standards go back much farther than C or Pascal. It appears that in 1958 when Algol was being designed, it was decided to use := for assignment. The commitee was composed of American and European representatives. Some of the Germans on the committee were familiar with Konrad Zuse's Plankalkul language (which was drafted during World War II but not published until 1972 and not implemented until 2005) and wanted the assignment to follow that language's proposed assignment method which was b+c => a where b+c is assigned to a. The committee changed this to =: on the grounds that the method of entering programs at the time called a keypunch, did not have a ">" to use. So they compromised on the equals colon. However, the Americans being familiar with FORTRAN (it didn't have lower case until 1990) wanted the assignment to operate to the left since that was how FORTRAN did it.

So they managed to get it changed to := instead and had the assignment operate toward the left rather than the right in the style of FORTRAN (being a known implemented language) rather than Plankalkul (a virtually unknown language outside of Germany and not implemented). Algol 60 strongly influenced all major subsequent imperative languages including Pascal and C. Thus Pascal kept ALGOL's syntax for assignment and both kept the lefthandedness of assignment.

ALGOL was designed to be easy to read and close to mathematical notation. It was the de facto (and basically de jure) standard for writing algorithms in journals for next 20+ years. Therefore, instructors and computer scientists educated from 1960 to around 1980 would have been familiar with that style of notation.

The release of the IBM 029 Keypunch in 1964 allowed for > and < characters, thus prompting their inclusion in C among others.

  • 1
    Apart from missing semicolons and function return type this code anyway looks like PASCAL, MODULA or some other Wirth language. – Ingo Aug 17 '11 at 10:27
  • 7
    most pseudo codes use `:=` for assignment. people with mathematical background will favor this, too. – Rommudoh Aug 17 '11 at 10:55
  • 3
    Just to add that it is still very much used practically in PL/SQL. – Jalayn Aug 17 '11 at 11:39
  • 1
    don't know why, but left arrow as assignment just drives me mad 9 – shabunc Sep 22 '11 at 09:45
  • CrystalReports also uses this syntax. – Malfist Nov 14 '11 at 18:30
  • 2
    Pascal (and the rest of "the Wirth languages") got it from ALGOL, which got it from mathematical notation. – Mason Wheeler Jan 19 '12 at 04:06
  • I would tend to go for `==` for equality testing and `:=` for assignment, leaving a plain `=` for unusual cases like “is defined as” (because most programming languages don't let you use ≝ directly). – Donal Fellows Jan 19 '12 at 11:36
  • Cormen uses `<-` for assignment. – Kos Jan 24 '12 at 18:44
  • @Kos it would be interesting to know the origin of Cormen's use of it. –  Jan 24 '12 at 18:47
  • *":= is the assignment operator for languages that use single equals sign equality testing."* Except Visual Basic, for one, which uses `=` in both cases and relies on context to figure out what's desired... Alas. ;) – Dan J Jan 25 '12 at 00:11
18

Just a quick and pedantic note. Pseudocode is quite informal, so ":=" means only what you want it to mean. As others have said, specific languages such as Pascal use ":=" for assignment to avoid confusion with "=" for equality, whereas other languages use the combination of "=" and "==" for the same purpose.

As far as actual Pseudocode is concerned, you can use "=", "==", "equals", "is assigned to", ":=", "has", "receives", or whatever floats your boat, just so long as you are consistent, and the usage and context is within your pseudocode is clear.

S.Robins
  • 11,385
  • 2
  • 36
  • 52
6

I'm guessing it's assignment (I think it is the assignment operator in Delphi), so in y[0] := x[0] you're assigning the value of x[0] to y[0].

But AFAIK there's no such thing as a standard pseudo code, so in theory it could be anything :=).

  • That's what I thought too but I'm puzzled as to why they use := and not just = –  Aug 17 '11 at 10:09
  • 8
    @loudsight: Because `=` *already* has a *very different* meaning: equality. Using an operator which already has a well-understood meaning for something different would be extremely stupid. – Jörg W Mittag Aug 17 '11 at 10:20
  • 1
    @Jörg W Mittag Well I guess it depends on who the intended audience is. I would imagine for most developers (Java, C/C++, etc..) = means assignment. –  Aug 17 '11 at 11:36
  • 5
    @loudsight: Most developers weren't even born, when the first pseudo-code was written. Back then, it was mostly people from a strong mathematical background, who wrote down algorithms, which makes `:=` the natural choice, because in mathematical notation `x := v` means "let `x` be `v`" as opposed to `x = v`, which means "`x` equals `v`" and would therefore cause confusion. – back2dos Aug 17 '11 at 12:16
  • 8
    If there were a standard pseudo code, we would see lots of pseudo pseudo code. –  Dec 10 '11 at 09:45
  • 2
    @back2dos etc Even today using `=` for assignment is confusing. I can still remember, long ago when I first learnt to program, how confusing it was to see `x = x + 1`. Once you've studied basic high-school maths, `x = x + 1` just looks like impossible contradictory gibberish. Next I read an excellent book on computer science for the general reader ([I think it was this](http://www.amazon.co.uk/New-Turing-Omnibus-DEWDNEY/dp/0805071660)) which used `<-` for assignment. `x <- x + 1` is much easier to understand. – MarkJ Jan 24 '12 at 17:27
-1

It usually means the same thing it means in mathematics: assignment.

Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
  • 6
    There is no such thing as "assignment" in math to my knowledge. – Ingo Aug 17 '11 at 10:26
  • @Ingo never wrote one? – rsman Aug 17 '11 at 10:29
  • @Raj, indeed, never, though it may occur that one gets a math assignment :) – Ingo Aug 17 '11 at 10:32
  • 7
    in mathematics, `:=` usually means "is defined as" or "is equal by definition". – Rommudoh Aug 17 '11 at 10:58
  • 1
    @oenone Yes, and this is completely different from "write the bit pattern for the value of expression x to a memory location that is named y" – Ingo Aug 17 '11 at 11:00
  • i just wanted to clarify what the actuall meaning in math is. – Rommudoh Aug 17 '11 at 11:02
  • 3
    @Ingo: "write the bit pattern for the value of expression x to a memory location that is named y" is completely different from an assignment in programming languages. What you describe is a possible implementation of executing assignment statements. – back2dos Aug 17 '11 at 12:07
  • @back2dos - It is *the* implementation on the current architecture (i.e. register machines in different flavors), for which programming languages that have assignment were designed. – Ingo Aug 17 '11 at 12:43
  • 3
    @Ingo: I disagree. Let alone the fact, that in the case of properties, an assignment yields a call, and the fact that a vast part of code is executed in virtual machines or by interpreters, rather than directly on the "current architecture", even assignments to variables need not result in such an operation, due to optimization. With few exceptions, a language should be used according to its specifications and not based on some assumptions about its implementation. All you can really say about assignments to variables is that the variable named y is rebound to the value of the expression x. – back2dos Aug 17 '11 at 13:49
  • 1
    @back2dos Sorry, but that's nonsense. Then it would not be called assignment, but binding (like it is indeed called in Haskell). All currently existing imperative languages build on the concept of overwritable, adressable memory. A virtual machine like for example the JVM is itself just another incarnation of the same concept. – Ingo Aug 17 '11 at 14:05
  • 3
    @Ingo: No, it's not nonsense. Compiling `x := 1; y := 2; if (x = 1) y := 3` as if it just were `y := 3` is a reasonable optimization (assuming x is not used later on). Of 3 assignments 2 are implemented by means of static analysis. Your "definition" of assignments is a blanket statement, that simply doesn't hold without numerous assumptions a definition of this term should not have to depend upon. – back2dos Aug 17 '11 at 14:32
  • 1
    @back2dos Whether this is a reasonable optimization or not depends on the language. The language defines the effects of assignments (and this invariably boils down to an overwrite of a memory location) and a correctly compiled program must behave as if all assignments are indeed done, i.e. as if no optimization was done. Therefore, a possible optimization cannot change the meaning of assignment - it just rewrites a program like the above one to a presumably more efficient one that does not contain assignments that have no observable effect. – Ingo Aug 17 '11 at 14:40
  • 1
    A variable could also be stored in a register, C does that all the time. – user281377 Jan 19 '12 at 07:24
  • Saw an interesting presentation by McCarthy (the AI pioneer) once, a mathematical expression of programming. Variables were represented by sequences, and a program was a method for determining the next value in all the sequences. `a := b` would translate into `a(n+1) = b(n); for all other x, x(n+1) = x(n)`. IIRC, he called these notations ALGOL-48 and ALGOL-50. – David Thornley Jan 19 '12 at 16:24