convex
convex copied to clipboard
Improve `import` statement.
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.coredefault bindings - Additional security checks?
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.
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))