This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-02
Channels
- # announcements (1)
- # babashka (4)
- # beginners (39)
- # calva (36)
- # cherry (11)
- # cider (23)
- # clj-on-windows (3)
- # clojure (105)
- # clojure-brasil (1)
- # clojure-chicago (3)
- # clojure-conj (8)
- # clojure-denver (4)
- # clojure-europe (18)
- # clojure-germany (5)
- # clojure-hungary (13)
- # clojure-nl (1)
- # clojure-norway (31)
- # clojure-sweden (9)
- # clojure-uk (2)
- # clojurescript (22)
- # core-async (4)
- # cursive (8)
- # data-science (25)
- # datomic (14)
- # devops (1)
- # emacs (9)
- # events (5)
- # holy-lambda (32)
- # hyperfiddle (26)
- # introduce-yourself (2)
- # kaocha (1)
- # leiningen (11)
- # lsp (17)
- # malli (8)
- # off-topic (84)
- # pedestal (4)
- # polylith (2)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (8)
- # sql (4)
- # tools-deps (8)
- # transit (5)
- # vim (1)
- # vscode (1)
- # xtdb (45)
Is it discouraged to eval in cljs runtime?
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
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.
don't know what eval has to do with that? sounds like a function that takes a parameter?
eval could have been used to evaluate the quoted expression as means of delay
delay
is one alternative
another would be a function like you said
it is mostly a syntactic sugar concern
no clue what you are talking about π but it doesn't sound like you want your build to grow by 5mb to get eval
Yeah, I figured that. I asked to be more sure of what I'm doing π
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 namespacesSCI 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
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.
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...
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
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.Usually Vars intended to be defined dynamically are *earmuffed*
I see "this" defined lexically and dynamic binding appears to be happening only incidentally
Searching for "dynamic variable Clojure" would probably lead you to the typical uses
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