Skip to content

Commit

Permalink
fixed signature for array.sort
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashk committed Apr 25, 2013
1 parent c29dc21 commit 89f45d5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/scala/org/moe/runtime/builtins/ArrayClass.scala
Expand Up @@ -370,14 +370,12 @@ object ArrayClass {
arrayClass.addMethod(
new MoeMethod(
"sort",
new MoeSignature(List(new MoeOptionalParameter("&sorter"))),
new MoeSignature(List(new MoeSlurpyParameter("@sorter"))),
env,
(e) => // self(e).sort(r, e.getAs[MoeCode]("&sorter"))
e.get("&sorter") match {
case Some(none: MoeUndefObject) => self(e).sort(r, None)
case Some(sorter: MoeCode) => self(e).sort(r, Some(sorter))
case _ => self(e).sort(r, None)
}
(e) => e.getAs[MoeArrayObject]("@sorter").get.at_pos(r, getInt(0)) match {
case none: MoeUndefObject => self(e).sort(r, None)
case sorter: MoeCode => self(e).sort(r, Some(sorter))
}
)
)

Expand Down

3 comments on commit 89f45d5

@stevan
Copy link
Member

@stevan stevan commented on 89f45d5 Apr 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prakashk why the change in signature?

@prakashk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that having to handle three cases when using MoeOptionalParameter a little awkward (handling the the Undef case should not be necessary). When I saw your change for the reduce method (where the signature was changed to use MoeSlurpyParameters and needed only two cases), I thought may be I could use the same approach (optional == 0 or 1 parameter, anyway). I should have spent a bit of time in writing a better comment :)

@stevan
Copy link
Member

@stevan stevan commented on 89f45d5 Apr 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prakashk actually the change on reduce was done as part of the branch where I am introducing a type system of sorts (I am still thinking this one through, and will eventually write something up about it). But I did that because I needed to be able to accept any "type" of variable (array, hash, code, scalar) and the type system currently doesn't allow that.

Please sign in to comment.