Is there anyone here that knows Clojure?
# getting-started
j
Is there anyone here that knows Clojure?
n
­čĹő
any reason in particular?
j
In Clojure you can import a namespace like ":require [user.core :as core]" and then access functions in the 'core' namespace like core/myfunction. I couldn't find a way to do the same. I don't want to import all functions in the core namespace. I want to access them via an "alias".
I solved it by using companion objects.
m
you can import as
import org.test.Message as testMessage
Ô׼ 3
j
But isn't that only used for classes? If you only want an alias to the namespace and then use it to access different functions in that namespace, like myns.func1(), myns.fnc2(), then I couldn't find an example of how to do that.
j
I know clojure, Kotlin basically doesn't have namespaces, only packages.. There are a few approaches to emulating namespaces but none of them are great. Writeup here: https://arturdryomov.dev/posts/namespacing-in-kotlin/
Java 9+ also has a module system (again not quite the same as namespaces but related)
j
I solved it like this:
Copy code
package user

object Interface {
    fun theUser(): String {
        return user.core.theUser();
    }
}
Then I use user.Interface as a namespace:
Copy code
package tool

import user.Interface as User

fun main() {
    println("Current user: " + User.theUser())
}