Fork me on GitHub
#clojure
<
2019-01-03
>
Jeremy02:01:50

Does anyone know of a good way to "sandbox" the loading of namespaces? I'm trying to find a way to load and evaluate a namespace from an external source without interfering with the bindings in my current Clojure process' instance of the same namespace.

rutledgepaulv04:01:58

I made this a while ago for that purpose: https://github.com/RutledgePaulV/clj-embed I keep meaning to come back and update it a bit. If you end up using it let me know and I’ll bring it up to date and cut a new release

andy.fingerhut07:01:21

There is a mranderson library that can create a "shadowed" version of a namespace, meaning renamed. I have not used it myself, but I know some other libraries have used it: https://github.com/benedekfazekas/mranderson

Jeremy18:01:12

Thanks guys! I had seen mranderson from where refactor-nrepl uses it to deal with this problem, but that solution seems a little more finicky than I was hoping for. clj-embed looks cool! The classloader solution-route was what I was hoping to find examples for.

Jeremy18:01:50

In the short term, I think I will forgo the namespace isolation requirement in my project, in order to focus on exercising the other aspects of the project. Later, I'll plan on attempting to incorporate clj-embed. So no hurry @U5RCSJ6BB, but thank you.

👍 5
seancorfield02:01:57

@jrsnyder13 Perhaps look at the clojail project?

seancorfield02:01:37

That will also make it safe to load and run that code (or at least safer) since it's coming from an external source...

sneakypeet09:01:54

Does anyone have an example of deploying a clojure library to clojars from gitlab-ci?

niels10:01:14

in for answer

Andreas Liljeqvist14:01:52

Is there any syntax that will help me include a specific key/val in a map depending on clojure/clojurescript target? I know of #?(:clj), but usable inside a map form

Andreas Liljeqvist14:01:31

I can wrap the whole thing in assoc of course, but still

Alex Miller (Clojure team)14:01:54

can you use the splicing reader conditional?

Alex Miller (Clojure team)14:01:25

could use a cond-> whose test is a reader conditional

Alex Miller (Clojure team)14:01:26

(cond-> { … } #?(:clj true :cljs false) (assoc :clj-only :foo))

Andreas Liljeqvist14:01:12

@alexmiller Thanks, splicing reader was what I was looking for.

dpsutton14:01:37

did the splicing reader work for you?

Andreas Liljeqvist14:01:12

{#?@(:clj [:key :val])}

Alex Miller (Clojure team)14:01:24

I’m a little surprised that works but I guess it makes sense

Alex Miller (Clojure team)14:01:54

it wouldn’t surprise me if that gives trouble to other tools with their own lexers

Lennart Buit14:01:57

Interesting syntax tho, #?@(...)

Alex Miller (Clojure team)14:01:19

as it looks like a map with an odd number of elements until it’s read

dpsutton14:01:17

would that break edn reading of a file with those forms?

Alex Miller (Clojure team)14:01:59

edn doesn’t have reader conditionals

👍 10
alex-eberts16:01:11

Does anyone know how to configure the built-in MacOS firewall to permanently accept incoming connections? I've added the version of java to the firewall but I'm stick stuck clicking "allow" each time I restart the server.

genmeblog18:01:30

Is there any way to determine in custom macro whether passed symbol is macro or function?

genmeblog18:01:32

my test is (:macro (meta (var loop)))

genmeblog18:01:03

of course this doesn't work here

(defmacro is-macro? [sym]
  (let [m? (:macro (meta (var sym)))]
    `~m?))

genmeblog18:01:25

is there any way to resolve sym within a macro?

john18:01:39

resolve?

jumpnbrownweasel18:01:29

(Note that you can't resolve vars in Clojurescript macros.)

john18:01:47

Except at compile-time, depending on... things

john18:01:06

I banged on this until it worked. It might not work in all situations though https://github.com/johnmn3/dispacio/blob/master/src/dispacio/alpha/core.cljc#L156

jumpnbrownweasel18:01:53

Interesting, thanks!! Earlier I couldn't figure out a way to do it, and just found a way to avoid the need for it, but I'll hang on to this for future reference.

john18:01:26

It doesn't work in most ways, you're right. There's just certain situations where you can get it to work.

john18:01:52

And I don't understand the interplay well enough to explain when it does or doesn't. But it works there 🙂

jumpnbrownweasel18:01:11

Could come in handy.

genmeblog18:01:50

it's in Clojure

genmeblog18:01:18

works! thanks a lot

dpsutton18:01:44

just for curiosity can you explain why you need to know?

genmeblog18:01:29

I have math functions and some of them are expressed as macros (java calls) and some of them are clj functions. I want to wrap such macros into functions (and avoid wrapping functions) to generate rest of the code.

genmeblog18:01:39

so my macro checks symbol and generated function or leave symbol unwrapped

(if (:macro (meta (resolve f))) `(fn [v#] (~f v#)) f)
which is used in final generated code

noisesmith18:01:39

one possible gotcha is if you get a function literal instead of a symbol bound to an fn

noisesmith18:01:19

"cannot embed object in bytecode" is the error message IIRC

genmeblog18:01:31

fortunately I operate on symbols here, it's a private macro and should be ok in my case

noisesmith21:01:45

Why recur with objs in one tail, and sorted-objs in another, when both are the same value?

noisesmith21:01:23

oh I see, there's a path where you want to use sorted-objs, even as objs got rebound, I get it now

emccue21:01:59

yeah, the fact that it is confusing is my reason for posting

emccue21:01:28

had a hope someone would have insight on how to simplify it

noisesmith21:01:03

maybe there's a way to turn the path that recurs with rest into a normal reduce, and the one that recurs with sorted-objs into a recur on the enclosing fn?

noisesmith21:01:09

just a thought

emccue21:01:29

got some... fun recursion

aria4222:01:08

Weird request, but working on a perf improvement to something and want to provide a realistic benchmark on public data. Tried randomly generating data, but issue is time is dominated by things that are artifacts of random data you wouldn't see in practice (for instance, all keywords are distinct and very long). I don't want to try to generate "realsitic data since that seems bad and want to know if someone has some large public batch of EDN data laying around that might be 'representative' of real-world data, or even better something someone's used to benchmark before