Fork me on GitHub
#clojurescript
<
2018-02-21
>
mathpunk00:02:12

but I do still seem to be making progress, thanks @hlolli

mfikes00:02:17

@mathpunk That should be (:require ["fs" :as fs]) (`:as` should be a keyword)

mathpunk00:02:28

hey thanks to all y'all helping me out, I now have a little web service that can generate extremely useful data, such as "Gandalf's music box of crafty second chances" and "an orcish sweater of courage" 😄 https://github.com/mathpunk/sherman

mathpunk00:02:02

another one that made me laugh was "Castamir the Usurper's mantle of ubiquitous second chances"

flyboarder06:02:28

My issue is getting the bindings to resolve to the correct cljs vars

flyboarder06:02:38

when using my list version

flyboarder07:02:43

wait im silly, I figured it out doing way more than I need to be lol

Serge07:02:26

Can I use ClojureScript with React with Lumo compiler?

Serge07:02:22

How can I attach code snippet to Slack? )

benzap08:02:52

How does one alias a macro from namespace A to be used from different namespace B as though it were part of namespace B?

moxaj09:02:22

@benzap (... :require [foo.bar :refer-macros [your-macro]])

moxaj09:02:25

there's also :require-macros with :refer

benzap09:02:19

no no, I mean say I have a macro in namespace A called a.foo, and I create a new namespace B. I want to make an alias of a.foo, within namespace B such that b.foo will refer to a.foo

benzap09:02:55

so when I call (:require [B :refer [foo]]), it will refer to b.foo, which in turn is an alias for a.foo

moxaj09:02:46

afaik best you can do is define a macro foo in B which calls A.foo

benzap09:02:03

I should write some sort of macro to make macro aliases lol

benzap09:02:22

hmm, it doesn't appear to like the macros, does it matter that i'm writing the macros in a .cljc file without reader conditionals?

thheller09:02:36

@benzap (ns my.lib (:require-macros [my.lib])) this lets anyone use my.lib/foo directly whether its a macro or a fn

thheller09:02:50

so (:require [my.lib :refer (foo)]) is probably prefereed over (def foo ...) in the ns itself?

moxaj09:02:05

@thheller I think he'd like some potemkin-like import feature

benzap09:02:31

The problem is I don't want them to use it directly, i'll be more specific, I want to wrap a logging library into shortforms which can be refered to from a local namespace

thheller09:02:32

ah. you can delegate but CLJS itself doesn't have anything for aliasing built-in

benzap09:02:39

ie. I want to refer to taoensso.timbre/info from foo.log --> (require '[foo.log :as log]) (log/i "test") ;; (taoensso.timbre/info "test")

benzap09:02:09

ya, i'm having troubles with the cljs side, clj seems to work, here's what I have: (defmacro i [& args] {tilde}(taoensso.timbre/info ~@args))

benzap09:02:28

on the cljs side, calling (log/i "Test") --> (taoensso.timbre/info)

thheller09:02:43

do you have (ns foo.log (:require-macros [foo.log]))?

thheller09:02:26

add #?(:cljs (:require-macros [hsynapse.log]))

benzap09:02:51

to where it's called?

thheller09:02:12

first thing after (ns hsynapse.log #?(:cljs (:require-macros [hsynapse.log])) ...)

benzap09:02:48

Doesn't appear to make a difference 😞

benzap09:02:23

I think the later clojurescript versions don't need you to use :require-macros, they figured out how to infer it

thheller09:02:45

the client has (:require [hsynapse.log :as log]) (log/i ...)?

benzap09:02:02

here, i'll post the whole file, so you get an idea

benzap09:02:56

so i'm calling (:require [hsynapse.log :as log]) ... (log/enable-logging!)

thheller09:02:24

#?(:cljs (:require-macros [hsynapse.log :refer (i)]))

benzap09:02:52

oh interesting, that works

thheller09:02:20

.cljc files are basically 2 files in one

thheller09:02:40

the defmacro should probably all be in :clj conditionals

benzap09:02:41

so does this mean I can't refer to an aliased namespace macro?

thheller09:02:56

or rather just split it into a .clj and .cljs files to begin with 😛

benzap09:02:14

haha yeah, I was testing my hand at reader conditionals

benzap09:02:20

I might just split them out then

thheller09:02:49

its hard to keep track of what is CLJS and what is CLJ sometimes in those files but basically the CLJS version didn't know what i was so it failed

benzap09:02:18

so from what I can tell, is there no way to shortform the namespace for i?

thheller09:02:54

it gets much easier to understand what is going on if you split the files into .clj and .cljs

thheller09:02:07

reader conditionals just make it super confusing

benzap09:02:32

ah, I think I figured it out

benzap09:02:55

yeah, I see what you mean. so i'm calling :require-macros to drag the defmacro from the :clj conditional

benzap09:02:09

so it's self-referencing it's macro half

benzap09:02:40

yeah, I should probably split this up into separate files

mfikes12:02:37

@benzap Yeah, keeping things separate is better IMHO, but if you really want to cram everything into one file, there is a library that helps with this: https://github.com/cgrand/macrovich

Jacob Haag13:02:53

Hey everyone, my name is Jacob and I have been given the task to test our Clojurescript applications. Currently, we are using "Doo" as our test runner and "Phantom JS" as our environment. One thing I have not been able to find a solution to is how to report our test results (other than just in the cmd). I know there are certain libraries available for formatting test results into JUnit test results but I have not been able to find any that integrate well with the "Doo" runner and "Phantom JS" environment. We would like to avoid using Karma and stick to Phantom JS. Does anybody have any recommendations for a solution to report clojurescript test findings?

sggdfgf13:02:07

is there a difference between ClojurScript and CLJC? in this talk https://www.youtube.com/watch?v=fICC26GGBpg is told that with Foam you have to port all ClojureScript to CLJS :thinking_face:

Olical13:02:11

cljc files just allow you to have clojure specific and clojurescript specific code in one file. There's a reader macro that let's you say "if this code is run in clojure, use this" and the same for clojurescript, other than that, cljc is the same as cljs

Olical13:02:26

It's just a way to store CLJ and CLJS in one file with some special switches. (I apologise if I misunderstood your question though!)

gklijs14:02:14

Kind of, I use it in one project to be able to use the same specs for client and server site rendering

gklijs14:02:31

But the goal should not be to put everything in cljc, just the bits you want to use on both sides, so in my case there are also a lot of functions taking specced data and giving back hiccup-like data structures of the components

gklijs14:02:39

but not much else

bhauman16:02:29

terminals are notorious so its tough to move ahead without a decent number of folks reporting success

bhauman16:02:25

if you find something please report it, and include terminal/platform info

Olical16:02:22

Working beautifully in a fresh lein new figwheel.... I'm on Arch running Termite. https://github.com/thestinger/termite awesome work, can't wait to integrate rebel-repl in more places! Massive jump for usability.

Olical16:02:14

Now get it working in Chrome devtools 😜

chris18:02:01

looks like it's working for me on centos 7 running alacritty

Chris Bidler20:02:47

I’m sure I’m not the first, but it seems to be working great in iTerm2 on macOS. I did find one interesting issue with apropos:

Chris Bidler20:02:51

dev:cljs.user=> (re-find
java.lang.ArithmeticException: Divide by zero
	at clojure.lang.Numbers.divide(Numbers.java:163)
	at clojure.lang.Numbers.divide(Numbers.java:3813)
	at rebel_readline.clojure.line_reader$standard_deviation.invokeStatic(line_reader.clj:619)
	at rebel_readline.clojure.line_reader$standard_deviation.invoke(line_reader.clj:613)
	at rebel_readline.clojure.line_reader$two_standards_plus_mean.invokeStatic(line_reader.clj:625)

Chris Bidler20:02:27

(that was from hitting C-x C-a at the end of re-find, which presumably has nothing for apropos to find)

bhauman00:02:02

that's a good one

gklijs17:02:49

@bhauman working on a small re-frame leiningen project, only had to set the snapshot version

bhauman17:02:25

great I'm assuming its working then, thanks!!

mathpunk22:02:05

holy eff, sherman has its first user other than myself! She too wants to generate text like "Tar Meneldur's blast of non-euclidean sparks"... but, she's not a Clojure user, so I'm trying to compile a server.js file to put in a dist directory. So far no luck. Here are my project.clj and my build.cljs files---

mathpunk22:02:58

but i'm not using the --classpath right, i don't think, because while i compiled something, it throws on running it with node, because it can't find transit

mathpunk22:02:13

oh! i have another problem, where, when I run my program I get errors that it's never heard of the namespace clojure.string, and yet, the functions that rely on it seem to be doing their work. super weird~

mfikes22:02:56

@mathpunk What you are probably seeing is that, in the namespace you are working with, you are calling functions in clojure.string without having required it. This causes the analyzer to complain with some warnings. But, they are just warnings, and the code that gets emitted happens to be correct. And at some point, something did require clojure.string, so the actual functionality is present in JavaScript.

mathpunk22:02:45

Ohhhh yeah that makes sense. In Clojure I've frequently found myself using a single string function once, so I just fully qualify it

mfikes22:02:31

Yeah, simply calling (clojure.string/trimr "abc ") is insufficient. Even though it might work, you really need to ensure that clojure.string is required in the namespace you are in.

noisesmith22:02:49

this can backfire when using namespaces (including clojure.string itself) that might be loaded by your tooling but not required in a direct invocation of your jar

noisesmith22:02:27

there’s minimal extra cost to requiring a namespace everywhere you use it, and it avoids these gotchas

mfikes22:02:38

Yeah, in other words, requiring a namespace essentially mutates the environment. But correct code puts all of its requried namespaces in its ns, form (for lack of a better way of putting it). One way this can bite you is, for example, if you enable parallel compilation in ClojureScript, and by chance, your namespace that is using clojure.string gets compiled first.

mfikes22:02:17

On this subject, @mathpunk there is an interesting compiler option, :analyze-path. This post might be informative and help understand this particular issue a little better: http://blog.fikesfarm.com/posts/2015-06-10-analyze-path-ftw.html

mathpunk22:02:40

I'm glad I have learned this before getting bitten by it, because (as I've made clear in #beginners) my mental model on what abstractions belong in the language, the runtime, and the tooling is fairly fuzzy

noisesmith22:02:59

I think that’s normal actually. 80% of the features people think come from their tools come from the language, and 90% of what people think comes from the language comes from the runtime. To make a wild estimate.

justinlee22:02:50

67% of @U051SS2EU’s statistics are made up on the spot 😛

mikerod23:02:05

I recall this subject coming up before with Alex Miller too. I was curious on the “reliability” of using some clojure/core namespaces that just happen to be pe-required on Clojure startup. If I recall correctly, he said that they are not something you should rely on. This is just reiterating what others have already said on this thread though. One relevant example that comes to mind is, eg. if Clojure was tweaked to speed up start-up time. It may be the case it “accidentally” requires a namespace right now that isn’t needed to startup. If it later removes that implicit require, your code may be broken if it relied on “some other namespace” to require the namespace for you. This same principle also applies to if you are implicitly getting a namespace loaded transitively by some library you depend on. That is an impl detail of that lib and could change and break you later. The whole subject reminds me of Maven (and probably other tools) best practice of not relying on transitive dependencies.

noisesmith23:02:37

iirc the only one that won’t ever be absent is http://clojure.java.io but even that could be missing in some future version, and adding a require for something is basically free, so…

mfikes23:02:46

IIRC, the same thing that occurs in ClojureScript is that goog.object, goog.string, and goog.array are always loaded, but strictly speaking, you shouldn't rely on this.

mfikes23:02:12

Perhaps the only things you can rely on are clojure.core and cljs.core 🙂

mikerod23:02:04

Sounds right

souenzzo15:02:35

There is any available linter/tool to check these kind of problem?