-1

Kotlin Script kotlin-experiment/Play.kts

import experiment.*

println(sum(2, 2))

Kotlin Library kotlin-experiment/Play.kts

package experiment

fun sum(x: Int, y: Int) = x + y

The compile and run command:

kotlinc -script Play.kts

produces an error:

Play.kts:3:9: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
...
println(sum(2, 2))
        ^

2 Answers 2

1

Currently, Kotlin script does not support this functionality out of the box.

By using Kscript you get this and other nice features https://github.com/holgerbrandl/kscript

Sign up to request clarification or add additional context in comments.

Comments

0

you should use @file:Import("kotlin-experiment/Play.kts")

working example here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.