Fork me on GitHub
#sci
<
2023-03-03
>
mhuebert11:03:38

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

borkdude11:03:48

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

mhuebert11:03:04

is defprotocol in general not supported?

mhuebert11:03:09

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

mhuebert11:03:25

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

borkdude11:03:48

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

borkdude11:03:05

protocol methods are fine

borkdude11:03:34

since they are just functions you can call

borkdude11:03:53

but extend-protocol might be problematic

borkdude11:03:59

things we can look into to improve of course

borkdude11:03:47

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

borkdude11:03:58

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

mhuebert11:03:38

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

borkdude11:03:58

I'll have a look after lunch

borkdude12:03:14

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

mhuebert12:03:56

cool thanks

borkdude13:03:03

pushed a solution to master

borkdude19:03:44

@mhuebert did it work for you now?

mhuebert19:03:12

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

mhuebert12:03:33

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

borkdude12:03:01

in SCI you can use bound?

borkdude12:03:13

also in clj

mhuebert12:03:01

ah great, didn’t know about that