Fork me on GitHub
#sci
<
2021-01-06
>
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?

borkdude12:01:19

@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

mkvlr12:01:33

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

borkdude12:01:01

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)

borkdude13:01:45

because it is calling itself?

borkdude13:01:48

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

mkvlr13:01:27

@sritchie09 the with-literal-function was also copied from https://github.com/sicmutils/sicmutils/blob/master/src/sicmutils/env.cljc#L86-L88 (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

mkvlr15:01:33

@sritchie09 I’m looking over it right now

mkvlr17:01:40

@borkdude is https://borkdude.github.io/sci.web/ using an old version of sci? defrecord doesn’t work there but does in my local sci

borkdude17:01:04

yeah, that's pretty old

mkvlr17:01:44

is this expected?

mkvlr17:01:57

or how can I recover the type from the record?

borkdude17:01:03

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

borkdude17:01:15

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

borkdude17:01:38

let me check

borkdude17:01:43

this can be fixed I think

parrot 3
borkdude17:01:30

$ 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

mkvlr17:01:03

I need the type as a keyword

borkdude17:01:30

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

borkdude17:01:45

or do you have some clojure equivalent of these records

mkvlr17:01:13

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

borkdude17:01:53

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

borkdude17:01:02

this can be improved though

borkdude17:01:09

feel free to post issue(s)

mkvlr17:01:40

will do, thanks!