Revision as of 21:52, 17 September 2010 edit211.31.53.16 (talk) fix broken sublinks← Previous edit | Revision as of 23:37, 21 September 2010 edit undoYobot (talk | contribs)Bots4,733,870 editsm WP:CHECKWIKI error 26 + genfixes using AWB (7165)Next edit → | ||
Line 3: | Line 3: | ||
C++ doesn't have: | C++ doesn't have: | ||
* ] - first class nested functions (emulation due to local definitions of class-types, which then could be ]) , | * ] - first class nested functions (emulation due to local definitions of class-types, which then could be ]) , | ||
* ] - definable operator symbols and priorities, | * ] - definable operator symbols and priorities, | ||
* garbage collection, | * garbage collection, | ||
Line 17: | Line 17: | ||
ALGOL 68 doesn't have: | ALGOL 68 doesn't have: | ||
* public/private struct member access protection, | * public/private struct member access protection, | ||
* ] (in contrast to operators), | * ] (in contrast to operators), | ||
* explicit memory deallocation, <!-- instead, GC --> | * explicit memory deallocation, <!-- instead, GC --> | ||
* forward declarations (use before definition is allowed) | * forward declarations (use before definition is allowed) | ||
Line 56: | Line 56: | ||
| void p(float x=888) { code; } | | void p(float x=888) { code; } | ||
|- | |- | ||
|Name a new operator || '''op''' |
|Name a new operator || '''op''' ↑ = ('''real''' x,y) '''real''': x**y; || ''n/a'' | ||
|- | |- | ||
|Set priority on a new operator || '''prio''' |
|Set priority on a new operator || '''prio''' ↑ = 9; || ''n/a'' | ||
|- | |- | ||
|Duplication by assignment || a:=b:=c:=d; || a = b = c = d; | |Duplication by assignment || a:=b:=c:=d; || a = b = c = d; | ||
Line 76: | Line 76: | ||
syntactically awkward as a ''conformity-clause'' is required. | syntactically awkward as a ''conformity-clause'' is required. | ||
'''ALGOL 68 example:''' | |||
<code> | <code> | ||
'''union'''('''int''', '''char''') x:=666; | '''union'''('''int''', '''char''') x:=666; | ||
printf(($3d l$, (x|('''int''' i):i) ))</code> | printf(($3d l$, (x|('''int''' i):i) ))</code> | ||
'''C/C++ example:''' | |||
<source lang="cpp"> | <source lang="cpp"> | ||
union { int i; char c; } x = { 666 }; | union { int i; char c; } x = { 666 }; | ||
Line 112: | Line 112: | ||
* - Apr 2004 - retrieved May 10, 2007 | * - Apr 2004 - retrieved May 10, 2007 | ||
{{DEFAULTSORT:Comparison Of Algol 68 And C++}} | |||
] | ] | ||
] | ] |
Revision as of 23:37, 21 September 2010
The nearest living sibling to ALGOL 68 may be C++, making this a good comparison candidate:
C++ doesn't have:
- PROC - first class nested functions (emulation due to local definitions of class-types, which then could be functors) ,
- OP and PRIO - definable operator symbols and priorities,
- garbage collection,
- use before define,
- formatted transput using complex formatting declarations,
- := - assignment operation symbol (to avoid confusion with equal sign),
- array (and slice operations on them, but in layered libraries),
- automatic UNIONs,
- CASE expressions,
- nonlocal GOTO
- intuitive declaration syntax due to its origin from C.
ALGOL 68 doesn't have:
- public/private struct member access protection,
- overloaded procedures (in contrast to operators),
- explicit memory deallocation,
- forward declarations (use before definition is allowed)
- textual preprocessing (eg macros),
- distinct reference and pointer types,
- comment lines (only bracketed comments),
- struct inheritance, struct member functions, virtual functions.
- destructors, exceptions, templates, namespaces, structured loop exits
Comparison of the assignment and equality operators
Intent | ALGOL 68 | C++ |
---|---|---|
Assign a value 888 to a variable x | x:=888; | x = 888; |
Compare two values | if x = 888 then ... fi | if (x == 888) { ... } |
Define a constant | int x=888; | const int x = 888; |
Initialise a variable | int x:=888; | int x = 888; |
Allocate a variable from the heap | ref int x = heap int; or simply: heap int x; |
int* x = new int; |
Compare address of two pointers | ref int x, y; if x :=: y then ... fi |
int* x; int* y; if (x == y) { ... } |
Compare value referenced by two pointers | ref int x, y; if x = y then ... fi |
int* x; int* y; if (*x == *y) { ... } |
Name a new type | mode longreal = long real; | typedef double longreal; |
Name a new record type | mode cust = struct(string name, address); | struct cust { std::string name, address; }; |
Name a new union type | mode taggedu = union(string s, real r); | union u { std::string s; float f; }; |
Name a procedure or function | proc f = (real x) real: ( code; result ); | float f(float x) { code; return result; } |
Procedure default parameters | proc 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 operator | op ↑ = (real x,y) real: x**y; | n/a |
Set priority on a new operator | prio ↑ = 9; | n/a |
Duplication by assignment | a:=b:=c:=d; | a = b = c = d; |
Displacement operator - ALGOL 68C only | a:=:=b:=:=c:=:=d; | a = b; b = c; c = d; |
Append "substr" to a variable str | str +:= "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/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 = 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;
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.
External references
- A comparison of PASCAL and ALGOL 68 - Andrew S. Tanenbaum - June 1977.
- Orthogonal language design - Apr 2004 - retrieved May 10, 2007
- How Solve the Dangling Else? - Apr 2004 - retrieved May 10, 2007
- A comparison of Pascal, C, C++ and Algol68: Types, cont Type system, Type checking, Type safety, Type conversion, Primitive types, Aggregate types: arrays - Apr 2004 - retrieved May 10, 2007
- Arrays in Algol68 - Apr 2004 - retrieved May 10, 2007