convex icon indicating copy to clipboard operation
convex copied to clipboard

Improve `import` statement.

Open kroezone opened this issue 5 years ago • 2 comments

Currently we just have a simple import macro:

(import some-address :as alias)

Should extend this and consider:

  • Ability to make multiple imports in one statement?
  • Ability to directly refer to specific symbols (like Clojure's refer)
  • Ability to replace the convex.core default bindings
  • Additional security checks?

kroezone avatar Jul 31 '20 03:07 kroezone

Follow up on Convex-Dev/convex-web#63.

Building on the failing example from the website:

(def my-lib-address
        (deploy
           '(defn distance [x y]
              (sqrt (+ (* x x) (* y y))))))
              
(import my-lib-address :as my-lib)

;; Error => Nobody: Could not resolve library name for import: my-lib-address

So, symbols are resolved in the CNS by default meaning the example fails. This is perfectly fine behavior in my opinion but it is hard to guess it given the example is misleading and the import's docstring does not explicitly mention the CNS.

helins avatar Apr 20 '21 16:04 helins

Last comment is now irrelevant.

Overall, I think I would prefer it to be a function. After spending a lot of time thinking about dependencies when working on the CVX runner, Convex Lisp is different than other languages due to its distributed nature. It's just super dynamic and there is nothing magic about it, an alias is literally an interned address. Plus I like to attach metadata (such as :private?).

So, something like this is less magical and more useful IMO:

(def asset
     (import 'convex.asset))

helins avatar Aug 07 '21 07:08 helins