-
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.
+ Added $:foldl, $:foldr, and $:filter commands
* $:cons and $:econs should work on linked lists
- Loading branch information
1 parent
1e110d7
commit f01c27d
Showing
8 changed files
with
83 additions
and
5 deletions.
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
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,20 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import scala.collection.mutable._ | ||
import util._ | ||
|
||
class FoldL extends Command { | ||
override def getName(): String = "foldl" | ||
override def isValidArg0(n: Int): Boolean = n == 3 | ||
override def apply(args: Array[Type]): Type = { | ||
val collection = args(0) | ||
val base = args(1) | ||
val f: TFunction = args(2) match { | ||
case func: TFunction => func | ||
case _ => return new TError(1) | ||
} | ||
CollectionOps.ctv[Type](_.foldLeft(base)((a, b) => f(Array(a, b))))(collection) | ||
} | ||
} |
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,20 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader.Command | ||
import types._ | ||
import scala.collection.mutable._ | ||
import util._ | ||
|
||
class FoldR extends Command { | ||
override def getName(): String = "foldr" | ||
override def isValidArg0(n: Int): Boolean = n == 3 | ||
override def apply(args: Array[Type]): Type = { | ||
val collection = args(0) | ||
val base = args(1) | ||
val f: TFunction = args(2) match { | ||
case func: TFunction => func | ||
case _ => return new TError(1) | ||
} | ||
CollectionOps.ctv[Type](_.foldRight(base)((a, b) => f(Array(a, b))))(collection) | ||
} | ||
} |
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,24 @@ | ||
package cmdreader.std | ||
|
||
import cmdreader._ | ||
import types._ | ||
import scala.collection.mutable._ | ||
import util._ | ||
|
||
class OFilter extends CommandOperator { | ||
override def getName(): String = "filter" | ||
override def isValidArg0(n: Int): Boolean = n == 2 | ||
override def apply(args: Array[Type]): Type = { | ||
val collection = args(0) | ||
val f: TFunction = args(1) match { | ||
case func: TFunction => func | ||
case _ => return new TError(1) | ||
} | ||
CollectionOps.ctc(_.filter(a => f(Array(a)).toBoolean))(collection) | ||
} | ||
override def getOpAlias(): String = "|>" | ||
def getPrecedence(): Int = PStandard.MAP | ||
def isReversed(): Boolean = false | ||
def hasAssignmentEquiv(): Boolean = true | ||
def getDoubleBase(): Option[Type] = None | ||
} |
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