Fork me on GitHub
#sci
<
2021-07-24
>
pez18:07:30

In lack of an #edamame channel. When I try the README example:

(parse-string "#(* % %1 %2)" {:fn true})
;;=> (fn [%1 %2] (* %1 %1 %2))
I instead get
(fn*
 [%1 %2]
 (* %1 %1 %2))
Is there a way I can force it to give me the same thing as in the example?

borkdude18:07:58

ah it should be fn* actually, this was changed at some point to be more like the original

borkdude18:07:05

so the README should be changed

pez18:07:12

Too bad =(

pez18:07:48

My use case is translating tests from 4Clojure and I would like them to not use the rather confusing fn*. But it is just my use case so probably not something that should direct the development of edamame.

borkdude18:07:59

user=> (e/parse-string "#(+ 1 2 3)" {:fn true :postprocess (fn [{:keys [obj]}] (if (and (seq? obj) (= 'fn* (first obj))) (list* 'fn (rest obj)) obj))})
(fn [] (+ 1 2 3))

phronmophobic19:07:20

I'm getting an Exception when trying to evaluate a defrecord that implements protocols that were defined outside of sci Example defrecord:

(defrecord
    My-comp
    [extra context]
    membrane.ui/IBounds
    (-bounds
      [this__25094__auto__]
      (:membrane.component/bounds this__25094__auto__)))
The protocol, membrane.ui/IBounds was defined and loaded outside of sci. The exception I'm getting is https://gist.github.com/phronmophobic/6603dbf9d7ea3a74ecd8b757aba1b41f

borkdude19:07:47

@smith.adriane protocols need a bit of special attention in sci. Internally they are piggy-backing on multi-methods (since multi-methods don't need any compilation, but protocols do).

borkdude19:07:13

I can show you how you can have a protocol outside of sci and inside sci, I have several examples of that

🙏 3
borkdude19:07:23

lemme check

borkdude19:07:40

@smith.adriane Note that this is quite "implementation" detail-ish, but here you go: https://github.com/borkdude/sci/blob/master/src/sci/impl/core_protocols.cljc IDeref, etc is implemented as a protocol in SCI and also outside of SCI (in CLJS, but in CLJ it's an interface)

borkdude19:07:55

I'll also dig up another example that's only in bb

borkdude19:07:14

something like this:

(defmethod as-file :default [x]
  (io/as-file x))
takes care of calling the "outside SCI" protocol

borkdude19:07:28

while inside sci the multimethod "wrapper" is being called

borkdude19:07:22

I should perhaps one day expose and document this better, but so far nobody ever asked for it :)

😄 3
pez19:07:52

The :postprocess trick works perfectly! Thanks!

👍 3
pez19:07:36

Is this a bug?

(edamame/parse-string "#{'(:x) '(:y)}")
; Execution error (ExceptionInfo) at edamame.impl.parser/throw-reader (parser.cljc:102).
; Set literal contains duplicate key: '

borkdude19:07:45

hm, it looks like it? issue welcome!

borkdude19:07:10

oh no wait, I get it :)

borkdude19:07:16

you should allow :quote as well

borkdude19:07:27

else it gets parsed as EDN

borkdude19:07:38

and single quotes are just standalone elements in EDN

borkdude20:07:20

Basically what you are seeing here is similar to:

user=> (clojure.edn/read-string "#{'(:x) '(:y)}")
Execution error (IllegalArgumentException) at user/eval1 (REPL:1).
Duplicate key: '

borkdude20:07:31

if you want to allow all code features, you can just use :all true

metal 3