| java.lang.Object jsint.U
U | abstract public class U (Code) | | A class to hold static utility methods; the name "U" stands for
"Utility", but is short because it will be used a lot.
author: Peter Norvig, Copyright 1998, peter@norvig.com, license author: subsequently modified by Jscheme project members author: licensed under zlib licence (see license.txt) |
Field Summary | |
final public static Object[] | EMPTY_ARGS | final public static Boolean | FALSE Same as Boolean.FALSE. | final public static Symbol | MISSING The value to use when a parameter is not supplied to a procedure. | final public static Object[] | NO_ARGS An argument list with zero arguments. | final public static Double | ONE A Double with value 1.0. | final public static Boolean | TRUE Same as Boolean.TRUE. | final public static Symbol | UNDEFINED The value to return when a variable is not defined. | final public static Double | ZERO A Double with value 0.0. | public static boolean | useJavaSyntax |
Method Summary | |
public static Object | and1(Object x) One argument and used by (and) macro. | public static Object | append(Object args) args is a list of lists to be appended together. | public static Object | apply(Procedure p, Pair args) R5RS apply as requested by
"Hoehle, Joerg-Cyril" . | public static Pair | arrayToList(Object x) | public static Object | callCC(Procedure k) A continuation exception is a specially marked RuntimeException. | public static Object | callWithInputFile(Object filename, Procedure proc) | public static Object | callWithOutputFile(Object filename, Procedure proc) | public static boolean | checkNargs(int min, int max, int given, Object form) Check that the form has between min and max arguments (exclusive
of the first element of the form). | public static boolean | equal(Object x, Object y) Structural equality. | public static boolean | eqv(Object x, Object y) Atomic equality. | public static Object | first(Object x) Return the first element of a Pair, or error. | public static long | gcd(Pair args) | static long | gcd(long a, long b) | public static boolean | isFalse(Object x) | public static boolean | isList(Object x) Return true if x is a proper list: null-terminated and finite.
Return false if it is an infinite or non-null-terminated list.
Not to be confused with (or (pair? x) (null? x)). | public static boolean | isPair(Object x) Check if the argument is a non-empty list. | public static boolean | isVector(Object x) | static long | lcm(Object args) | public static Pair | list(Object a, Object b, Object c) Creates a three element list. | public static Pair | list(Object a, Object b) Creates a two element list. | public static Pair | list(Object a) Creates a one element list. | public static Object | listToArray(Class C, Object x) | public static String | listToString(Object chars) Convert a list of characters to a String. | public static Object[] | listToVector(Object x) | public static String | makeString(int size, Object fill) | public static Object | makeVector(Object x) | public static Object | makeVector(Object x, Object fill) | public static Pair | map(Procedure proc, Object args, Pair result) Map proc over a list of lists of args.
If result is a passed in as a Pair, then accumulate values there. | public static Class | maybeToClass(Object c) | public static Object | memberAssoc(Object obj, Object list, boolean member, int eq) | public static Boolean | not(Object x) Returns TRUE if x is FALSE or null. | public static Object | numCompute(Object x, Pair args, char op) Compute (x op arg1 op arg2 op ...), in ints or doubles. | public static Object | numCompute(long result, Pair args, char op) Compute (result op arg1 op arg2 op ...). | public static Object | numCompute(double result, Pair args, char op) Compute (result op arg1 op arg2 op ...). | public static Object | numberToString(Object x, Object y) | public static InputPort | openInputFile(Object filename) Opens a file, resource, or URL. | public static PrintWriter | openOutputFile(Object filename) | public static Object | p(String x, Object y) Used for debugging. | public static Object | rest(Object x) Return the rest of a Pair, or error. | public static Object | second(Object x) Return the second element of a list. | public static String | stringAppend(Pair args) | public static int | stringCompareIgnoreCase(Object x, Object y) Return <0 if x is alphabetically first, >0 if y is first,
0 if same. | public static Object | stringToList(Object x) | public static Object | stringToNumber(Object x, Object y) | public static StringBuffer | stringify(Object x, boolean quoted, StringBuffer buf) Convert a Scheme object to its printed representation, as a java
String. | public static String | stringify(Object x) Convert x to a String giving its external representation. | public static String | stringify(Object x, boolean quoted) Convert x to a String giving its external representation. | public static Pair | timeCall(Procedure proc, int nTimes) Call the procedure repeatedly nTimes, and return a list of the
the last result, the elapsed time, and the memory used. | public static Boolean | toBool(boolean x) Convert boolean to Boolean. | public static Boolean | toBool(Object x) Convert Scheme object to Boolean. | public static Character | toChar(char ch) Converts a char to a Character. | public static Class | toClass(Object c) | public static InputPort | toInPort(Object x) Cast a Scheme object to a Scheme input port, which is an InputPort.
If the argument is missing, returns Scheme.getInput(). | public static int | toInt(Object x) Converts a Scheme object to an int, or calls error. | public static int | toInt(Object x, int defaultVal) Converts a Scheme object to an int, return the default
if it is not possible to convert the object to an int. | public static Pair | toList(Object x) Cast a Scheme object to a Pair or the empty list. | public static Integer | toNum(int i) Convert int to Integer. | public static Number | toNum(long i) Convert long to Number, either Integer or Long. | public static Double | toNum(double x) Convert double to Double. | public static PrintWriter | toOutPort(Object x) Cast a Scheme object to a Scheme input port, which is a PrintWriter.
If the argument is missing, returns Scheme.getOutput(). | public static Pair | toPair(Object x) Cast a Scheme object to a Pair (can't be the empty list). | public static Procedure | toProc(Object x) Cast a Scheme object to a procedure, or call error. | public static double | toReal(Object x) Converts a Scheme object to a double, or calls error. | public static String | toStr(Object x) Cast a Scheme object to a String, or call error. | public static Symbol | toSym(Object x) Cast a Scheme object to a Scheme symbol, or call error. | public static Object | toVec(Object x) Cast a Scheme object to a Scheme vector, or call error. | public static boolean | to_bool(Object x) Convert Scheme object to boolean. | public static char | to_char(Object x) Converts a Character to a char, or calls error for non-Characters. | public static char | to_lc_char(Object x) Converts a Character to a lowercase char, or calls error for non-Characters. | public static Object | vectorFill(Object vec, Object fill) | public static Object | vectorLength(Object x) | public static Object | vectorRef(Object x, Object y) | public static Object | vectorSet(Object x, Object y, Object z) | public static Pair | vectorToList(Object vec) | public static Object | write(Object x, PrintWriter port, boolean quoted) Write the object to a port. |
FALSE | final public static Boolean FALSE(Code) | | Same as Boolean.FALSE. *
|
MISSING | final public static Symbol MISSING(Code) | | The value to use when a parameter is not supplied to a procedure. *
|
NO_ARGS | final public static Object[] NO_ARGS(Code) | | An argument list with zero arguments. *
|
ONE | final public static Double ONE(Code) | | A Double with value 1.0. Defined here so that we need only one. *
|
TRUE | final public static Boolean TRUE(Code) | | Same as Boolean.TRUE. *
|
UNDEFINED | final public static Symbol UNDEFINED(Code) | | The value to return when a variable is not defined. *
|
ZERO | final public static Double ZERO(Code) | | A Double with value 0.0. Defined here so that we need only one. *
|
useJavaSyntax | public static boolean useJavaSyntax(Code) | | a flag which specifies whether Java (or Scheme) syntax
should be used when printing Scheme terms
|
append | public static Object append(Object args)(Code) | | args is a list of lists to be appended together. *
|
apply | public static Object apply(Procedure p, Pair args)(Code) | | R5RS apply as requested by
"Hoehle, Joerg-Cyril" .
We splice the last argument onto the end of the argument list.
|
callCC | public static Object callCC(Procedure k)(Code) | | A continuation exception is a specially marked RuntimeException. *
|
checkNargs | public static boolean checkNargs(int min, int max, int given, Object form)(Code) | | Check that the form has between min and max arguments (exclusive
of the first element of the form). If the form has the wrong
number of arguments, then complain. *
|
first | public static Object first(Object x)(Code) | | Return the first element of a Pair, or error. *
|
gcd | static long gcd(long a, long b)(Code) | | |
isFalse | public static boolean isFalse(Object x)(Code) | | #f and #null are treated as false *
|
isList | public static boolean isList(Object x)(Code) | | Return true if x is a proper list: null-terminated and finite.
Return false if it is an infinite or non-null-terminated list.
Not to be confused with (or (pair? x) (null? x)). *
|
isPair | public static boolean isPair(Object x)(Code) | | Check if the argument is a non-empty list. *
|
listToString | public static String listToString(Object chars)(Code) | | Convert a list of characters to a String. *
|
map | public static Pair map(Procedure proc, Object args, Pair result)(Code) | | Map proc over a list of lists of args.
If result is a passed in as a Pair, then accumulate values there.
Otherwise, just return the empty list. *
|
numCompute | public static Object numCompute(Object x, Pair args, char op)(Code) | | Compute (x op arg1 op arg2 op ...), in ints or doubles. *
|
numCompute | public static Object numCompute(long result, Pair args, char op)(Code) | | Compute (result op arg1 op arg2 op ...). Return the result
as an Object, but along the way, use result (a long) as an accumulator of
the result so far. For compare ops, returns FALSE for false, and
a number for true. *
|
numCompute | public static Object numCompute(double result, Pair args, char op)(Code) | | Compute (result op arg1 op arg2 op ...). Return the result
as an Object, but along the way, use result (a double) as an accumulator of
the result so far. For compare ops, returns FALSE for false, and
a number for true. *
|
openInputFile | public static InputPort openInputFile(Object filename)(Code) | | Opens a file, resource, or URL. Returns null if unsuccessful.*
|
stringCompareIgnoreCase | public static int stringCompareIgnoreCase(Object x, Object y)(Code) | | Return <0 if x is alphabetically first, >0 if y is first,
0 if same. Case insensitive iff ci is true. Error if not strings.
NOTE: In Java 2, just use String.CompareIgnorecase. But that
method is missing in Java 1.0 and 1.1. *
|
stringify | public static StringBuffer stringify(Object x, boolean quoted, StringBuffer buf)(Code) | | Convert a Scheme object to its printed representation, as a java
String. If quoted is true, use "str" and #\c, otherwise use str and
c. You need to pass in a StringBuffer that is used to accumulate the
results. (If the interface didn't work that way, the system would use
lots of little internal StringBuffers. But note that you can still call
stringify(x) and a new StringBuffer will be created for you.
If useJavaSyntax is true, then literals are printed using a Java syntax
|
stringify | public static String stringify(Object x)(Code) | | Convert x to a String giving its external representation.
Strings and characters are quoted. *
|
stringify | public static String stringify(Object x, boolean quoted)(Code) | | Convert x to a String giving its external representation.
Strings and characters are quoted iff quoted is true.. *
|
timeCall | public static Pair timeCall(Procedure proc, int nTimes)(Code) | | Call the procedure repeatedly nTimes, and return a list of the
the last result, the elapsed time, and the memory used. *
|
toBool | public static Boolean toBool(boolean x)(Code) | | Convert boolean to Boolean. *
|
toChar | public static Character toChar(char ch)(Code) | | Converts a char to a Character. Caches low-numbered chars. *
|
toInPort | public static InputPort toInPort(Object x)(Code) | | Cast a Scheme object to a Scheme input port, which is an InputPort.
If the argument is missing, returns Scheme.getInput(). *
|
toInt | public static int toInt(Object x)(Code) | | Converts a Scheme object to an int, or calls error. *
|
toInt | public static int toInt(Object x, int defaultVal)(Code) | | Converts a Scheme object to an int, return the default
if it is not possible to convert the object to an int. *
|
toList | public static Pair toList(Object x)(Code) | | Cast a Scheme object to a Pair or the empty list. *
|
toNum | public static Integer toNum(int i)(Code) | | Convert int to Integer. Caches small ints so that we only ever
make one copy of new Integer(0), new Integer(1), etc. *
|
toNum | public static Number toNum(long i)(Code) | | Convert long to Number, either Integer or Long. *
|
toNum | public static Double toNum(double x)(Code) | | Convert double to Double. Caches 0 and 1; makes new for others. *
|
toOutPort | public static PrintWriter toOutPort(Object x)(Code) | | Cast a Scheme object to a Scheme input port, which is a PrintWriter.
If the argument is missing, returns Scheme.getOutput(). *
|
toPair | public static Pair toPair(Object x)(Code) | | Cast a Scheme object to a Pair (can't be the empty list). *
|
toProc | public static Procedure toProc(Object x)(Code) | | Cast a Scheme object to a procedure, or call error. *
|
toReal | public static double toReal(Object x)(Code) | | Converts a Scheme object to a double, or calls error. *
|
toStr | public static String toStr(Object x)(Code) | | Cast a Scheme object to a String, or call error. *
|
toSym | public static Symbol toSym(Object x)(Code) | | Cast a Scheme object to a Scheme symbol, or call error. *
|
toVec | public static Object toVec(Object x)(Code) | | Cast a Scheme object to a Scheme vector, or call error. *
|
to_bool | public static boolean to_bool(Object x)(Code) | | Convert Scheme object to boolean. *
|
to_char | public static char to_char(Object x)(Code) | | Converts a Character to a char, or calls error for non-Characters. *
|
to_lc_char | public static char to_lc_char(Object x)(Code) | | Converts a Character to a lowercase char, or calls error for non-Characters. *
|
write | public static Object write(Object x, PrintWriter port, boolean quoted)(Code) | | Write the object to a port. If quoted is true, use "str" and #\c,
otherwise use str and c. *
|
|
|