sci 2023-03-03

hmm, running into a weird error with copy-ns and looking for a sanity check… I am trying to use sci/copy-ns with a namespace containing a defprotocol. Here’s the copy-ns:

(ns re-db.sci-config
  (:require [sci.core :as sci]
            [re-db.sci-test :as test]))

(sci/copy-ns re-db.sci-test (sci/create-ns 're-db.sci-test nil))
Here’s the ns being required:
(ns re-db.sci-test)

(defprotocol ITest
  (x [y]))
the error I get is:
Syntax error compiling at (src/main/re_db/sci_config.cljc:5:1).
Unable to resolve symbol: x in this context

@mhuebert You can use :exclude to suppress copying for some of those things, but issue welcome

is defprotocol in general not supported?

Maybe in general I should just be cherry-picking the things I want to expose

but I think I have macros that are calling those protocol methods

not really that well, since defprotocol inside SCI works quite different than outside SCI. this library does support it by changing the host protocol to take into account the SCI protocol: https://github.com/phronmophobic/scify

protocol methods are fine

since they are just functions you can call

but extend-protocol might be problematic

things we can look into to improve of course

but the copy-ns macro has some difficulties with metadata / arglists that is sometimes quoted or not quoted which is where the unresolved symbol comes from, likely

which SCI version are you using? there have been some improvements in this area over the last year

I don’t have much time atm, just trying to get maria v2 out the door. so I think I will try to do the most limited thing

I'll have a look after lunch

@mhuebert did it work for you now?

Great! Haven't had a chance to work again yet

I can at least repro the problem @mhuebert and looking into a fix now

pushed a solution to master

I have a macro that checks if a var is already bound, currently the implementation is

(if (:ns env)
    `(~'exists? ~name)
    `(.hasRoot (def ~name)))
ie in cljs, we use exists? and in clj we use hasRoot. I suppose I should use sci.impl.vars/hasRoot

in SCI you can use bound?

also in clj

ah great, didn’t know about that