Pseudo Code – What Does := Mean?

algorithms

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?

Best Answer

:= 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.

Related Topic