sci

https://github.com/babashka/SCI - also see #babashka and #nbb
Sam Ritchie 2021-01-06T12:34:05.198500Z

@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?

borkdude 2021-01-06T12:35:19.199100Z

@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

mkvlr 2021-01-06T12:36:33.199900Z

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

borkdude 2021-01-06T12:37:01.200200Z

yeah copying is usually the safest strategy

Sam Ritchie 2021-01-06T12:38:01.200500Z

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

Sam Ritchie 2021-01-06T12:38:35.201200Z

@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

mkvlr 2021-01-06T12:40:22.201800Z

@sritchie09 I think I only made very minor changes like fully qualifying the namespace here https://github.com/sicmutils/sicmutils/pull/216/files#diff-68db231b19f934a25d6bd98078d1f5b6fe90fdc9fa8fb86bdeefe139bc042bd1R34

👍 1
Sam Ritchie 2021-01-06T13:22:53.202400Z

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

Sam Ritchie 2021-01-06T13:23:12.202900Z

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

Sam Ritchie 2021-01-06T13:23:14.203200Z

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

Sam Ritchie 2021-01-06T13:23:20.203500Z

and just pass the args through to the underlying macro

Sam Ritchie 2021-01-06T13:24:14.203900Z

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

Sam Ritchie 2021-01-06T13:24:28.204300Z

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

Sam Ritchie 2021-01-06T13:24:29.204700Z

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

Sam Ritchie 2021-01-06T13:25:12.205100Z

I can test too, just looking for intuition here!

Sam Ritchie 2021-01-06T13:30:51.205300Z

it causes a stackoverflow, hmm

Sam Ritchie 2021-01-06T13:42:19.206100Z

(either one does)

borkdude 2021-01-06T13:42:45.206500Z

because it is calling itself?

borkdude 2021-01-06T13:42:48.206700Z

adding printlns sometimes help :)

Sam Ritchie 2021-01-06T13:42:53.206900Z

oh yeah!

Sam Ritchie 2021-01-06T13:43:09.207400Z

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

Sam Ritchie 2021-01-06T13:43:43.208200Z

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

mkvlr 2021-01-06T13:45:27.208800Z

@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 Ritchie 2021-01-06T13:59:05.209600Z

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

Sam Ritchie 2021-01-06T13:59:21.210100Z

@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 Ritchie 2021-01-06T13:59:28.210400Z

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

Sam Ritchie 2021-01-06T13:59:32.210800Z

for example

Sam Ritchie 2021-01-06T14:00:06.211300Z

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

🦜 1
Sam Ritchie 2021-01-06T14:20:24.211900Z

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 Ritchie 2021-01-06T14:20:38.212400Z

except I can’t since the name overrides…

Sam Ritchie 2021-01-06T14:20:47.212600Z

oh, wait, never mind

Sam Ritchie 2021-01-06T14:20:56.213Z

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

Sam Ritchie 2021-01-06T14:20:59.213300Z

💥

Sam Ritchie 2021-01-06T14:46:16.213800Z

okay, that should do it!!

Sam Ritchie 2021-01-06T14:47:30.214500Z

@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

mkvlr 2021-01-06T15:02:33.214800Z

@sritchie09 I’m looking over it right now

mkvlr 2021-01-06T17:11:40.215500Z

@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

borkdude 2021-01-06T17:12:04.215700Z

yeah, that's pretty old

mkvlr 2021-01-06T17:12:11.215900Z

ah ok

borkdude 2021-01-06T17:12:18.216100Z

This is more recent: https://babashka.org/xterm-sci/

mkvlr 2021-01-06T17:12:44.216300Z

is this expected?

mkvlr 2021-01-06T17:12:57.217Z

or how can I recover the type from the record?

borkdude 2021-01-06T17:13:03.217200Z

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

borkdude 2021-01-06T17:13:15.217500Z

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

borkdude 2021-01-06T17:13:28.217700Z

ah

borkdude 2021-01-06T17:13:38.217900Z

let me check

borkdude 2021-01-06T17:13:43.218100Z

this can be fixed I think

🦜 1
borkdude 2021-01-06T17:14:30.218900Z

$ 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

mkvlr 2021-01-06T17:15:03.219200Z

I need the type as a keyword

borkdude 2021-01-06T17:15:30.219700Z

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

borkdude 2021-01-06T17:15:45.220Z

or do you have some clojure equivalent of these records

mkvlr 2021-01-06T17:17:13.220400Z

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

borkdude 2021-01-06T17:22:53.221100Z

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

borkdude 2021-01-06T17:23:02.221300Z

this can be improved though

borkdude 2021-01-06T17:23:09.221500Z

feel free to post issue(s)

mkvlr 2021-01-06T17:26:40.221700Z

will do, thanks!