Template:Prelude/general.a68: Difference between revisions

add some more useful MODEs and exceptions
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:
<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
##########################################
# -*- 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(INTBOOL, CHAR, STRING, []STRINGUTF, 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 errorexception = (STRING type, SIMPLEOUT argv)VOID:(
raiseBOOL exception("Value Error",argv)= FALSE;
putf(stand error, ($g$, "Exception"," ",type, ": ", argv, $l$));
ASSERT (exception)
);
 
PROC raise exceptionundefined = (STRING type, SIMPLEOUT argv)VOID:(
raise exception("Undefined", argv);
 
PROC raise undefinedvalue 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>