COMMENT This example introduces the language ALGOL 68, with emphasis on the facilities it provides over and above those found in PASCAL. The new facilities of special interest are array slicing, string handling, and expression-oriented features. Note that reserved words, and words introduced for Types, are in upper case. Also that words like IF, CASE and DO are matched by words like FI, ESAC and OD (effectively forming brackets around groups of statements, and removing the need for BEGIN/END pairs). COMMENT ( MODE CARD = STRUCT(CHAR suit, INT pips) # a Type declaration for CARD. STRUCT introduces a Record Type, with two fields in this case # ; LOC [1:52] CARD pack # declares the variable 'pack' of Type Array of CARD, and with bounds [1..52] # ; FOR i FROM 0 BY 4 TO 51 DO FOR j FROM i+1 TO i+4 DO suit OF pack[j] := # 'OF' selects a field of a STRUCT (cf. 'pack[j].suit' in Pascal) # CASE j-i IN "S", "H", "D", "C" ESAC # a CASE clause standing as an expression # ; pips OF pack[j] := i%4+1 # '%' is integer division # OD OD COMMENT the pack is now arranged in perfect order COMMENT ; PROC cut = (INT i, j)VOID: # VOID is the fictitious Type returned by procedures # COMMENT takes the cards [1:i] and [j:52], and swaps them over COMMENT ( [] CARD first = pack[ :i] # declares 'first' as a Constant (since we don't need to assign to it again); its Type is Array of CARD; 'pack[ :i]' is a "slice" of 'pack', up to element 'i' # , last = pack[j+1: ] ; pack[53-j:52-i] := pack[i+1:j] # more slices # ; pack[ :52-j] := last ; pack[52-i+1: ] := first ) COMMENT we shuffle the pack by cutting it several times COMMENT ; LOC INT c, d ; print(( "Type pairs of integers to show where to cut the pack." , newline , "Terminate with a pair of zeroes" , newline, newline)) ; WHILE read((c, d, newline)); print((c, d, newline)); c>0 AND c<52 AND d>0 AND d<52 AND c