Fork me on GitHub
#clojurescript
<
2023-05-02
>
Lidor Cohen09:05:04

Is it discouraged to eval in cljs runtime?

thheller09:05:55

not discouraged but you have to be aware of the "cost" you have to pay to get it. meaning it will make your build gigantic, which may or may not affect you

Lidor Cohen09:05:01

I need to delay some computations until I have some more context at runtime. I think I can wrap them in delay and later compute them inside binding with the relevant context.

thheller09:05:22

don't know what eval has to do with that? sounds like a function that takes a parameter?

Lidor Cohen09:05:04

eval could have been used to evaluate the quoted expression as means of delay

Lidor Cohen09:05:12

delay is one alternative

Lidor Cohen09:05:28

another would be a function like you said

Lidor Cohen09:05:01

it is mostly a syntactic sugar concern

thheller09:05:31

no clue what you are talking about πŸ˜› but it doesn't sound like you want your build to grow by 5mb to get eval

Lidor Cohen10:05:50

Yeah, I figured that. I asked to be more sure of what I'm doing πŸ˜…

Sam Ritchie11:05:13

@U8RHR1V60 #C015LCR9MHD is an option as well

πŸ™ 2
Lidor Cohen14:05:15

I think I'm missing something about binding: I have this function:

(defn compute-delayed [env delayed]
  (binding [this env]
    (delayed)))
from within the same ns:
(compute-delayed {:name "John"} #(str "Hello, " (this :name)))
=> "Hello, John"
from a different ns:
(compute-delayed {:name "John"} #(str "Hello, " (this :name)))
=> :repl/exception!
; 
; Execution error (TypeError) at (<cljs repl>:1).
; presets.example.this$ is undefined
I'm pretty sure I'm missing something about how binding works, something that has to do with namespaces

borkdude14:05:12

SCI is an option for eval (1mb) but #cherry is now also an option (which comes in around 300kb): https://github.com/squint-cljs/cherry/blob/main/doc/embed.md

πŸ™ 2
borkdude14:05:16

You can see here in malli how cherry is integrated: https://github.com/metosin/malli/blob/master/src/malli/cherry.cljs These may not be the right solution to your problem, but if you want to know more join #sci or #cherry and I'll reply there.

πŸ™ 2
Lidor Cohen14:05:37

thanks @U04V15CAJ, I can say that the problem I'm trying to solve is "delayed computation that waits for a context" as thheller pointed out, in its simplest form, it's just a function so I'm investigating that direction for now (it seems way more simple that bringing in an evaluator). P.S With a simple function it already works I'm just trying to workout some syntactic sugar around it...

thheller15:05:38

I still don't have a clue what you are trying to do in the first place, or what you mean by "syntactic sugar" there. binding works with vars (the def kind), and is almost certainly not what you want there

Lidor Cohen16:05:26

By "syntactic sugar" I mean that I don't want to write this:

(fn [this context root parent ...]
(this ...))
I want to write this:
(this ...)
Or
(context ...)
In some specific form (under my control) I want to omit the fn noise and have it added implicitly behind the scenes. It's for a dsl so the main focus here is about syntax and semantics, not the computation itself, the computation already works.

alandipert16:05:22

Usually Vars intended to be defined dynamically are *earmuffed*

alandipert16:05:04

I see "this" defined lexically and dynamic binding appears to be happening only incidentally

alandipert16:05:31

Searching for "dynamic variable Clojure" would probably lead you to the typical uses

πŸ™ 2
Lidor Cohen14:05:15

I think I'm missing something about binding: I have this function:

(defn compute-delayed [env delayed]
  (binding [this env]
    (delayed)))
from within the same ns:
(compute-delayed {:name "John"} #(str "Hello, " (this :name)))
=> "Hello, John"
from a different ns:
(compute-delayed {:name "John"} #(str "Hello, " (this :name)))
=> :repl/exception!
; 
; Execution error (TypeError) at (<cljs repl>:1).
; presets.example.this$ is undefined
I'm pretty sure I'm missing something about how binding works, something that has to do with namespaces

simon15:05:46

Hi all! πŸ‘‹ Are there recommendations on how to use swipe interactions in reagent? I've tried to use react-swipeable, but had no luck implementing it (I guess I don't understand react and react-hooks enough to know how to use them in reagent).

simon18:05:30

Turns out I was using a reagent version < 1.0.0, that’s why :f> was throwing an error.. now it all works with react hooks, and I implemented drag-to-close with framer-motion