


## pre-basis.pkg
# Compiled by:
# src/lib/std/src/standard-core.sublib# This contains definitions of various Basis types that are
# abstract but need to be concrete to the basis implementation.
# It also has some ultility functions.
### "Now and then we had a hope
### that if we lived and were good,
### God would permit us to be pirates."
###
### -- Mark Twain,
### Life on the Mississippi
package pre_basis {
stipulate
my (-) = inline_t::default_int::(-);
my (+) = inline_t::default_int::(+);
my (<) = inline_t::default_int::(<);
herein
# The time type is abstract in the time package,
# but other modules need access to it.
#
# Here we open the type-only Time package
# to expose the representation.
include time;
# **************************************************************************
# These definitions are part of the number_string package, but are defined here
# so that they can be used in other basis modules.
# **************************************************************************
fun scan_string scan_g input_string
=
{ n = inline_t::vector_of_chars::length input_string;
fun getc i
=
if (i < n) THE (inline_t::vector_of_chars::get (input_string, i), i+1);
else NULL;
fi;
case (scan_g getc 0)
THE (x, _) => THE x;
NULL => NULL;
esac;
};
fun skip_ws (getc: X -> Null_Or( (Char, X) ) )
=
lp
where
fun is_ws (' ') => TRUE;
is_ws ('\t') => TRUE;
is_ws ('\n') => TRUE;
is_ws _ => FALSE;
end;
fun lp cs
=
case (getc cs)
THE (c, cs') => if (is_ws c) lp cs';
else cs ;
fi;
NULL => cs;
esac;
end;
# Get n characters from a character source.
# (This is not a visible part of number_string.)
#
fun get_nchars (getc: X -> Null_Or ((Char, X)) )
(cs, n)
=
get (cs, n, [])
where
fun reverse ([], l2) => l2;
reverse (x ! l1, l2) => reverse (l1, x ! l2);
end;
fun get (cs, 0, l)
=>
THE (reverse (l, []), cs);
get (cs, i, l)
=>
case (getc cs)
NULL => NULL;
(THE (c, cs')) => get (cs', i - 1, c ! l);
esac;
end;
end;
end; # stipulate
};


