-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
$:abs(x) - returns absolute value of number. If list is passed, then applies the function element by element. $:floor(x) - returns floor of number. If list is passed, then applies the function element by element. $:fpart(x) - returns fractional part of number. If list is passed, then applies the function element by element. $:now() - returns number of milliseconds since midnight Jan. 1 1970 $:rrbzo() - returns a Random Real Between Zero and One. $:sub(c, s[, e]) - returns a subcollection of a collection `c' with starting index `s' and ending index `e' if specified
- Loading branch information
1 parent
ea4e2a1
commit 8aaa1b3
Showing
9 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import gui._ | ||
import util._ | ||
|
||
class Abs extends Command { | ||
override def getName(): String = "abs" | ||
override def isValidArg0(n: Int): Boolean = n == 1 | ||
override def apply(args: Array[Type]): Type = { | ||
MathUtil.abs(args(0)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import gui._ | ||
import util._ | ||
|
||
class FPart extends Command { | ||
override def getName(): String = "fpart" | ||
override def isValidArg0(n: Int): Boolean = n == 1 | ||
override def apply(args: Array[Type]): Type = { | ||
MathUtil.fpart(args(0)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import gui._ | ||
import util._ | ||
|
||
// What TI-Basic-inspired language could be complete without a floor function? | ||
|
||
class Floor extends Command { | ||
override def getName(): String = "floor" | ||
override def isValidArg0(n: Int): Boolean = n == 1 | ||
override def apply(args: Array[Type]): Type = { | ||
MathUtil.floor(args(0)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import java.util.Date | ||
|
||
class Now extends Command { | ||
override def getName(): String = "now" | ||
override def apply(args: Array[Type]): Type = { | ||
new THill(new Date().getTime) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader._ | ||
import types._ | ||
|
||
class Rrbzo extends Command { | ||
override def getName(): String = "rrbzo" | ||
override def isValidArg0(n: Int): Boolean = n == 0 | ||
override def apply(args: Array[Type]): Type = { | ||
TFish(Global.r.nextDouble) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import scala.collection.mutable._ | ||
|
||
class Sub extends Command { | ||
override def getName(): String = "sub" | ||
override def isValidArg0(n: Int): Boolean = n == 2 || n == 3 | ||
override def apply(args: Array[Type]): Type = { | ||
val whole = args(0) | ||
(whole, args(1), if (args.length == 2) 0 else args(2)) match { | ||
case (w: LList, n: TNumerical, p: TNumerical) => { | ||
val const = (b: Buffer[Type]) => { | ||
if (w.getType == 5) new LArray(b.to[ArrayBuffer]) | ||
else new LLinked(b.to[ListBuffer]) | ||
} | ||
const({ | ||
if (args.length == 2) w.l.drop(n.intValue) | ||
else w.l.slice(n.intValue, p.intValue) | ||
}) | ||
} | ||
case (w: TString, n: TNumerical, p: TNumerical) => { | ||
new TString({ | ||
if (args.length == 2) w.getVal.substring(n.intValue) | ||
else w.getVal.substring(n.intValue, p.intValue) | ||
}) | ||
} | ||
case (_, _, _) => new TError(1) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters