Changeset 4130 for trunk/ProjectFortress/demos
- Timestamp:
- 09/05/09 14:21:41 (3 months ago)
- Location:
- trunk/ProjectFortress/demos
- Files:
-
- 20 modified
-
ArrayListLong.fss (modified) (3 diffs)
-
BiCGSTAB.fss (modified) (4 diffs)
-
Cfa.fss (modified) (2 diffs)
-
DynamicSemantics.fss (modified) (2 diffs)
-
FeatherweightJava.fss (modified) (7 diffs)
-
HeapShakedown.fss (modified) (5 diffs)
-
Lambda.fss (modified) (2 diffs)
-
PureListLong.fss (modified) (3 diffs)
-
Syntax.fsi (modified) (1 diff)
-
Syntax.fss (modified) (8 diffs)
-
aStar.fss (modified) (1 diff)
-
newtictactoe.fss (modified) (3 diffs)
-
posFeedback.fss (modified) (1 diff)
-
sudoku.fss (modified) (2 diffs)
-
tennisRanking.fss (modified) (9 diffs)
-
tictactoe.fss (modified) (4 diffs)
-
trips.fss (modified) (2 diffs)
-
turnersParaffins0.fss (modified) (5 diffs)
-
wordcount.fss (modified) (2 diffs)
-
wordcount2.fss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/demos/ArrayListLong.fss
r3550 r4130 22 22 assertStr[\T\](a:ZZ32, b:ZZ32, s:String, l: List[\T\]) = 23 23 if a=/=b then 24 fail(a "=/=" b ": " s l.asString ())24 fail(a "=/=" b ": " s l.asString) 25 25 end 26 26 27 27 assertStr[\T\](a:Boolean, s:String, l: List[\T\]) = 28 28 if NOT a then 29 fail("Failed assertion: " s l.asString ())29 fail("Failed assertion: " s l.asString) 30 30 end 31 31 32 32 assertStr[\T\](a:Boolean, s:String, l: List[\T\], r: List[\T\]) = 33 33 if NOT a then 34 fail("Failed assertion: " s l.asString () " and " r.asString())34 fail("Failed assertion: " s l.asString " and " r.asString) 35 35 end 36 36 … … 64 64 ll : List[\ZZ32\] := l 65 65 for i <- seq(0#sz) do 66 (e,ll0) = ll.extractLeft ().get()66 (e,ll0) = ll.extractLeft.get 67 67 assertStr(e,i,"extractLeft wrong in ",ll) 68 assertStr(ll.left ().get(),i,"left wrong in ",ll)68 assertStr(ll.left.get,i,"left wrong in ",ll) 69 69 ll := ll0 70 70 end 71 assertStr(ll.isEmpty ()," not empty after extractLeft(); it's ",ll)71 assertStr(ll.isEmpty," not empty after extractLeft; it's ",ll) 72 72 ll := l 73 73 for i <- seq(1#sz) do 74 (ll0,e) = ll.extractRight ().get()74 (ll0,e) = ll.extractRight.get 75 75 assertStr(e,sz-i,"extractRight wrong in ",ll) 76 assertStr(ll.right ().get(),sz-i,"right wrong in ",ll)76 assertStr(ll.right.get,sz-i,"right wrong in ",ll) 77 77 ll := ll0 78 78 end 79 assertStr(ll.isEmpty ()," not empty after extractRight(); it's ",ll)79 assertStr(ll.isEmpty," not empty after extractRight; it's ",ll) 80 80 end 81 81 … … 125 125 chkPop(ivli,0,i,2) 126 126 print(".") 127 rli=li.reverse ()127 rli=li.reverse 128 128 for j <- 0#i do 129 129 print(".") -
trunk/ProjectFortress/demos/BiCGSTAB.fss
r3647 r4130 229 229 excessive boundary checking. 230 230 *) 231 r[i] := b[i] - c[i], i <- x.indices ()231 r[i] := b[i] - c[i], i <- x.indices 232 232 c1 : RR64 := dot_product(r, r) (* r DOT r *) 233 233 234 234 label MainLoop 235 235 if (c1 < er0) then exit MainLoop with () end 236 p[i] = r[i], i <- r.indices ()(* p = r *)237 r'[i] = r[i], i <- r.indices ()(* r' = r *)236 p[i] = r[i], i <- r.indices (* p = r *) 237 r'[i] = r[i], i <- r.indices (* r' = r *) 238 238 239 239 (* … … 247 247 c2 = dot_product(r', y) (* r' DOT y *) 248 248 alp = c1 / c2 249 e[i] := r[i] - alp y[i], i <- r.indices ()(* e = r - alp y *)249 e[i] := r[i] - alp y[i], i <- r.indices (* e = r - alp y *) 250 250 MatrixVectorProduct[\imax,jmax,kmax\](Ap,Ae,Aw,An,As,At,Ab,e,v) 251 251 ev = dot_product(e, v) (* e DOT v *) … … 253 253 (* We get ev=vv=0 when imax=jmax=kmax=2. Thus, we need to avoid NaN. *) 254 254 c3 = if (vv=0) AND (ev=0) then 1 else ev / vv end 255 x[i] := x[i] + alp p[i] + c3 e[i], i <- x.indices ()(* x = x + alp p + c3 e *)256 r[i] := e[i] - c3 v[i], i <- e.indices ()(* r = e - c3 v *)255 x[i] := x[i] + alp p[i] + c3 e[i], i <- x.indices (* x = x + alp p + c3 e *) 256 r[i] := e[i] - c3 v[i], i <- e.indices (* r = e - c3 v *) 257 257 rr := dot_product(r, r) (* r DOT r *) 258 258 println(it " residual = " rr) … … 261 261 262 262 bet = c1 / (c2 c3) 263 p[i] := r[i] + bet (p[i] - c3 y[i]), i <- p.indices ()(* p = r + bet (p - c3 y) *)263 p[i] := r[i] + bet (p[i] - c3 y[i]), i <- p.indices (* p = r + bet (p - c3 y) *) 264 264 265 265 it += 1 -
trunk/ProjectFortress/demos/Cfa.fss
r3546 r4130 403 403 println "Test Program:" 404 404 if debug 405 then println (p.asString ())//405 then println (p.asString)// 406 406 else println (p.toSource())// 407 407 end … … 410 410 result = (VDASH p).getValue() 411 411 if debug 412 then println (indent result.asString ())//412 then println (indent result.asString)// 413 413 else println (indent result.toSource())// 414 414 end -
trunk/ProjectFortress/demos/DynamicSemantics.fss
r3492 r4130 23 23 (* Runtime value ***************************************************************) 24 24 trait RuntimeValue comprises { Val, FnValue } 25 getter asString(): String 25 26 getValue(): Value 26 asString(): String27 27 toSource(): String 28 28 end 29 29 30 30 object Val(v: Value) extends RuntimeValue 31 getter asString() = v.asString 31 32 getValue() = v 32 asString() = v.asString()33 33 toSource() = v.toSource() 34 34 end … … 36 36 object FnValue(fun: FnExpr, sigma: Map[\String, RuntimeValue\]) 37 37 extends RuntimeValue 38 getter asString() = "(" fun.asString ", " sigma ")" 38 39 getValue() = fun 39 asString() = "(" fun.asString() ", " sigma ")"40 40 toSource() = fun.toSource() 41 41 end -
trunk/ProjectFortress/demos/FeatherweightJava.fss
r3645 r4130 47 47 48 48 label find 49 for i <- fields_v.indices ()do49 for i <- fields_v.indices do 50 50 if n = fields_v[i].name then 51 51 exit find with v.args[i] … … 90 90 (* Exprs *) 91 91 trait Expr 92 getter asString(): String 92 93 isVal(): Boolean = false 93 94 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr 94 95 ensures { outcome.isVal() } 95 asString(): String96 96 end 97 97 98 98 object Var(x: String) extends Expr 99 getter asString(): String = x 99 100 opr =(self, other: Var) = (x = other.x) 100 asString(): String = x101 101 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr = theta[x] 102 102 end 103 103 104 104 object New(tag: Type, args: List[\Expr\]) extends Expr 105 getter asString() = "new " tag.asString <|[\String\] a.asString | a <- args|> 106 105 107 isVal() = BIG AND[arg <- args] arg.isVal() 106 108 107 109 opr =(self, other: New) = 108 (tag = other.tag) AND (BIG AND[i <- args.indices()] args[i] = other.args[i]) 109 110 asString() = "new " tag.asString() <|[\String\] a.asString() | a <- args|> 110 (tag = other.tag) AND (BIG AND[i <- args.indices] args[i] = other.args[i]) 111 111 112 112 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr = … … 115 115 116 116 object Proj(receiver: Expr, field: String) extends Expr 117 getter asString() = (receiver.asString "." field) 118 117 119 opr =(self, other: Proj) = 118 120 (receiver = other.receiver) AND (field = other.field) 119 121 120 asString() = (receiver.asString() "." field)121 122 122 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr = 123 123 CT_.field(cast[\New\](receiver.eval(CT_, theta)), field) … … 125 125 126 126 object Invk(receiver: Expr, m_name: String, args: List[\Expr\]) extends Expr 127 getter asString() = (receiver.asString "." m_name args) 128 127 129 opr =(self, other: Invk) = 128 130 (receiver = other.receiver) AND (m_name = other.m_name) AND (args = other.args) 129 130 asString() = (receiver.asString "." m_name args)131 131 132 132 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr = do … … 142 142 143 143 object Cast(typ: Type, term: Expr) extends Expr 144 getter asString() = ("(" typ.asString ")" term.asString) 145 144 146 opr =(self, other: Cast) = (typ = other.typ) AND (term = other.term) 145 146 asString() = ("(" typ.asString() ")" term.asString())147 147 148 148 eval(CT_: ClassTable, theta: Map[\String, Expr\]): Expr = do … … 156 156 (* Types *) 157 157 object Type(name: String) 158 asString() = name158 getter asString() = name 159 159 opr =(self, other:Type) = (name = other.name) 160 160 end … … 163 163 (* Syntactic Subcomponents *) 164 164 object Decl(typ: Type, name: String) 165 asString() = typ " " name ";"165 getter asString() = typ " " name ";" 166 166 end 167 167 object Cons(tag: Type, params: List[\Decl\], -
trunk/ProjectFortress/demos/HeapShakedown.fss
r3550 r4130 36 36 end 37 37 println( 38 BIG ||[(i,l) <- headers.indexValuePairs ()]38 BIG ||[(i,l) <- headers.indexValuePairs] 39 39 //l (BIG ||[row <- data] "," row[i])) 40 40 end 41 41 42 42 checkFull(h0: Heap[\ZZ32,ZZ32\], n:ZZ32): () = 43 if h0.isEmpty ()then43 if h0.isEmpty then 44 44 if NOT (n=0) then fail("empty with n=/=0") end 45 45 else 46 46 flags : Array[\Boolean,ZZ32\] = array[\Boolean\](n).fill(false) 47 (k:ZZ32, v:ZZ32, h:Heap[\ZZ32,ZZ32\]) := h0.extractMinimum().get ()47 (k:ZZ32, v:ZZ32, h:Heap[\ZZ32,ZZ32\]) := h0.extractMinimum().get 48 48 k_prev : ZZ32 := k 49 49 expected: ZZ32 := 1 50 50 flags[v] := true 51 51 failed : Boolean := false 52 while NOT h.isEmpty ()AND expected <= n do53 (k,v,h) := h.extractMinimum().get ()52 while NOT h.isEmpty AND expected <= n do 53 (k,v,h) := h.extractMinimum().get 54 54 if k < k_prev then 55 55 println("FAIL: Keys " k_prev " and " k " out of order.") … … 63 63 expected += 1 64 64 end 65 if NOT h.isEmpty ()then65 if NOT h.isEmpty then 66 66 println("FAIL: Too many elements.") 67 67 failed := true … … 74 74 expected := 0 75 75 println(h.asDebugString) 76 while NOT h.isEmpty ()AND expected <= n do77 (k,v,h) := h.extractMinimum().get ()76 while NOT h.isEmpty AND expected <= n do 77 (k,v,h) := h.extractMinimum().get 78 78 println(expected ": min = (" k "," v ")") 79 79 println(h.asDebugString) … … 106 106 assert(n,sz," size versus computed size") 107 107 if (sz > 0) then 108 (mn_k, mn_v) = h.minimum ().get()109 assert(mn,mn_k," computed minimum versus .minimum ()")108 (mn_k, mn_v) = h.minimum.get 109 assert(mn,mn_k," computed minimum versus .minimum") 110 110 end 111 111 end … … 175 175 appending[\RR64\]( 176 176 <| 1.0 s, s lg s |>, 177 testHeap(s,lazy[\ZZ32,ZZ32\],(0#s).indexValuePairs ()),177 testHeap(s,lazy[\ZZ32,ZZ32\],(0#s).indexValuePairs), 178 178 testHeap(s,lazy[\ZZ32,ZZ32\],(0#s).map[\(ZZ32,ZZ32)\](spread)), 179 testHeap(s,pairing[\ZZ32,ZZ32\],(0#s).indexValuePairs ()),179 testHeap(s,pairing[\ZZ32,ZZ32\],(0#s).indexValuePairs), 180 180 testHeap(s,pairing[\ZZ32,ZZ32\],(0#s).map[\(ZZ32,ZZ32)\](spread)) 181 181 ))) -
trunk/ProjectFortress/demos/Lambda.fss
r3663 r4130 245 245 ')' => fail ("unexpected ')' in arg list, last arg " id) 246 246 else => if isDigit(curr) then 247 fail ("unexpected digit " curr.asString ()" in arg list")247 fail ("unexpected digit " curr.asString " in arg list") 248 248 else 249 249 mkLambda(id,parseLambdaF(newlineOK)) … … 259 259 r = parseReqTerm(true) 260 260 if curr=/=')' then 261 fail("unexpected terminator " curr.asString ()", expected ')'")261 fail("unexpected terminator " curr.asString ", expected ')'") 262 262 end 263 263 skip(newlineOK) -
trunk/ProjectFortress/demos/PureListLong.fss
r3550 r4130 22 22 assertStr[\T\](a:ZZ32, b:ZZ32, s:String, l: List[\T\]) = 23 23 if a=/=b then 24 fail(a "=/=" b ": " s l.asString ())24 fail(a "=/=" b ": " s l.asString) 25 25 end 26 26 27 27 assertStr[\T\](a:Boolean, s:String, l: List[\T\]) = 28 28 if NOT a then 29 fail("Failed assertion: " s l.asString ())29 fail("Failed assertion: " s l.asString) 30 30 end 31 31 32 32 assertStr[\T\](a:Boolean, s:String, l: List[\T\], r: List[\T\]) = 33 33 if NOT a then 34 fail("Failed assertion: " s l.asString () " and " r.asString())34 fail("Failed assertion: " s l.asString " and " r.asString) 35 35 end 36 36 … … 64 64 ll : List[\ZZ32\] := l 65 65 for i <- seq(0#sz) do 66 (e,ll0) = ll.extractLeft ().get()66 (e,ll0) = ll.extractLeft.get 67 67 assertStr(e,i,"extractLeft wrong in ",ll) 68 assertStr(ll.left ().get(),i,"left wrong in ",ll)68 assertStr(ll.left.get,i,"left wrong in ",ll) 69 69 ll := ll0 70 70 end 71 assertStr(ll.isEmpty ()," not empty after extractLeft(); it's ",ll)71 assertStr(ll.isEmpty," not empty after extractLeft; it's ",ll) 72 72 ll := l 73 73 for i <- seq(1#sz) do 74 (ll0,e) = ll.extractRight ().get()74 (ll0,e) = ll.extractRight.get 75 75 assertStr(e,sz-i,"extractRight wrong in ",ll) 76 assertStr(ll.right ().get(),sz-i,"right wrong in ",ll)76 assertStr(ll.right.get,sz-i,"right wrong in ",ll) 77 77 ll := ll0 78 78 end 79 assertStr(ll.isEmpty ()," not empty after extractRight(); it's ",ll)79 assertStr(ll.isEmpty," not empty after extractRight; it's ",ll) 80 80 end 81 81 … … 125 125 chkPop(ivli,0,i,2) 126 126 print(".") 127 rli=li.reverse ()127 rli=li.reverse 128 128 for j <- 0#i do 129 129 print(".") -
trunk/ProjectFortress/demos/Syntax.fsi
r1969 r4130 25 25 trait Ast 26 26 getId(): ZZ32 27 toString(): String27 asString(): String 28 28 toSource(): String 29 29 end -
trunk/ProjectFortress/demos/Syntax.fss
r3237 r4130 29 29 (* abstract syntax tree *) 30 30 trait Ast 31 getter asString(): String 31 32 getId(): ZZ32 32 asString(): String33 33 toSource(): String 34 34 end … … 38 38 object Program(decls: List[\FnDecl\], expr: Expr) extends Ast 39 39 id = nextId() 40 getter asString() = 41 (BIG //[d <- decls] (indent d.asString)) // // indent expr.asString 42 40 43 getId() = id 41 42 asString() =43 (BIG //[d <- decls] (indent d.asString())) // // indent expr.asString()44 44 45 45 toSource() = … … 51 51 object FnDecl(name: String, param: String, body: Expr) extends Ast 52 52 id = nextId() 53 getter asString() = name "_" id "(" param ") = " body.asString 53 54 getId() = id 54 asString() = name "_" id "(" param ") = " body.asString()55 55 toSource() = name "(" param ") = " body.toSource() 56 56 end … … 66 66 object Var(name: String) extends Expr 67 67 id = nextId() 68 getter asString() = name "_" id 68 69 getId() = id 69 asString() = name "_" id70 70 toSource() = name 71 71 end … … 73 73 object App(function: Expr, argument: Expr) extends Expr 74 74 id = nextId() 75 getter asString() = function.asString "(_" id " " argument.asString ")" 75 76 getId() = id 76 asString() = function.asString() "(_" id " " argument.asString() ")"77 77 toSource() = function.toSource() "(" argument.toSource() ")" 78 78 end … … 80 80 object If(cond: Expr, thenB: Expr, elseB: Expr) extends Expr 81 81 id = nextId() 82 getter asString() = 83 ("if_" id " " cond.asString "\n" indent "then " thenB.asString "\n" 84 indent "else " elseB.asString "\n" indent "end") 82 85 getId() = id 83 asString() =84 ("if_" id " " cond.asString() "\n" indent "then " thenB.asString() "\n"85 indent "else " elseB.asString() "\n" indent "end")86 86 toSource() = 87 87 ("if " " " cond.toSource() "\n" indent "then " thenB.toSource() "\n" … … 98 98 object FnExpr(param: String, body: Expr) extends Value 99 99 id = nextId() 100 getter asString() = "fn_" id " " param " => " body.asString 100 101 getId() = id 101 asString() = "fn_" id " " param " => " body.asString()102 102 toSource() = "fn" " " param " => " body.toSource() 103 103 end … … 105 105 object True extends Value 106 106 id = nextId() 107 getter asString() = "true" 107 108 getId() = id 108 asString() = "true" 109 toSource() = asString() 109 toSource() = self.asString 110 110 end 111 111 112 112 object False extends Value 113 113 id = nextId() 114 getter asString() = "false" 114 115 getId() = id 115 asString() = "false" 116 toSource() = asString() 116 toSource() = self.asString 117 117 end 118 118 -
trunk/ProjectFortress/demos/aStar.fss
r3663 r4130 316 316 sudoku(compact:String): Sudoku = do 317 317 st0 = emptySudoku() 318 for n<-compact.bounds ()do318 for n<-compact.bounds do 319 319 i=n DIV 9 320 320 j=n REM 9 -
trunk/ProjectFortress/demos/newtictactoe.fss
r4015 r4130 31 31 32 32 object IllegalMove(n) extends Exception 33 asString() = "Illegal move at " n33 getter asString() = "Illegal move at " n 34 34 end 35 35 … … 43 43 (* Represents the tic-tac-toe board *) 44 44 object Board(N: ZZ32, locs: List[\Maybe[\String\]\]) 45 46 getter asString() = BIG || [i <- 0#N] ((if i=0 then "" else (("+---")^N)[1:] "\n" end) || renderRow(i)) 45 47 46 48 (*) A board may be indexed by a move number from 1 to `N^2`. … … 61 63 62 64 renderRow(i: ZZ32) = BIG || [j <- 0#N] (squareLabel(i, j) || (if j=N-1 then "\n" else "|")) 63 64 asString() = BIG || [i <- 0#N] ((if i=0 then "" else (("+---")^N)[1:] "\n" end) || renderRow(i))65 65 66 66 (*) `BIG SQCUP`: if there is one winner, you get `Just` that winner. -
trunk/ProjectFortress/demos/posFeedback.fss
r3550 r4130 130 130 getter asString(): String = 131 131 ("Entity(" positivity ", [" known[0] " " known[1] "]) t = " time // 132 facts.asString ())132 facts.asString) 133 133 134 134 otherResult(result: ZZ32): ZZ32 = 1 - result -
trunk/ProjectFortress/demos/sudoku.fss
r3550 r4130 70 70 for i <- 0#9, j<- 0#9 do 71 71 if |board[i,j]| = 1 then 72 elem = board[i,j].minimum ().get()72 elem = board[i,j].minimum.get 73 73 propagateSingleton(board, i, j, elem) 74 74 else … … 92 92 init init {5} init {1} init init {9} init; 93 93 {9} init {7} {8} init {4} {6} init {2} ] 94 println(board.asString ())94 println(board.asString) 95 95 println("Starting parallel sudoku solver") 96 96 recordTime(6.847) 97 97 propagate(board) 98 98 printTime(6.847) 99 println(board.asString ())99 println(board.asString) 100 100 end 101 101 end -
trunk/ProjectFortress/demos/tennisRanking.fss
r3645 r4130 136 136 played:Map[\String,Map[\String,String\]\] := {[\String,Map[\String,String\]\]} 137 137 138 (* asString() returns the following: 139 ranking name totalWon / totalLost (thisWon / thisLost) totalgames (thisGames) totalPoints (thisPoints) 140 *) 141 getter asString():String = (twoToStr ranking) " " (tostring()) 142 138 143 (* Has played a singles game with this player? *) 139 144 playedSingle(against: String) = 140 145 do 141 146 againstGames = played.member(against) 142 againstGames.holds () AND: againstGames.get().member("").holds()147 againstGames.holds AND: againstGames.get.member("").holds 143 148 end 144 149 … … 150 155 then if against1' <- withGames.member(against1) 151 156 then (against1' = against2) 152 else withGames.member(against2).holds ()AND:153 (withGames.member(against2).get ()= against1)157 else withGames.member(against2).holds AND: 158 (withGames.member(against2).get = against1) 154 159 end 155 160 else false end … … 182 187 tostring():String = 183 188 name " " (twoToStr totalWon) " / " totalLost " (" thisWon " / " thisLost ") " (totalWon+totalLost) " (" (thisWon+thisLost) ") " totalPoints " (" thisPoints ")"// 184 185 (* asString() returns the following:186 ranking name totalWon / totalLost (thisWon / thisLost) totalgames (thisGames) totalPoints (thisPoints)187 *)188 asString():String = (twoToStr ranking) " " (tostring())189 189 190 190 (* asStringTie() does not return the ranking *) … … 300 300 init(name, 0, 0, 0, if old then oldPoints else 1000 end) 301 301 numPlayers += 1 302 database.member(name).get ()302 database.member(name).get 303 303 end 304 304 … … 380 380 println msg' 381 381 if debugOut.holds 382 then debugOut.get ().println(msg')383 debugOut.get ().close()382 then debugOut.get.println(msg') 383 debugOut.get.close() 384 384 end 385 385 fail "end" … … 504 504 ranking: ZZ32 := 1 505 505 (* the points of the previous player *) 506 points : ZZ32 := database.member(top).get ().totalPoints + 10506 points : ZZ32 := database.member(top).get.totalPoints + 10 507 507 for i <- seq(0#numPlayers) do 508 508 (_,v) = arr[i] 509 player = database.member(v).get ()509 player = database.member(v).get 510 510 (* print a player with the new ranking result *) 511 511 if player.totalPoints = points … … 513 513 fout.print(player.asStringTie()) 514 514 else player.ranking := i+1; ranking := i+1; points := player.totalPoints 515 fout.print(player.asString ())515 fout.print(player.asString) 516 516 end 517 517 (* find MVP players *) … … 534 534 for i <- seq(0#numPlayers) do 535 535 (_,v) = arr[i] 536 player = database.member(v).get ()536 player = database.member(v).get 537 537 if player.preRanking - player.ranking = mip 538 538 then mipPlayers := mipPlayers.addLeft(player.name) end … … 549 549 (* print MIP players and their old and new rankings *) 550 550 mipRec(p:String): String = do 551 player = database.member(p).get ()551 player = database.member(p).get 552 552 (" " player.name 553 553 " (ranking " player.preRanking " => " player.ranking ")") -
trunk/ProjectFortress/demos/tictactoe.fss
r4015 r4130 34 34 35 35 object IllegalMove(n) extends Exception 36 asString() = "Illegal move at " n36 getter asString() = "Illegal move at " n 37 37 end 38 38 … … 42 42 (* 43 43 opr [n:ZZ32](z:List) = 44 z.take(n).drop(n-1).left ().get()44 z.take(n).drop(n-1).left.get 45 45 *) 46 46 47 47 (* Returns nth element of a list *) 48 48 element(z:List[\ZZ32\], n:ZZ32) = 49 z.take(n+1).right ().get()49 z.take(n+1).right.get 50 50 51 51 (* Replaces the index-th element with val *) … … 62 62 (* Represents the tic-tac-toe board *) 63 63 object Board(rows) 64 asString() = do64 getter asString() = do 65 65 var all:String = "" 66 66 for y <- seq(0#boardSize) do … … 156 156 who = all.filter(fn i => i =/= 0) 157 157 if |who| > 0 then 158 who.left ().get()158 who.left.get 159 159 else 160 160 0 -
trunk/ProjectFortress/demos/trips.fss
r3550 r4130 56 56 object trip (a:ZZ32, b:ZZ32, c:ZZ32) 57 57 extends StandardTotalOrder[\trip\] 58 getter asString():String = "[trip " a " " b " " c "]" 58 59 opr CMP(self, other:trip):TotalComparison = 59 60 (a CMP other.a) LEXICO (b CMP other.b) LEXICO (c CMP other.c) 60 asString():String = "[trip " a " " b " " c "]"61 61 end trip 62 62 … … 103 103 object generator(doc:String, max:ZZ32, fun:ZZ32->List[\trip\]) 104 104 extends StandardTotalOrder[\trip\] 105 getter asString():String = "[generator " doc " max: " max "]" 105 106 opr CMP(self, other:generator):TotalComparison = doc CMP other.doc 106 asString():String = "[generator " doc " max: " max "]"107 107 end generator 108 108 -
trunk/ProjectFortress/demos/turnersParaffins0.fss
r3550 r4130 91 91 (* H objects are the leaves of the trees.*) 92 92 object H extends Radical 93 getter asString():String = "H" 93 94 opr CMP(self, other:Radical):TotalComparison = 94 95 typecase other of … … 99 100 opr |self|:ZZ32 = 0 100 101 canonical():Boolean = true 101 asString():String = "H"102 102 end H 103 103 104 104 (* Rad objects are the internal nodes of the trees.*) 105 105 object Rad (r1:Radical, r2:Radical, r3:Radical) extends Radical 106 getter asString():String = 107 case self of 108 methyl => "M"; ethyl => "E"; propyl => "p3" 109 butyl => "b4"; pentyl => "p5" 110 y3 => "y3"; t4 => "t4"; y4 => "y4"; z4 => "z4" 111 else => "[R " r1 " " r2 " " r3 " ]" 112 end 106 113 opr CMP(self, other:Radical):TotalComparison = 107 114 typecase other of … … 114 121 opr |self|:ZZ32 = 1 + |r1| + |r2| + |r3| 115 122 canonical():Boolean = r1 <= r2 <= r3 116 asString():String =117 case self of118 methyl => "M"; ethyl => "E"; propyl => "p3"119 butyl => "b4"; pentyl => "p5"120 y3 => "y3"; t4 => "t4"; y4 => "y4"; z4 => "z4"121 else => "[R " r1 " " r2 " " r3 " ]"122 end123 123 end Rad 124 124 … … 282 282 object Paraffin (r1:Radical, r2:Radical, r3:Radical, r4:Radical) 283 283 extends StandardTotalOrder[\Paraffin\] 284 getter asString():String = "[P " r1 " " r1 " " r3 " " r4 " ]" 284 285 opr CMP(self, other:Paraffin):TotalComparison = 285 286 (r1 CMP other.r1) LEXICO: … … 303 304 (* The following are for debugging and for testing. *) 304 305 opr |self|:ZZ32 = 1 + |r1| + |r2| + |r3| + |r4| 305 asString():String = "[P " r1 " " r1 " " r3 " " r4 " ]"306 306 end Paraffin 307 307 -
trunk/ProjectFortress/demos/wordcount.fss
r3664 r4130 45 45 var start:ZZ32 := 0 46 46 47 while (current < s.size ()) do47 while (current < s.size) do 48 48 if isDelimiter(s[current]) then 49 49 count := count - 1 … … 98 98 time("Acquired words",start,acq) 99 99 var invDatabase:Map[\ZZ32,List[\String\]\] = 100 BIG UNIONUNION [(x,y) <-database] makeInv(x.asString (),y)100 BIG UNIONUNION [(x,y) <-database] makeInv(x.asString,y) 101 101 inv = nanoTime() 102 102 time("Inverted database",acq,inv) -
trunk/ProjectFortress/demos/wordcount2.fss
r4016 r4130 120 120 time("Acquired words",start,acq) 121 121 invDatabase:Map[\ZZ32,List[\String\]\] = 122 BIG UNIONUNION [(x,y) <-database] makeInv(x.asString (),y)122 BIG UNIONUNION [(x,y) <-database] makeInv(x.asString,y) 123 123 inv = nanoTime() 124 124 time("Inverted database",acq,inv) 125 entries = <|[\(ZZ32, List[\String\])\] (c,m) | (c,m) <- invDatabase.reverse ()|>125 entries = <|[\(ZZ32, List[\String\])\] (c,m) | (c,m) <- invDatabase.reverse |> 126 126 for (c,m) <- seq(entries[0#100]) do 127 127 println(m ": " c " times")

