is there some way to get the result of a function ...
# announcements
n
is there some way to get the result of a function call into a const val ? some sort of pure function annotation that allows it to be executed at compiletime ?
🚫 2
r
Kotlin doesn't have a concept of a "pure function", or a way to execute functions at compile time. How can you execute it before compiling it?
s
compile-time function execution is a pretty common thing
it’s not really found in JVM languages, but elsewhere for sure
h
According to the roadmap given by Andrey in the keynote at kotlinconf, there'll be an API for compiler plugins sometime in the future...
@Shawn I think Scala has something like that on the JVM with their macros.
s
Oh, I didn’t even know Scala had macros lol
h
If there's a programming language feature, it's a pretty safe default to assume Scala has it... 🧌
😂 4
n
well could potentially shim it by making a gradle plugin that uses kotlinpoet and creates a new sourceset
but this is actually for a script in buildSrc to simplify dependency managment in a project, having constants would possibly improve buildtimes
r
Yes, many languages do it with some sort of macro system, but that's arguably a separate "pre-compilation" step and not at compile-time. Technically the JVM has it to some degree with annotations and code generation.
It's often easier (at least from my perspective) to think of macros as inlined code generation annotations, and not actually part of the source code itself, but maybe I'm just crazy 🙂
n
well i'd reall like to have that to inline some string concat or other and have them be
const
for other usecases (and i know string interpolation works but apparently not if done in a method to avoid copypasta
i
There's a feature request about that: https://youtrack.jetbrains.com/issue/KT-14652
👍 2