ajm188 / go-ff Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
https://github.com/slok/noglog
We should also update the README instructing people how to get noglog
working, since replace
directives don't apply transitively.
Things like:
rand(n float64) float64
Abstractly I thought this was a good idea, but now that I'm playing around with this, anything that's idempotent can be precomputed and be provided via the parameters
map in Evaluate
, so there may not be a huge need for this.
There's also the whole thing where govaluate
only actually deals in four types: float64, bool, string, and arrays, so the "correct" implementation a rand
function is:
map[string]govaluate.ExpressionFunction{
"rand": func(arguments ...interface{}) (interface{}, error) {
if len(arguments) != 1 {
return nil, fmt.Errorf("must provide one argument to rand, got %d", len(arguments))
}
n, ok := arguments[0].(float64)
if !ok {
return nil, fmt.Errorf("rand takes a numeric value, got %v (%T)", arguments[0], arguments[0])
}
return float64(rand.Intn(int(n))), nil
}
}
If we don't explicitly cast the result of rand.Intn
to a float64
then that value will be treated as a string in the expression, so an expression like rand(10) < 2
will fail because it's comparing a string and a float. So the whole thing also becomes kind of annoying to implement correctly.
An important note from the govaluate
manual (emphasis mine):
During expression parsing (not evaluation), a map of functions can be given to govaluate.NewEvaluableExpressionWithFunctions (the lengthiest and finest of function names). The resultant expression will be able to invoke those functions during evaluation. Once parsed, an expression cannot have functions added or removed - a new expression will need to be created if you want to change the functions, or behavior of said functions.
So, managing that could get a bit tricky, depending on whether we want users to provide functions globally (pro: automatically available in every feature, don't have to remember which features have which functions available; con: have to re-parse every single feature anytime a function is added or removed, even if that feature doesn't use that function) or per-feature (same pro/con list but reversed). In any case, I wanted to get this written down before I inevitably forget.
Currently we use the default globalRand
, and users can only control the behavior by calling rand.SetSeed
, which applies globally and not just to the randomness used by feature.Get
.
It might be nice to provide an API for setting a package-level source, or maybe that's a bad idea and using rand.SetSeed
is Good Enough™
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.