helix

https://github.com/Lokeh/helix
alidlorenzo 2020-01-23T15:01:47.002600Z

i'm trying to generate helix native components but the JS ones are nested inside an object. i.e. c.View , c.Text how would I go about accessing an object's property inside a macro? i've tried this:

(defn- gen-comp
       [v]
       `(defmacro ~v [& args#]
          `(hx/$ ^:native (.-~v c)
                 ~@args#)))
but shadow-cljs returning No such var: rf.core.comps/v

lilactown 2020-01-23T16:12:54.003Z

the double quoting makes it weird

lilactown 2020-01-23T16:14:23.003500Z

you have to double unquote ~ it to get the value of v

lilactown 2020-01-23T16:14:31.003700Z

try

(defn- gen-comp
  [v]
  `(defmacro ~v [& args#]
     `(hx/$ ^:native (.-~~v c)
            ~@args#)))

alidlorenzo 2020-01-23T17:11:34.004500Z

interesting, wasn't aware of double quoting new error:

Encountered error when macroexpanding helix.core/$.
[1] Error in phase :compilation
[1] dot prop access with args

alidlorenzo 2020-01-23T17:12:14.005100Z

so looks like accessing the v variable works now, but the object access isn't possible for some reason?

lilactown 2020-01-23T17:15:27.005400Z

hm, the error doesn’t make much sense to me

lilactown 2020-01-23T17:15:39.005700Z

if you’re using the code I pasted above

danielneal 2020-01-23T17:19:54.006300Z

I’m not sure you can splice into dot property access like that

danielneal 2020-01-23T17:20:11.006600Z

might be best to use goog.object/get

danielneal 2020-01-23T17:20:45.007Z

maybe try (goog.object/get c v)

danielneal 2020-01-23T17:21:19.007800Z

getting this right is super hard though, might be easier to do without macros, or at least not by generating macros.

danielneal 2020-01-23T17:21:29.008100Z

if there’s only a few properties

alidlorenzo 2020-01-23T17:22:33.008900Z

yea that might be the issue, will try using goog.object what exactly does ~~ do btw? can't find info about it online

danielneal 2020-01-23T17:23:24.010Z

I guess ~ is unquote, but if the thing you unquote is still quoted, you can do another ~ to unquote again

😅 1
lilactown 2020-01-23T17:33:28.010500Z

yeah, your macro used ` twice

lilactown 2020-01-23T17:34:52.012100Z

(let [v 'Foo]
  v)
;; => Foo

(let [v 'Foo]
  `v)
;; => v

(let [v 'Foo]
  `~v)
;; => Foo

(let [v 'Foo]
  ``~v)
;; => v

(let [v 'Foo]
  ``~~v)
;; => Foo

👍 1
lilactown 2020-01-23T17:35:57.012700Z

the error sounds like you are trying to do (.-~~v c foo bar) which won’t work

lilactown 2020-01-23T17:36:09.013Z

the dot prop access with args

alidlorenzo 2020-01-23T17:55:31.014300Z

no just (.-~~v c) , and looks like (o/get c ~~v) gives same error. but going to try again in a bit

lilactown 2020-01-23T18:05:59.014700Z

the other problem that I was thinking of was that the c might not be available

lilactown 2020-01-23T18:06:26.015200Z

the macro will literally expand to ($ (.-v c) …) inside whatever namespace you use it in

lilactown 2020-01-23T18:06:34.015600Z

so you need to make sure that c is required in that namespace

lilactown 2020-01-23T18:06:53.016100Z

wait no, nevermind

alidlorenzo 2020-01-23T18:07:06.016700Z

Yea it’s required, code works when I hand write each macro

lilactown 2020-01-23T18:07:23.017Z

it should auto-namespace c because it’s in a syntax quote…

lilactown 2020-01-23T18:07:30.017200Z

can you paste the full error?

alidlorenzo 2020-01-23T18:24:32.017400Z

Encountered error when macroexpanding helix.core/$.
[1] Error in phase :compilation
[1] dot prop access with args
[1] {:form (. #function[rf.core.comps/vw] - rf.core.comps/c)}
[1] ExceptionInfo: dot prop access with args
[1]     shadow.build.cljs-hacks/shadow-analyze-dot (cljs_hacks.cljc:483)
[1]     shadow.build.cljs-hacks/shadow-analyze-dot (cljs_hacks.cljc:438)
[1]     shadow.build.cljs-hacks/eval10376/fn--10378 (cljs_hacks.cljc:510)
[1]     clojure.lang.MultiFn.invoke (MultiFn.java:252)
[1]     cljs.analyzer/analyze-seq* (analyzer.cljc:3934)
[1]     cljs.analyzer/analyze-seq* (analyzer.cljc:3932)
[1]     cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3939)
[1]     cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3937)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3963)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4200)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4191)
[1]     cljs.analyzer/analyze (analyzer.cljc:4220)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3964)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4200)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4191)
[1]     cljs.analyzer/analyze (analyzer.cljc:4220)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer.api/analyze (api.cljc:88)
[1]     cljs.analyzer.api/analyze (api.cljc:69)
[1]     cljs.analyzer.api/analyze (api.cljc:80)
[1]     cljs.analyzer.api/analyze (api.cljc:69)
[1]     cljs.analyzer.api/analyze (api.cljc:78)
[1]     cljs.analyzer.api/analyze (api.cljc:69)
[1]     cljs.analyzer.api/analyze (api.cljc:77)
[1]     cljs.analyzer.api/analyze (api.cljc:69)
[1]     helix.impl.analyzer/inferred-type/fn--38888 (analyzer.clj:80)
[1]     helix.impl.analyzer/inferred-type (analyzer.clj:80)
[1]     helix.impl.analyzer/inferred-type (analyzer.clj:79)
[1]     helix.core// (core.clj:22)
[1]     helix.core// (core.clj:7)
[1]     clojure.core/apply (core.clj:669)
[1]     clojure.core/apply (core.clj:660)
[1]     cljs.analyzer/macroexpand-1*/fn--2556 (analyzer.cljc:3879)
[1]     cljs.analyzer/macroexpand-1* (analyzer.cljc:3877)
[1]     cljs.analyzer/macroexpand-1* (analyzer.cljc:3864)
[1]     cljs.analyzer/macroexpand-1 (analyzer.cljc:3928)
[1]     cljs.analyzer/macroexpand-1 (analyzer.cljc:3924)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3961)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4200)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4191)
[1]     cljs.analyzer/analyze (analyzer.cljc:4220)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3964)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4200)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4191)
[1]     cljs.analyzer/analyze (analyzer.cljc:4220)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/analyze (analyzer.cljc:4213)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/analyze (analyzer.cljc:4211)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/fn--1962 (analyzer.cljc:2262)
[1]     cljs.analyzer/fn--1962 (analyzer.cljc:2248)
[1]     clojure.lang.MultiFn.invoke (MultiFn.java:252)
[1]     cljs.analyzer/analyze-seq* (analyzer.cljc:3934)
[1]     cljs.analyzer/analyze-seq* (analyzer.cljc:3932)
[1]     cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3939)
[1]     cljs.analyzer/analyze-seq*-wrap (analyzer.cljc:3937)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3963)
[1]     cljs.analyzer/analyze-seq (analyzer.cljc:3941)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4150)
[1]     cljs.analyzer/analyze-form (analyzer.cljc:4147)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4200)
[1]     cljs.analyzer/analyze* (analyzer.cljc:4191)
[1]     cljs.analyzer/analyze (analyzer.cljc:4220)
[1]     cljs.analyzer/analyze (analyzer.cljc:4203)
[1]     cljs.analyzer/analyze (analyzer.cljc:4213)
[1] 

alidlorenzo 2020-01-23T18:24:32.017500Z

lilactown 2020-01-23T18:33:56.017800Z

and you get the same error with gobj/get?

alidlorenzo 2020-01-23T18:41:21.017900Z

actually, no, after restarting shadow-cljs i'm seeing Can't take value of a macro: #'rf.core.comps/vw error will have to look into that when i have more time later today