-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0248e39
commit 448ae8a
Showing
2 changed files
with
41 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
src/main/java/me/predatorray/bud/lisp/buitin/arithmetic/IntegerPredicate.java
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,39 @@ | ||
package me.predatorray.bud.lisp.buitin.arithmetic; | ||
|
||
import me.predatorray.bud.lisp.buitin.Predicate; | ||
import me.predatorray.bud.lisp.evaluator.EvaluatingException; | ||
import me.predatorray.bud.lisp.lang.BudNumber; | ||
import me.predatorray.bud.lisp.lang.BudObject; | ||
import me.predatorray.bud.lisp.lang.BudType; | ||
import me.predatorray.bud.lisp.lang.FunctionType; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
public class IntegerPredicate extends Predicate { | ||
|
||
private final FunctionType thisType = new FunctionType(this); | ||
|
||
@Override | ||
protected void checkArgumentTypes(List<BudType> argumentTypes) { | ||
if (argumentTypes.size() != 1) { | ||
throw new EvaluatingException("requires one argument"); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean predicate(List<BudObject> arguments) { | ||
BudObject arg = arguments.get(0); | ||
if (!BudType.NUMBER.equals(arg.getType())) { | ||
return false; | ||
} | ||
BudNumber number = (BudNumber) arg; | ||
BigDecimal decimal = number.getValue(); | ||
return decimal.scale() <= 0; | ||
} | ||
|
||
@Override | ||
public FunctionType getType() { | ||
return thisType; | ||
} | ||
} |