diff options
Diffstat (limited to 'src/algebra')
-rw-r--r-- | src/algebra/strap/CHAR.lsp | 220 | ||||
-rw-r--r-- | src/algebra/string.spad.pamphlet | 27 |
2 files changed, 169 insertions, 78 deletions
diff --git a/src/algebra/strap/CHAR.lsp b/src/algebra/strap/CHAR.lsp index 15a63aa1..bb9f017d 100644 --- a/src/algebra/strap/CHAR.lsp +++ b/src/algebra/strap/CHAR.lsp @@ -61,44 +61,79 @@ (PUT '|CHAR;escape;$;14| '|SPADreplace| '(XLAM NIL (|%ccst| "_"))) +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) |CHAR;newline;$;15|)) + +(PUT '|CHAR;newline;$;15| '|SPADreplace| '(XLAM NIL (|%ccst| "\\n"))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) + |CHAR;carriageReturn;$;16|)) + +(PUT '|CHAR;carriageReturn;$;16| '|SPADreplace| + '(XLAM NIL (|%ccst| "\\r"))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) |CHAR;linefeed;$;17|)) + +(PUT '|CHAR;linefeed;$;17| '|SPADreplace| '(XLAM NIL (|%i2c| 10))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) |CHAR;formfeed;$;18|)) + +(PUT '|CHAR;formfeed;$;18| '|SPADreplace| '(XLAM NIL (|%ccst| "\\f"))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) |CHAR;backspace;$;19|)) + +(PUT '|CHAR;backspace;$;19| '|SPADreplace| '(XLAM NIL (|%ccst| "\\b"))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) + |CHAR;horizontalTab;$;20|)) + +(PUT '|CHAR;horizontalTab;$;20| '|SPADreplace| + '(XLAM NIL (|%ccst| "\\t"))) + +(DECLAIM (FTYPE (FUNCTION (|%Shell|) |%Char|) |CHAR;verticalTab;$;21|)) + +(PUT '|CHAR;verticalTab;$;21| '|SPADreplace| + '(XLAM NIL (|%ccst| "\\v"))) + (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Thing|) - |CHAR;coerce;$Of;15|)) + |CHAR;coerce;$Of;22|)) -(PUT '|CHAR;coerce;$Of;15| '|SPADreplace| '(XLAM (|c|) |c|)) +(PUT '|CHAR;coerce;$Of;22| '|SPADreplace| '(XLAM (|c|) |c|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;digit?;$B;16|)) + |CHAR;digit?;$B;23|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;hexDigit?;$B;17|)) + |CHAR;hexDigit?;$B;24|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;upperCase?;$B;18|)) + |CHAR;upperCase?;$B;25|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;lowerCase?;$B;19|)) + |CHAR;lowerCase?;$B;26|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;alphabetic?;$B;20|)) + |CHAR;alphabetic?;$B;27|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Boolean|) - |CHAR;alphanumeric?;$B;21|)) + |CHAR;alphanumeric?;$B;28|)) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%String|) - |CHAR;latex;$S;22|)) + |CHAR;latex;$S;29|)) (DECLAIM (FTYPE (FUNCTION (|%String| |%Shell|) |%Char|) - |CHAR;char;S$;23|)) + |CHAR;char;S$;30|)) + +(PUT '|CHAR;char;S$;30| '|SPADreplace| '|%s2c|) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Char|) - |CHAR;upperCase;2$;24|)) + |CHAR;upperCase;2$;31|)) -(PUT '|CHAR;upperCase;2$;24| '|SPADreplace| 'CHAR-UPCASE) +(PUT '|CHAR;upperCase;2$;31| '|SPADreplace| 'CHAR-UPCASE) (DECLAIM (FTYPE (FUNCTION (|%Char| |%Shell|) |%Char|) - |CHAR;lowerCase;2$;25|)) + |CHAR;lowerCase;2$;32|)) -(PUT '|CHAR;lowerCase;2$;25| '|SPADreplace| 'CHAR-DOWNCASE) +(PUT '|CHAR;lowerCase;2$;32| '|SPADreplace| 'CHAR-DOWNCASE) (DEFUN |CHAR;=;2$B;1| (|a| |b| $) (DECLARE (IGNORE $)) @@ -123,12 +158,12 @@ (DEFUN |CHAR;size;Nni;6| ($) (DECLARE (IGNORE $)) 256) (DEFUN |CHAR;index;Pi$;7| (|n| $) - (CODE-CHAR (LET ((#0=#:G1380 (- |n| 1))) + (CODE-CHAR (LET ((#0=#:G1379 (- |n| 1))) (|check-subtype| (NOT (MINUSP #0#)) '(|NonNegativeInteger|) #0#)))) (DEFUN |CHAR;lookup;$Pi;8| (|c| $) - (LET ((#0=#:G1382 (+ 1 (CHAR-CODE |c|)))) + (LET ((#0=#:G1381 (+ 1 (CHAR-CODE |c|)))) (|check-subtype| (PLUSP #0#) '(|PositiveInteger|) #0#))) (DEFUN |CHAR;char;Nni$;9| (|n| $) @@ -147,47 +182,58 @@ (DEFUN |CHAR;escape;$;14| ($) (DECLARE (IGNORE $)) #\_) -(DEFUN |CHAR;coerce;$Of;15| (|c| $) (DECLARE (IGNORE $)) |c|) +(DEFUN |CHAR;newline;$;15| ($) (DECLARE (IGNORE $)) #\Newline) -(DEFUN |CHAR;digit?;$B;16| (|c| $) - (SPADCALL |c| (|spadConstant| $ 32) (|getShellEntry| $ 34))) +(DEFUN |CHAR;carriageReturn;$;16| ($) (DECLARE (IGNORE $)) #\Return) -(DEFUN |CHAR;hexDigit?;$B;17| (|c| $) - (SPADCALL |c| (|spadConstant| $ 36) (|getShellEntry| $ 34))) +(DEFUN |CHAR;linefeed;$;17| ($) (DECLARE (IGNORE $)) (CODE-CHAR 10)) -(DEFUN |CHAR;upperCase?;$B;18| (|c| $) - (SPADCALL |c| (|spadConstant| $ 38) (|getShellEntry| $ 34))) +(DEFUN |CHAR;formfeed;$;18| ($) (DECLARE (IGNORE $)) #\Page) -(DEFUN |CHAR;lowerCase?;$B;19| (|c| $) - (SPADCALL |c| (|spadConstant| $ 40) (|getShellEntry| $ 34))) +(DEFUN |CHAR;backspace;$;19| ($) (DECLARE (IGNORE $)) #\Backspace) -(DEFUN |CHAR;alphabetic?;$B;20| (|c| $) - (SPADCALL |c| (|spadConstant| $ 42) (|getShellEntry| $ 34))) +(DEFUN |CHAR;horizontalTab;$;20| ($) (DECLARE (IGNORE $)) #\Tab) -(DEFUN |CHAR;alphanumeric?;$B;21| (|c| $) - (SPADCALL |c| (|spadConstant| $ 44) (|getShellEntry| $ 34))) +(DEFUN |CHAR;verticalTab;$;21| ($) (DECLARE (IGNORE $)) #\^K) -(DEFUN |CHAR;latex;$S;22| (|c| $) +(DEFUN |CHAR;coerce;$Of;22| (|c| $) (DECLARE (IGNORE $)) |c|) + +(DEFUN |CHAR;digit?;$B;23| (|c| $) + (SPADCALL |c| (|spadConstant| $ 39) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;hexDigit?;$B;24| (|c| $) + (SPADCALL |c| (|spadConstant| $ 43) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;upperCase?;$B;25| (|c| $) + (SPADCALL |c| (|spadConstant| $ 45) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;lowerCase?;$B;26| (|c| $) + (SPADCALL |c| (|spadConstant| $ 47) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;alphabetic?;$B;27| (|c| $) + (SPADCALL |c| (|spadConstant| $ 49) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;alphanumeric?;$B;28| (|c| $) + (SPADCALL |c| (|spadConstant| $ 51) (|getShellEntry| $ 41))) + +(DEFUN |CHAR;latex;$S;29| (|c| $) (STRCONC "\\mbox{`" (STRCONC (MAKE-FULL-CVEC 1 |c|) "'}"))) -(DEFUN |CHAR;char;S$;23| (|s| $) - (COND - ((EQL (QCSIZE |s|) 1) - (SPADCALL |s| (SPADCALL |s| (|getShellEntry| $ 52)) - (|getShellEntry| $ 53))) - (T (|userError| "String is not a single character")))) +(DEFUN |CHAR;char;S$;30| (|s| $) + (DECLARE (IGNORE $)) + (|stringToChar| |s|)) -(DEFUN |CHAR;upperCase;2$;24| (|c| $) +(DEFUN |CHAR;upperCase;2$;31| (|c| $) (DECLARE (IGNORE $)) (CHAR-UPCASE |c|)) -(DEFUN |CHAR;lowerCase;2$;25| (|c| $) +(DEFUN |CHAR;lowerCase;2$;32| (|c| $) (DECLARE (IGNORE $)) (CHAR-DOWNCASE |c|)) (DEFUN |Character| () (DECLARE (SPECIAL |$ConstructorCache|)) - (PROG (#0=#:G1402) + (PROG (#0=#:G1407) (RETURN (COND ((SETQ #0# (HGET |$ConstructorCache| '|Character|)) @@ -202,7 +248,7 @@ (DEFUN |Character;| () (DECLARE (SPECIAL |$ConstructorCache|)) - (LET ((|dv$| (LIST '|Character|)) ($ (|newShell| 58)) + (LET ((|dv$| (LIST '|Character|)) ($ (|newShell| 61)) (|pv$| (|buildPredVector| 0 0 NIL))) (|setShellEntry| $ 0 |dv$|) (|setShellEntry| $ 3 |pv$|) @@ -224,25 +270,49 @@ (FUNCALL (|dispatchFunction| |CHAR;quote;$;13|) $)) (CONS IDENTITY (FUNCALL (|dispatchFunction| |CHAR;escape;$;14|) $)) - (|OutputForm|) |CHAR;coerce;$Of;15| (|CharacterClass|) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| |CHAR;newline;$;15|) $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| + |CHAR;carriageReturn;$;16|) + $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| |CHAR;linefeed;$;17|) + $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| |CHAR;formfeed;$;18|) + $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| |CHAR;backspace;$;19|) + $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| + |CHAR;horizontalTab;$;20|) + $)) + (CONS IDENTITY + (FUNCALL (|dispatchFunction| + |CHAR;verticalTab;$;21|) + $)) + (|OutputForm|) |CHAR;coerce;$Of;22| (|CharacterClass|) (25 . |digit|) (|Character|) (29 . |member?|) - |CHAR;digit?;$B;16| (35 . |hexDigit|) - |CHAR;hexDigit?;$B;17| (39 . |upperCase|) - |CHAR;upperCase?;$B;18| (43 . |lowerCase|) - |CHAR;lowerCase?;$B;19| (47 . |alphabetic|) - |CHAR;alphabetic?;$B;20| (51 . |alphanumeric|) - |CHAR;alphanumeric?;$B;21| (|String|) (55 . |new|) - (61 . |concat|) |CHAR;latex;$S;22| (67 . |#|) - (72 . |one?|) (77 . |minIndex|) (82 . |elt|) - |CHAR;char;S$;23| |CHAR;upperCase;2$;24| - |CHAR;lowerCase;2$;25| (|SingleInteger|)) - '#(~= 88 |upperCase?| 94 |upperCase| 99 |space| 104 |size| - 108 |random| 112 |quote| 116 |ord| 120 |min| 125 |max| 135 - |lowerCase?| 145 |lowerCase| 150 |lookup| 155 |latex| 160 - |index| 165 |hexDigit?| 170 |hash| 175 |escape| 180 - |digit?| 184 |coerce| 189 |char| 194 |before?| 204 - |alphanumeric?| 210 |alphabetic?| 215 >= 220 > 226 = 232 - <= 238 < 244) + |CHAR;digit?;$B;23| (35 . |hexDigit|) + |CHAR;hexDigit?;$B;24| (39 . |upperCase|) + |CHAR;upperCase?;$B;25| (43 . |lowerCase|) + |CHAR;lowerCase?;$B;26| (47 . |alphabetic|) + |CHAR;alphabetic?;$B;27| (51 . |alphanumeric|) + |CHAR;alphanumeric?;$B;28| (|String|) (55 . |new|) + (61 . |concat|) |CHAR;latex;$S;29| |CHAR;char;S$;30| + |CHAR;upperCase;2$;31| |CHAR;lowerCase;2$;32| + (|SingleInteger|)) + '#(~= 67 |verticalTab| 73 |upperCase?| 77 |upperCase| 82 + |space| 87 |size| 91 |random| 95 |quote| 99 |ord| 103 + |newline| 108 |min| 112 |max| 122 |lowerCase?| 132 + |lowerCase| 137 |lookup| 142 |linefeed| 147 |latex| 151 + |index| 156 |horizontalTab| 161 |hexDigit?| 165 |hash| 170 + |formfeed| 175 |escape| 179 |digit?| 183 |coerce| 188 + |char| 193 |carriageReturn| 203 |before?| 207 |backspace| + 213 |alphanumeric?| 217 |alphabetic?| 222 >= 227 > 233 = + 239 <= 245 < 251) 'NIL (CONS (|makeByteWordVec2| 1 '(0 0 0 0 0 0 0 0)) (CONS '#(NIL NIL NIL |SetCategory&| |OrderedType&| @@ -250,24 +320,24 @@ (CONS '#((|OrderedFinite|) (|OrderedSet|) (|Finite|) (|SetCategory|) (|OrderedType|) (|BasicType|) (|Type|) - (|CoercibleTo| 29)) - (|makeByteWordVec2| 57 + (|CoercibleTo| 36)) + (|makeByteWordVec2| 60 '(0 14 0 15 0 12 0 16 2 17 0 0 0 18 2 - 12 0 0 0 22 1 12 0 0 24 0 31 0 32 2 - 31 6 33 0 34 0 31 0 36 0 31 0 38 0 31 - 0 40 0 31 0 42 0 31 0 44 2 46 0 12 33 - 47 2 46 0 0 0 48 1 46 12 0 50 1 12 6 - 0 51 1 46 17 0 52 2 46 33 0 17 53 2 0 - 6 0 0 1 1 0 6 0 39 1 0 0 0 55 0 0 0 - 26 0 0 12 13 0 0 0 25 0 0 0 27 1 0 12 - 0 21 0 0 0 1 2 0 0 0 0 1 0 0 0 1 2 0 - 0 0 0 1 1 0 6 0 41 1 0 0 0 56 1 0 14 - 0 23 1 0 46 0 49 1 0 0 14 20 1 0 6 0 - 37 1 0 57 0 1 0 0 0 28 1 0 6 0 35 1 0 - 29 0 30 1 0 0 46 54 1 0 0 12 19 2 0 6 - 0 0 1 1 0 6 0 45 1 0 6 0 43 2 0 6 0 0 - 11 2 0 6 0 0 9 2 0 6 0 0 7 2 0 6 0 0 - 10 2 0 6 0 0 8))))) + 12 0 0 0 22 1 12 0 0 24 0 38 0 39 2 + 38 6 40 0 41 0 38 0 43 0 38 0 45 0 38 + 0 47 0 38 0 49 0 38 0 51 2 53 0 12 40 + 54 2 53 0 0 0 55 2 0 6 0 0 1 0 0 0 35 + 1 0 6 0 46 1 0 0 0 58 0 0 0 26 0 0 12 + 13 0 0 0 25 0 0 0 27 1 0 12 0 21 0 0 + 0 29 0 0 0 1 2 0 0 0 0 1 0 0 0 1 2 0 + 0 0 0 1 1 0 6 0 48 1 0 0 0 59 1 0 14 + 0 23 0 0 0 31 1 0 53 0 56 1 0 0 14 20 + 0 0 0 34 1 0 6 0 44 1 0 60 0 1 0 0 0 + 32 0 0 0 28 1 0 6 0 42 1 0 36 0 37 1 + 0 0 53 57 1 0 0 12 19 0 0 0 30 2 0 6 + 0 0 1 0 0 0 33 1 0 6 0 52 1 0 6 0 50 + 2 0 6 0 0 11 2 0 6 0 0 9 2 0 6 0 0 7 + 2 0 6 0 0 10 2 0 6 0 0 8))))) '|lookupComplete|)) (MAKEPROP '|Character| 'NILADIC T) diff --git a/src/algebra/string.spad.pamphlet b/src/algebra/string.spad.pamphlet index 9f2e5883..9ea5e74f 100644 --- a/src/algebra/string.spad.pamphlet +++ b/src/algebra/string.spad.pamphlet @@ -42,6 +42,20 @@ Character: OrderedFinite() with ++ \spad{escape} provides the escape character, \spad{_}, which ++ is used to allow quotes and other characters {\em within} ++ strings. + newline: % + ++ \spad{newline} designates the new line character. + carriageReturn: % + ++ \spad{carriageReturn} designates carriage return. + linefeed: % + ++ \spad{linefeed} designates the line feed character. + formfeed: % + ++ \spad{formfeed} designates the form feed character. + backspace: % + ++ \spad{backspace} designates the backspace character. + horizontalTab: % + ++ \spad{horizontalTab} designates horizontal tab. + verticalTab: % + ++ \spad{verticalTab} designates vertical tab. upperCase: % -> % ++ upperCase(c) converts a lower case letter to the corresponding ++ upper case letter. If c is not a lower case letter, then @@ -83,6 +97,7 @@ Character: OrderedFinite() with import %c2i: % -> NNI from Foreign Builtin import %i2c: NNI -> % from Foreign Builtin import %ccst: String -> % from Foreign Builtin + import %s2c: String -> % from Foreign Builtin a = b == %ceq(a,b) a < b == %clt(a,b) @@ -98,6 +113,13 @@ Character: OrderedFinite() with space == %ccst " " quote == %ccst "_"" escape == %ccst "__" + newline == %ccst "\n" + carriageReturn == %ccst "\r" + linefeed == %i2c 10 + formfeed == %ccst "\f" + backspace == %ccst "\b" + horizontalTab == %ccst "\t" + verticalTab == %ccst "\v" coerce(c:%):OutputForm == c : OutputForm digit? c == member?(c, digit()) hexDigit? c == member?(c, hexDigit()) @@ -109,9 +131,8 @@ Character: OrderedFinite() with latex c == concat("\mbox{`", concat(new(1,c)$String, "'}")$String)$String - char(s:String) == - one?(#s) => s(minIndex s) - userError "String is not a single character" + char(s: String) == + %s2c s upperCase c == CHAR_-UPCASE(c)$Lisp : % |