Template:Prelude/general.a68: Difference between revisions
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 |
|||
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 -*- # |
|||
⚫ | |||
########################################## |
|||
⚫ | |||
MODE UTFCHAR = STRING; |
|||
⚫ | |||
MODE UTF=FLEX[0]UTFCHAR; |
|||
MODE |
|||
⚫ | |||
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), |
|||
⚫ | |||
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), |
|||
⚫ | |||
LCOMPL = UNION(SHORT SHORT COMPL, SHORT COMPL, COMPL, LONG COMPL, LONG LONG COMPL); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
# 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; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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
- -*- coding: utf-8 -*- #
- 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);
- 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);
- KEEP * #</lang>