Template:Prelude/general.a68

Revision as of 02:20, 2 September 2011 by rosettacode>NevilleDNZ (fix typo)

<lang algol68># -*- coding: utf-8 -*- # COMMENT

 This is an ALGOL 68 prelude file called prelude/general.
 It contains small routines that are not part of any standard, 
 but are none the less useful and widely used.

USAGE

 PR READ "prelude/general.a68" PR

END COMMENT

  1. -*- coding: utf-8 -*- #
  2. Define some general routines and MODES #

MODE

 UTFCHAR = STRING, LONGCHAR = UTFCHAR, UTF=FLEX[0]LONGCHAR,
 LBITS =  UNION(SHORT SHORT BITS,  SHORT BITS,  BITS,  LONG BITS,  LONG LONG BITS),
 LBYTES = UNION(SHORT SHORT BYTES, SHORT BYTES, BYTES, LONG BYTES, LONG LONG BYTES),
 LINT =   UNION(SHORT SHORT INT,   SHORT INT,   INT,   LONG INT,   LONG LONG INT),
 LREAL =  UNION(SHORT SHORT REAL,  SHORT REAL,  REAL,  LONG REAL,  LONG LONG REAL),
 LCOMPL = UNION(SHORT SHORT COMPL, SHORT COMPL, COMPL, LONG COMPL, LONG LONG COMPL);

MODE SIMPLEOUT = [0]UNION(BOOL, CHAR, STRING, UTF, LBITS, # LBYTES,# LINT, LREAL, LCOMPL);

  1. Use MOID with "*:=" OPerators who's where the returned MODE is often VOIDed for convenience #

MODE MOID = VOID;

PROC raise exception = (STRING type, SIMPLEOUT argv)VOID:(

 BOOL exception = FALSE;
 putf(stand error, ($g$, "Exception"," ",type, ": ", argv, $l$));
 ASSERT (exception)

);

PROC raise undefined = (SIMPLEOUT argv)VOID:

 raise exception("Undefined", argv);

PROC raise value error = (SIMPLEOUT argv)VOID:

 raise exception("Value Error",argv);

PROC raise index error = (SIMPLEOUT argv)VOID:

 raise exception("Index Error",argv);
  1. KEEP * #</lang>

This is a template. There are many others. See Category:RCTemplates for a complete list of templates.