keddelzz / hidden-args Goto Github PK
View Code? Open in Web Editor NEWHide your accumulators from the public API
License: MIT License
Hide your accumulators from the public API
License: MIT License
Change it from com.github.keddelzz.hidden-args
to com.github.keddelzz
.
This change will also affect future releases of hidden-args
. (Because we should also change the organization-name of the project on jcenter to be consistent with the changes in repo.)
In the scope of issue #15 the moving of annotations from the outer to the inner function was introduced, however I'm not sure how to unit-test this feature.
source code position for the test
We came across the following problem during our release process: morganey-lang/Morganey#271
We suspect that publishing a stable version of hidden-args somewhere could help us to resolve it easily. Is it possible to do that? Thanks!
@hiddenargs("loop")
def sum(xs: List[Int], @hidden acc: Int = 0): Int =
xs match {
case Nil => acc
case hd :: tl => sum(tl, acc + hd)
}
The annotation @hiddenargs
could get an optional parameter, which represents the name of the inner function, thus the code snipped above would expand to
def sum(xs: List[Int], @hidden acc: Int = 0): Int = {
def loop(xs: List[Int], acc: Int): Int =
xs match {
case Nil => acc
case hd :: tl => sum(tl, acc + hd)
}
loop(xs, 0)
}
.. instead of using the (synthetic) name sum_impl
.
See PR #26 for a discussion about migrating.
If a function is defined to be tailrec
, the inner function should receive the tailrec
annotation instead of the outer one, because after macro expansion the wrapper function isn't tailrec
anymore.
For example:
@hiddenarg
@tailrec
def factorial(n: Int, @hidden acc: BigInt = BigInt(1)): BigInt =
if (n <= 0) acc
else factorial(n - 1, BigInt(n) * acc)
I want to be able to write something like:
@hiddenargs
def sum2[T: Numeric](xs: List[T], @hidden acc: T = implicitly[Numeric[T]].zero): T =
xs match {
case Nil => acc
case hd :: tl => sum(tl, implicitly[Numeric[T]].plus(acc, hd))
}
Or maybe use the implicit parameter explicitly. For example:
@hiddenargs
def sum[T](xs: List[T], @hidden acc: T = ev.zero)(implicit ev: Numeric[T]): T =
xs match {
case Nil => acc
case hd :: tl => sum(tl, ev.plus(hd, acc))
}
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.