Fork me on GitHub
Sam Ritchie12:01:05

@borkdude Q for you, probably should be obvious from watching your discussions with @mkvlr but asking here anyway! if I have an existing macro that doesn’t use &env or &form, is there any way to re-use its definition, or do I have to redefine as a fn?


@sritchie09 as long as the macro produces s-expressions with namespaces that are also valid inside sci, then it should be fine to hook it up as a macro


@sritchie09 @borkdude I copied it because it would not be available in ClojureScript otherwise, for Clojure it worked fine with copy-var


yeah copying is usually the safest strategy

Sam Ritchie12:01:01

got it! @mkvlr as you can see, finally making a pass

Sam Ritchie12:01:35

@mkvlr I think I can slim these macros down too… binding macros often look nice paired with a form like let-coordinates* that takes the things it wants to bind as args

Sam Ritchie13:01:53

one more Q for you both if you have a moment!

Sam Ritchie13:01:12

@mkvlr for some of the macros you were able to do this:

Sam Ritchie13:01:14

(defn with-literal-functions
  [_ _ & args]
  `(af/with-literal-functions ~@args))

Sam Ritchie13:01:20

and just pass the args through to the underlying macro

Sam Ritchie13:01:14

but then in that let-coordinates macro you linked above, you recreated the body -

Sam Ritchie13:01:28

would this work, if we fully qualified the namespaces in the original macro?

Sam Ritchie13:01:29

(defn let-coordinates
  [_ _ bindings & body]
  `(cc/let-coordinates ~bindings ~@body))

Sam Ritchie13:01:12

I can test too, just looking for intuition here!

Sam Ritchie13:01:51

it causes a stackoverflow, hmm

Sam Ritchie13:01:19

(either one does)


because it is calling itself?


adding printlns sometimes help :)

Sam Ritchie13:01:09

probably because it is calling the macro it’s supposed to be rewriting?

Sam Ritchie13:01:43

if the prefix gets ignored that might do it. I have a better idea for how to deal with this


@sritchie09 the with-literal-function was also copied from (I think this exists somewhere else as well?)

Sam Ritchie13:01:05

good call, I think this is trying to “alias” a macro, which seems to work in non-SCI land

Sam Ritchie13:01:21

@mkvlr I’ve got everything up and running!! I’m refactoring the macros to make the actual macro part way slimmer so it’s easier to copy

Sam Ritchie13:01:28

(defn with-literal-functions [_ _ litfns & body]
  (let [pairs    (af/binding-pairs litfns)
        bindings (into [] cat pairs)]
    `(let ~bindings ~@body)))

Sam Ritchie14:01:06

chatting with @jackrusher shortly, after that I’ll send a PR to your PR 🙂

parrot 3
Sam Ritchie14:01:24

the only thought I’m having is that maybe I should put the duplicate macros inside the namespace where the real one is defined

Sam Ritchie14:01:38

except I can’t since the name overrides…

Sam Ritchie14:01:47

oh, wait, never mind

Sam Ritchie14:01:56

that already happens, based on how you constructed the ns forms in the sci context!

Sam Ritchie14:01:16

okay, that should do it!!

Sam Ritchie14:01:30

@mkvlr heading out for a run ~soon, but if you’re around, @mkvlr, happy to take a look at this together or answer any Qs


@sritchie09 I’m looking over it right now


@borkdude is using an old version of sci? defrecord doesn’t work there but does in my local sci


yeah, that's pretty old


is this expected?


or how can I recover the type from the record?


Records in sci are really just maps with some metadata on it


there is no real record type, it's just there for compatibility


let me check


this can be fixed I think

parrot 3

$ bb -e '(defrecord Foo []) (meta (Foo.))'
{:sci.impl/record true, :sci.impl/type Foo}
the type is currently not exposed, but instance? should work on it


I need the type as a keyword


maybe just use maps with :type, is that an option for you?


or do you have some clojure equivalent of these records


this works mostly but it seems to be missing the namespace?


yeah, defrecords are pretty hacky and mostly there to make existing clojure libs works


this can be improved though


feel free to post issue(s)


will do, thanks!