Koz Ross
Koz Ross

Reputation: 3140

Importing my own .hy files and using their elements

Suppose I have a file foo.hy, which looks like this:

(def friends ["Joe" "Mark" "Bob"])

And another file bar.hy, in the same directory as foo.hy, which looks like this:

#!/usr/bin/env hy

(import foo)

In bar.hy, I'd like to refer to the friends variable defined in foo.hy. How would I do this? For example, I'd like to call print with friends from bar.hy, but I'm not sure how to do this (and all my attempts don't seem to make the Hy REPL too happy).

Upvotes: 0

Views: 153

Answers (1)

algernon
algernon

Reputation: 71

(import foo) (print foo.friends)

Or, if you want to import friends into the current namespace, so you don't have to prefix it with foo.:

(import [foo [friends]]) (print friends)

Upvotes: 1

Related Questions