- Website : notkamui.com
- Email : [email protected]
- Organization/Team : Black Kamelia
- Discord :
notkamui.
Check out my team's work:
A Kotlin mini library for math expression string evaluation
License: MIT License
notkamui.
Check out my team's work:
Running keval()
on single negative number results in exception KevalInvalidExpressionException
The neg()
function seems to work in those situations but it would be nice to have support for negation via minus operator.
Tested on: Android
keval version: 0.9.0
minimal reproducible example: "-1".keval()
If we have 2 operators/functions such that the name of one of them is subset of the other, it can lead to both false exceptions, and unexpected behavior
val resource = Keval {
function {
name = "a"
arity = 1
implementation = { it[0] }
}
function {
name = "ab"
arity = 1
implementation = { it[0] + 1 }
}
}
assertFailsWith(KevalInvalidOperatorException::class) {
resource.eval("ab(1)")
}
The expected result is 2
val eval = Keval {
operator {
symbol = "a"
precedence = 1
isLeftAssociative = false
implementation = { a, b -> a - b }
}
function {
name = "a1"
arity = 1
implementation = { it[0] + 1 }
}
}.eval("1a1(1)")
assertNotEquals(1.0*(1.0+1.0), eval)
assertEquals((1.0-1.0)*(1.0), eval)
The expected result is either 1*(1+1)
or an exception
Hello! Thank you for that fantastic library.
It seems like TOKENIZER_REGEX
fails to tokenize constants with names like AB_ABCD5_Abc2_Abc_Abc_A1
and P_331abcf98a8105826357ea87c1a7e456
properly, resulting in Invalid expression at position...
exceptions.
Hi!
I have the following code snippet:
val evaluator = Keval {
includeDefault()
function {
name = "if"
arity = 3
implementation = { args -> if (args[2]==1.0) args[1] else args[0] }
}
println(evaluator.eval("if((1*1),4,5))
println(evaluator.eval("if(1*1,4,5))
}
The first expression evaluates to 4 (as expected), the second one evaluates to 1 (not expected).
Do you agree that this is a bug?
Another thought: the argument order confused me a bit, I was expecting args[0] to be the leftmost argument of the function, but it is the other way around..
When try to add a new binary operator, an exception throws like:
"java.lang.ClassCastException: class com.notkamui.keval.KevalBinaryOperator cannot be cast to class com.notkamui.keval.KevalUnaryOperator."
The bug is that in KevalBuilder.addOperator
, all the convertions are wrong:
private fun addOperator(symbol: Char, operator: KevalOperator, isUnary: Boolean) {
when (val resource = resources[symbol.toString()]) {
is KevalUnaryOperator -> resources[symbol.toString()] =
KevalBothOperator(operator as KevalBinaryOperator, resource) // should be KevalUnaryOperator
is KevalBinaryOperator -> resources[symbol.toString()] =
KevalBothOperator(resource, operator as KevalUnaryOperator) // should be KevalBinaryOperator
is KevalBothOperator -> resources[symbol.toString()] =
if (isUnary) KevalBothOperator(operator as KevalBinaryOperator, resource.unary) // should be KevelUnaryOperator
else KevalBothOperator(resource.binary, operator as KevalUnaryOperator) // should be KevalBinaryOperator
else -> resources[symbol.toString()] = operator
}
}
Could you correct this and publish a new version?
BTW, this is a really nice repository, saves my day when creating a calculator app~
When using log10(1.6)
as the expression, the tokens will be like this:
Seems the regex is not correct, that splits the token into log
and 10
.
And I can not use log(1.6)
as the expression, because the default operators don't contain log
.
So could you please either change DEFAULT_RESOURCES
to log
or modify the regex to match log10
?
Hi,
When passing an empty string to eval()
, a NoSuchElementException
is thrown by Keval.
Here is complete stack trace :
Caused by: java.util.NoSuchElementException: List is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:386)
at com.notkamui.keval.ShuntingYardKt.toAbstractSyntaxTree(ShuntingYard.kt:168)
at com.notkamui.keval.Keval.eval(Keval.kt:120)
Hello! So I use ur library in one of my app cuz its very cool and simple, are you still working on negative numbers within the .keval() method ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.