https://kotlinlang.org logo
Title
n

Nikky

10/17/2018, 5:18 PM
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

Ruckus

10/17/2018, 5:22 PM
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

Shawn

10/17/2018, 5:24 PM
compile-time function execution is a pretty common thing
it’s not really found in JVM languages, but elsewhere for sure
h

hho

10/17/2018, 5:24 PM
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

Shawn

10/17/2018, 5:28 PM
Oh, I didn’t even know Scala had macros lol
h

hho

10/17/2018, 5:28 PM
If there's a programming language feature, it's a pretty safe default to assume Scala has it... :troll:
😂 4
n

Nikky

10/17/2018, 5:33 PM
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

Ruckus

10/17/2018, 5:41 PM
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

Nikky

10/17/2018, 5:51 PM
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

ilya.gorbunov

10/17/2018, 6:52 PM
There's a feature request about that: https://youtrack.jetbrains.com/issue/KT-14652
👍 2