clojurescript

wcohen 2024-12-12T17:47:30.305819Z

I need a touch of macro help! With emscripten, I’ve got a module that spits out a function which, when evaluated, returns an object with all the functions available from a transpiled C thing. (This is for http://github.com/willcohen/clj-proj, which builds a C library.) In other words, (.-_proj_context_create (proj-emscripten)) gives me the function that in C would have been _proj_context_create . I’d love to create a macro that lets me simplify this to something like (foo _proj_context_create) , which I can then apply arguments to. I’ve got the following, which isn’t quite working, yielding _proj_context_create is not defined rather than returning JS function

(defmacro foo
     [f]
     `(.-~f (proj-emscripten))))

p-himik 2024-12-12T18:25:48.388579Z

Macroexpansion adds a space between - and the value of f. You gotta construct a symbol, something like ~(symbol (str ".-" (name f))).

wcohen 2024-12-12T20:33:30.829479Z

Thank you! Still not working, need to diagnose further on my own. Might be something funny about how macros are working in cherry.

p-himik 2024-12-12T20:34:30.638519Z

What are the current symptoms of "not working"? What does macroexpand-1 say?

wcohen 2024-12-12T20:38:54.930639Z

Ah, that’s it. cherry hasn’t implemented macroexpand yet, so this case of the symbol is probably still an edge case there. Will try to create a test case based on what comes out of the JS and work with @borkdude accordingly. Thank you!

👍 1
Craterfall 2024-12-12T23:39:40.494889Z

I am trying to import a hook from material ui but cant figure it out Any of the attempts I've tried just return nil.

["@mui/x-tree-view/hooks" :refer [useTreeViewApiRef]]
(def tree-api (dbg useTreeViewApiRef))
undefined the example https://codesandbox.io/embed/c43mdf?module=/src/Demo.tsx&fontsize=12 the tsx is import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; Using npm and webpack

p-himik 2024-12-13T05:37:41.892179Z

Try importing the whole package with an alias via :as and then log it to the JS console to see what's inside.

Craterfall 2024-12-13T15:52:34.167769Z

Its still undefined for some of the other packages

["@mui/x-tree-view/TreeItem" :as MuiTreeItem]
that works I wonder if its the way they package and export libraires

p-himik 2024-12-13T15:55:12.166189Z

So you did ["@mui/x-tree-view/hooks" :as something] and (js/console.log something) printed out undefined? Hmm.

p-himik 2024-12-13T15:59:32.716579Z

I just tried it, and it worked.

Craterfall 2024-12-13T16:00:31.910889Z

So strange

p-himik 2024-12-13T16:00:41.731739Z

It also worked with ["@mui/x-tree-view/hooks" :refer [useTreeViewApiRef]]. But I'm using shadow-cljs. Don't know what you're using.

Craterfall 2024-12-13T16:01:48.113659Z

That is probably the issue I am using figwheel

Craterfall 2024-12-13T16:53:54.297259Z

Why is shadow able to do this but figwheel fails?

p-himik 2024-12-13T16:54:15.339869Z

I don't know, I have stopped using Fighweel a long time ago.