https://kotlinlang.org logo
#announcements
Title
# announcements
k

karelpeeters

11/14/2017, 4:23 PM
@elect
Copy code
val b
    get() = array[5]
    set(value) { array[5] = value }
and then use
::b
e

elect

11/14/2017, 4:27 PM
uhm, no other way?
k

karelpeeters

11/14/2017, 4:28 PM
Well what do you need it for?
e

elect

11/14/2017, 4:29 PM
I'm started to use reference to primitives in my code
k

karelpeeters

11/14/2017, 4:29 PM
You could write a custom delegate to simplify this if you need it often, something like
val b by arrayArraySpot(aarray, 5)
e

elect

11/14/2017, 4:30 PM
and since references to local variable is not yet available, I'm declaring them most of the time as top level or in the companion object
but right now, my code started to recursively call multiple functions which makes uses of these variables
to I need to create a sort of push/pop mechanismus
k

karelpeeters

11/14/2017, 4:31 PM
Hmm, do you have a code sample?
e

elect

11/14/2017, 4:32 PM
of this concept?
not really, I'm working on it right now
I'm trying now to implement your tip
k

karelpeeters

11/14/2017, 4:34 PM
Still don't really get what you're going for but let me know if it works 🙂.
e

elect

11/14/2017, 4:34 PM
in that gist
there is an
inline fun
the idea is to call that function instead a top level or companion object primitive
and that function will offer a primitive, which is not being used by any other function at the moment, and I can use its reference to pass it along
k

karelpeeters

11/14/2017, 4:37 PM
Ah I see, then I think delegates are indeed the solution.
Although performance might not be great.
e

elect

11/14/2017, 4:37 PM
you think?
what you had in mind exactly with delegates?
mind sketching up a quick example?
k

karelpeeters

11/14/2017, 4:38 PM
Sure, just a sec.
e

elect

11/14/2017, 4:45 PM
I update the gist
what you think?
k

karelpeeters

11/14/2017, 4:48 PM
Should work I think.
I created this over-engineered example: https://gist.github.com/b4bb3f6257eaf3ae8c6d6c2e2771dec1
e

elect

11/14/2017, 4:48 PM
I'll play with it, thanks dear
one last question, do you see any perf flaws with the design I proposed?
k

karelpeeters

11/14/2017, 5:36 PM
I think you should be fine.
4 Views