Template:Prelude/general.a68: Difference between revisions

From Rosetta Code
Content added Content deleted
m (moved ALGOL 68/prelude/general.a68 to Template:Prelude/general.a68: To be included into code as a template.)
(add some more useful MODEs and exceptions)
Line 1: Line 1:
<lang algol68># -*- coding: utf-8 -*- #
COMMENT
COMMENT
This is an ALGOL 68 prelude file called prelude/general.
This is an ALGOL 68 prelude file called prelude/general.
It contains small routine that are not part of any standard,
It contains small routine that are not part of any standard,
but are none the less useful and widely used.
but are none the less useful and widely used.
USAGE
USAGE
PR READ "prelude/general.a68" PR
PR READ "prelude/general.a68" PR
END COMMENT
END COMMENT
##########################################
# -*- coding: utf-8 -*- #
# Define some general routines and MODES #
##########################################
##########################################
# Define some general routines and MODES #
MODE UTFCHAR = STRING;
##########################################
MODE UTF=FLEX[0]UTFCHAR;
MODE
MODE SIMPLEOUT = [0]UNION(INT, CHAR, STRING, []STRING);
UTFCHAR = STRING, LONGCHAR = UTFCHAR, UTF=FLEX[0]LONGCHAR,
MODE MOID = VOID; # Use in cases where the OP should really return a MODE #
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),
PROC raise exception = (STRING type, SIMPLEOUT argv)VOID:(
LINT = UNION(SHORT SHORT INT, SHORT INT, INT, LONG INT, LONG LONG INT),
BOOL exception = FALSE;
LREAL = UNION(SHORT SHORT REAL, SHORT REAL, REAL, LONG REAL, LONG LONG REAL),
putf(stand error, ($g$, "Exception"," ",type, ": ", argv, $l$));
LCOMPL = UNION(SHORT SHORT COMPL, SHORT COMPL, COMPL, LONG COMPL, LONG LONG COMPL);
ASSERT (exception)
MODE SIMPLEOUT = [0]UNION(BOOL, CHAR, STRING, UTF, LBITS, # LBYTES,# LINT, LREAL, LCOMPL);
);

# Use MOID with "*:=" OPerators who's where the returned MODE is often VOIDed for convenience #
PROC raise undefined = (SIMPLEOUT argv)VOID:
MODE MOID = VOID;
raise exception("Undefined", argv);

PROC raise value error = (SIMPLEOUT argv)VOID:
PROC raise exception = (STRING type, SIMPLEOUT argv)VOID:(
raise exception("Value Error",argv);
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);

# KEEP * #</lang>
<noinclude>{{template}}</noinclude>
<noinclude>{{template}}</noinclude>

Revision as of 02:19, 2 September 2011

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

 This is an ALGOL 68 prelude file called prelude/general.
 It contains small routine 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.