sci

2023-03-03T11:28:38.540359Z

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

borkdude 2023-03-03T11:29:48.496649Z

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

2023-03-03T11:30:04.570199Z

is defprotocol in general not supported?

2023-03-03T11:31:09.109949Z

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

2023-03-03T11:31:25.005179Z

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

borkdude 2023-03-03T11:31:48.337149Z

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

borkdude 2023-03-03T11:32:05.465439Z

protocol methods are fine

borkdude 2023-03-03T11:32:34.706539Z

since they are just functions you can call

borkdude 2023-03-03T11:32:53.797119Z

but extend-protocol might be problematic

borkdude 2023-03-03T11:32:59.921999Z

things we can look into to improve of course

borkdude 2023-03-03T11:33:47.633819Z

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

borkdude 2023-03-03T11:34:58.217899Z

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

2023-03-03T11:35:03.591949Z

latest

2023-03-03T11:35:38.342899Z

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

borkdude 2023-03-03T11:35:58.763199Z

I'll have a look after lunch

borkdude 2023-03-04T19:12:44.911439Z

@mhuebert did it work for you now?

2023-03-04T19:13:12.362419Z

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

borkdude 2023-03-04T19:13:36.290759Z

ok

borkdude 2023-03-03T12:05:14.154579Z

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

2023-03-03T12:29:56.732789Z

cool thanks

borkdude 2023-03-03T13:27:03.128209Z

pushed a solution to master

2023-03-03T12:32:33.828409Z

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

borkdude 2023-03-03T12:35:01.905399Z

in SCI you can use bound?

borkdude 2023-03-03T12:35:13.210579Z

also in clj

2023-03-03T12:37:01.264839Z

ah great, didn’t know about that