C++ doesn't have:

ALGOL 68 doesn't have:

Comparison of the assignment and equality operators

IntentALGOL 68C++
Define a constantint x=888;const int x = 888;
Initialise a variableint x:=888;int x = 888;
Assign a value 888 to a variable xx:=888;x = 888;
Compare two valuesif x = 888 then ... fiif (x == 888) { ... }
Allocate a variable from the heapref int x = heap int;
or simply:
heap int x;
int* x = new int;
Compare address of two pointersref int x, y;
if x :=: y then ... fi
int* x; int* y;

if (x == y) { ... }

Compare value referenced by two pointersref int x, y;
if x = y then ... fi
int* x; int* y;

if (*x == *y) { ... }

Name a new typemode longreal = long real;typedef double longreal;
or (as of C++11):
using longreal = double;
Name a new record typemode cust = struct(string name, address);struct cust { std::string name, address; };
Name a new union typemode taggedu = union(string s, real r);union u { std::string s; float f; };
Name a procedure or functionproc f = (real x) real: ( code; result );float f(float x) { code; return result; }
Procedure default parametersproc p = (union (real, void) in x)void:

    ( real x = (in x|(real x):x|888); code );

void p(float x=888) { code; }
Name a new operatorop ↑ = (real x,y) real: x**y;
Set priority on a new operatorprio ↑ = 9;
Chain variables assignmenta:=b:=c:=d;a = b = c = d;
Displacement operator - ALGOL 68C onlya:=:=b:=:=c:=:=d;a = b; b = c; c = d;
Append "substr" to a variable strstr +:= "substr";str += "substr";
Prefix "substr" to a variable str"substr" +=: str;str = "substr" + str;

Code Examples

Union declaration and use

Assigning values into an A68 union variable is automatic, the type is "tagged" to the variable, but pulling the value back out is syntactically awkward as a conformity-clause is required.

ALGOL 68 example:

 union(int, char) x:=666;
 printf(($3d l$, (x|(int i):i) ))

C++ example:

  union { int i; char c; } x = { 666 };
  std::cout << x.i << std::endl;

The net effect of "type-tagging" is that Algol68's strong typing "half" encroaches into the union.

Mode declaration

A new mode (type) may be declared using a mode declaration:

int max=99;
mode newtype = [0:9][0:max]struct (
   long real a, b, c, short int i, j, k, ref real r
);

This has the similar effect as the following C++ code:

const int max=99;
typedef struct { 
    double a, b, c; short i, j, k; float& r;
} newtype[9+1][max+1];

Note that for ALGOL 68 only the newtype name appears to the left of the equality, and most notably the construction is made - and can be read - from left to right without regard to priorities.

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.