Attached is diff with respect to current trunk which
should give the same functionality as your code, but
omits most problematic changes.
As I wrote in previous mail, changes to Symbol IMO
should go to a separate package. From changes to
'string.spad' we probaly should take some but not
all.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/ZWKY5diqMW5qp54O%40fricas.org.
diff --git a/src/algebra/string.spad b/src/algebra/string.spad
index 92a16e76..a2eff212 100644
--- a/src/algebra/string.spad
+++ b/src/algebra/string.spad
@@ -22,6 +22,10 @@ Character : Join(OrderedFinite(), Hashable) with
++ char(s) provides a character from a string s of length one.
space : () -> %
++ space() provides the blank character.
+-- begin new code jg
+ infinityCharacter : () -> %
+ ++ infinityCharacter() provides ∞.
+-- end new code jg
quote : () -> %
++ quote() provides the string quote character, \spad{"}.
underscore : () -> %
@@ -56,12 +60,20 @@ Character : Join(OrderedFinite(), Hashable) with
alphanumeric? : % -> Boolean
++ alphanumeric?(c) tests if c is either a letter or number,
++ i.e. one of 0..9, a..z or A..Z.
+-- begin new code jg
+ greek? : % -> Boolean
+ ++ greek?(c) tests if c is a greek letter.
+ toDigit: % -> Integer
+ ++ toDigit(c) transforms c to a digit, error if not possible.
+-- end new code jg
== add
Rep := SingleInteger -- 0..(1114112 - 1)
CC ==> CharacterClass()
import from CC
+ OF ==> OutputForm
+ import from OF
--cl: Record(dig: CC, hex: CC, upp: CC, low: CC, alpha: CC, alnum: CC) :=
-- [ digit(), hexDigit(),
@@ -89,6 +101,24 @@ Character : Join(OrderedFinite(), Hashable) with
lowerCase? c == member?(c pretend Character, lowerCase())
alphabetic? c == member?(c pretend Character, alphabetic())
alphanumeric? c == member?(c pretend Character, alphanumeric())
+-- begin new code jg
+ infinityCharacter(): % == char 8734
+ greek? c == member?(c pretend Character, greek())
+ toDigit(c: %): Integer ==
+ --print blankSeparate [msg "toDigit aufgerufen mit c = ", c :: OF]
+ c = char "0" => 0
+ c = char "1" => 1
+ c = char "2" => 2
+ c = char "3" => 3
+ c = char "4" => 4
+ c = char "5" => 5
+ c = char "6" => 6
+ c = char "7" => 7
+ c = char "8" => 8
+ c = char "9" => 9
+ error "toDigit: not a number"
+ -1
+-- end new code jg
char(s : String) == STR_to_CHAR(s)$Lisp
-- (#s) = 1 => s(minIndex s) pretend %
@@ -147,6 +177,11 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
alphanumeric : constant -> %
++ alphanumeric() returns the class of all characters for which
++ \spadfunFrom{alphanumeric?}{Character} is true.
+-- begin new code jg
+ greek : constant -> %
+ ++ greek() returns the class of all characters for which
+ ++ \spadfunFrom{greek?}{Character} is true.
+-- end new code jg
== add
Rep := IndexedBits(0)
@@ -154,7 +189,8 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
import from Character
- N := 256
+ --N := 256
+ N := 1024
a, b : %
@@ -164,6 +200,13 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
lowerCase() == charClass "abcdefghijklmnopqrstuvwxyz"
alphabetic() == union(upperCase(), lowerCase())
alphanumeric() == union(alphabetic(), digit())
+-- begin new code jg
+ gL : String := construct [index(u :: PositiveInteger) for u in 946..962]
+ gL := concat(gL, construct [index(u :: PositiveInteger) for u in 964..970] )
+ gL := concat(gL, construct [index(u :: PositiveInteger) for u in 914..930] )
+ gL := concat(gL, construct [index(u :: PositiveInteger) for u in 932..938] )
+ greek() == charClass gL
+-- end new code jg
a = b == a =$Rep b
@@ -424,8 +467,54 @@ String() : StringCategory with
++ as sequence of octets using UTF-8 encoding. Consegently
++ length of returened list may be smaller than length
++ of the string in octets.
+-- begin new code jg
+ toInteger: % -> Integer
+ ++ toInteger(s) changes s into an integer, if it is a list of digits
+ ++ possible after a minus sign.
+ toDecimalExpansion: % -> DecimalExpansion
+ ++ toDecimalExpansion(s) changes s into a decimal expansion, if
+ ++ it is a list of digit, possible after a minus sign,
+ ++ containing at most one comma, but is allowed to contain
+ ++ arbitrary many blanks and periods.
+-- end new code jg
== IndexedString(MINSTRINGINDEX) add
+ import OutputForm
+-- begin new code jg
+ toInteger(s: %): Integer ==
+ lc : List Character := parts s
+ empty? lc => 0
+ negative? : Boolean := first(lc) = char "-"
+ if negative? then lc := rest lc
+ res : Integer := 0
+ for c in lc repeat
+ if c ~= char "." then
+ res := 10 * res + toDigit(c)$Character
+ if negative? then -res else res
+ toDecimalExpansion(s: %): DecimalExpansion ==
+ lc : List Character := parts s
+ empty? lc => 0
+ negative? : Boolean := first(lc) = char "-"
+ if negative? then lc := rest lc
+ lc' : List Character := copy lc
+ res : DecimalExpansion := 0
+ ten : DecimalExpansion := 10 :: DecimalExpansion
+ oneTenth : DecimalExpansion := 1/ten
+ for c in lc repeat
+ if c = char "," then
+ lc' := rest lc'
+ break
+ if c ~= char "." then
+ res := ten * res + toDigit(c) :: DecimalExpansion
+ lc' := rest lc'
+ lc' := reverse lc'
+ res' : DecimalExpansion := 0
+ for c in lc' repeat
+ if c ~= char "." then
+ res' := oneTenth * (res' + toDigit(c) :: DecimalExpansion)
+ res := res+res'
+ if negative? then -res else res
+-- end new code jg
ucodeToString(n : Integer) : % == NUM2USTR(n)$Lisp
uentries(s : %) : List(SingleInteger) == UENTRIES(s)$Lisp
diff --git a/src/algebra/symbol.spad b/src/algebra/symbol.spad
index 3a77357e..4044a22e 100644
--- a/src/algebra/symbol.spad
+++ b/src/algebra/symbol.spad
@@ -19,6 +19,13 @@ Symbol() : Exports == Implementation where
resetNew : () -> Void
++ resetNew() resets the internals counters that new() and
++ new(s) use to return distinct symbols every time.
+-- begin new code jg
+ newGreek : () -> %
+ ++ newGreek() returns the next greek character.
+ resetNewGreek : () -> Void
+ ++ resetNewGreek() resets the internals counters that newGreek()
+ ++ use to return distinct symbols every time.
+-- end new code jg
coerce : String -> %
++ coerce(s) converts the string s to a symbol.
name : % -> %
@@ -53,6 +60,111 @@ Symbol() : Exports == Implementation where
++ Error: if the symbol is subscripted.
sample : constant -> %
++ sample() returns a sample of %
+-- begin new code jg
+ partial: constant -> %
+ ++ partial() returns ∂.
+ tabulator: constant -> %
+ ++ tabulator() returns .
+ endOfLine: constant -> %
+ ++ endOfLine() returns the end-of-line chacter.
+ alpha: constant -> %
+ ++ alpha() returns α.
+ beta: constant -> %
+ ++ beta() returns β.
+ gamma: constant -> %
+ ++ gamm() returns γ.
+ delta: constant -> %
+ ++ delta() returns δ.
+ epsilon: constant -> %
+ ++ epsilon() returns ε.
+ zeta: constant -> %
+ ++ zeta() returns ς.
+ eta: constant -> %
+ ++ eta() returns η.
+ theta: constant -> %
+ ++ theta() returns θ.
+ iota: constant -> %
+ ++ iota() returns ι.
+ kappa: constant -> %
+ ++ kappa() returns κ.
+ lambda: constant -> %
+ ++ lambda() returns λ.
+ mu: constant -> %
+ ++ mu() returns μ.
+ nu: constant -> %
+ ++ nu() returns ν.
+ xi: constant -> %
+ ++ xi() returns ξ.
+ omicron: constant -> %
+ ++ omicron() returns ο.
+ pi: constant -> %
+ ++ pi() returns π.
+ rho: constant -> %
+ ++ rho() returns ρ.
+ sigma: constant -> %
+ ++ sigma() returns σ.
+ tau: constant -> %
+ ++ tau() returns τ.
+ upsilon: constant -> %
+ ++ upsilon() returns υ.
+ phi: constant -> %
+ ++ phi() returns φ.
+ chi: constant -> %
+ ++ chi() returns χ.
+ psi: constant -> %
+ ++ psi() returns ψ.
+ omega: constant -> %
+ ++ omega() returns ω.
+ Alpha: constant -> %
+ ++ Alpha() returns Α.
+ Beta: constant -> %
+ ++ Beta() returns Β.
+ Gamma: constant -> %
+ ++ Gamm() returns Γ.
+ Delta: constant -> %
+ ++ Delta() returns Δ.
+ Epsilon: constant -> %
+ ++ Epsilon() returns Ε.
+ Zeta: constant -> %
+ ++ Zeta() returns Ζ.
+ Eta: constant -> %
+ ++ Eta() returns Η.
+ Theta: constant -> %
+ ++ Theta() returns Θ.
+ Iota: constant -> %
+ ++ Iota() returns Ι.
+ Kappa: constant -> %
+ ++ Kappa() returns Κ.
+ Lambda: constant -> %
+ ++ Lambda() returns Λ.
+ Mu: constant -> %
+ ++ Mu() returns Μ.
+ Nu: constant -> %
+ ++ Nu() returns Ν.
+ Xi: constant -> %
+ ++ Xi() returns Ξ.
+ Omicron: constant -> %
+ ++ Omicron() returns Ο.
+ Pi: constant -> %
+ ++ Pi() returns Π.
+ Rho: constant -> %
+ ++ Rho() returns Ρ.
+ Sigma: constant -> %
+ ++ Sigma() returns Σ.
+ Tau: constant -> %
+ ++ Tau() returns Τ.
+ Upsilon: constant -> %
+ ++ Upsilon() returns Υ.
+ Phi: constant -> %
+ ++ Phi() returns Φ.
+ Chi: constant -> %
+ ++ Chi() returns Χ.
+ Psi: constant -> %
+ ++ Psi() returns Ψ.
+ Omega: constant -> %
+ ++ omega() returns Ω.
+-- ["Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"
+-- end new code jg
Implementation ==> add
@@ -68,6 +180,9 @@ Symbol() : Exports == Implementation where
nums:String := "0123456789"
ALPHAS:String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphas:String := "abcdefghijklmnopqrstuvwxyz"
+-- begin new code jg
+ greekCount : Integer := 0
+-- end new code jg
writeOMSym(dev : OpenMathDevice, x : %) : Void ==
scripted? x =>
@@ -194,6 +309,21 @@ Symbol() : Exports == Implementation where
count := count + 1
concat("%",sym)::%
+-- begin new code jg
+ greek_str(i : Integer) : String ==
+ ns : String := ""
+ repeat
+ qr := divide(i, 24)
+ i := qr.quotient
+ ns := concat(ucodeToString(qr.remainder + 946), ns)
+ if zero?(i) then return ns
+
+ newGreek() ==
+ sym := greek_str(greekCount)
+ greekCount := greekCount + 1
+ sym :: %
+-- end new code jg
+
new x ==
n : Integer :=
(u := search(x, xcount)) case "failed" => 0
@@ -215,6 +345,12 @@ Symbol() : Exports == Implementation where
for k in keys xcount repeat remove!(k, xcount)
void
+-- begin new code jg
+ resetNewGreek() ==
+ greekCount := 0
+ void
+-- end new code jg
+
scripted? sy ==
not ATOM(sy)$Lisp
@@ -251,6 +387,63 @@ Symbol() : Exports == Implementation where
sample() == "aSymbol"::%
+-- begin new code jg
+ getUTF(i : PositiveInteger): % == ucodeToString(i)::%
+ partial(): % == getUTF(8707)
+ tabulator(): % == getUTF(9225)
+ endOfLine(): % == getUTF(10)
+-- α, β, γ, δ, ε, ζ, η, θ, ι, κ, λ, μ, ν, ξ, ο, π, ρ, ς, σ, τ, υ, φ, χ, ψ, ω,
+ alpha(): % == getUTF(946)
+ beta(): % == getUTF(947)
+ gamma(): % == getUTF(948)
+ delta(): % == getUTF(949)
+ epsilon(): % == getUTF(950)
+ zeta(): % == getUTF(951)
+ eta(): % == getUTF(952)
+ theta(): % == getUTF(953)
+ iota(): % == getUTF(954)
+ kappa(): % == getUTF(955)
+ lambda(): % == getUTF(956)
+ mu(): % == getUTF(957)
+ nu(): % == getUTF(958)
+ xi(): % == getUTF(959)
+ omicron(): % == getUTF(960)
+ pi(): % == getUTF(961)
+ rho(): % == getUTF(962)
+ --?? (): % == getUTF(963)
+ sigma(): % == getUTF(964)
+ tau(): % == getUTF(965)
+ upsilon(): % == getUTF(966)
+ phi(): % == getUTF(967)
+ chi(): % == getUTF(968)
+ psi(): % == getUTF(969)
+ omega(): % == getUTF(670)
+ Alpha(): % == getUTF(914)
+ Beta(): % == getUTF(915)
+ Gamma(): % == getUTF(916)
+ Delta(): % == getUTF(917)
+ Epsilon(): % == getUTF(918)
+ Zeta(): % == getUTF(919)
+ Eta(): % == getUTF(920)
+ Theta(): % == getUTF(921)
+ Iota(): % == getUTF(922)
+ Kappa(): % == getUTF(923)
+ Lambda(): % == getUTF(924)
+ Mu(): % == getUTF(925)
+ Nu(): % == getUTF(926)
+ Xi(): % == getUTF(927)
+ Omicron(): % == getUTF(928)
+ Pi(): % == getUTF(929)
+ Rho(): % == getUTF(930)
+ --?? (): % == getUTF(931)
+ Sigma(): % == getUTF(932)
+ Tau(): % == getUTF(933)
+ Upsilon(): % == getUTF(934)
+ Phi(): % == getUTF(935)
+ Chi(): % == getUTF(936)
+ Psi(): % == getUTF(937)
+ Omega(): % == getUTF(938)
+-- end new code jg
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.