Fork me on GitHub

I've noticed in cljs.core there are cljc and cljs files for the same namespace. I don't see any documentation on doing this, and it seems a bit strange to me to not at least say the order of evaluation. Or is this just an internal artifact of that source base that you should not do in your own projects?


not that I want to do it...things that surprise me just make me think I'm not understanding things well enough


@tony.kay the only reason to do it is supporting regular + self-hosted ClojureScript


the CLJC file is the macros file


I see. But if you then put cljs in that file, does it just merge with the .cljs file?


and if so, in which order?


no merging happens


one is treated as a CLJS file, the other as a macros file


in that case, the cljc file is only used to expand the macros


but what if there are functions in the cljc file that has no reader conditional?

tony.kay01:02:41 you're saying you would not put anything but macros in the cljc file?


I had assumed that self-hosted cljs could just use cljc files


do you see my concern here?


so I put cljs in a cljc file and have a cljs file


but not merged?


how do I know what I get?


I don't understand what your problem is


(defn f [a] ..) in cljc file and (defn g [b] ) in cljs file.


Do I have both fns in my end product?


here's how the compiler figures things out: looking for a non-macros namespace: .cljs, only check for .cljc if the first doesnt exist looking for a macros namsepace: clj, then cljc if clj doesn't exist


@tony.kay if both files declare the same namespace, only g should be in your end product


that was my question. No docs I could find specify that is the behavior...but if I have just a cljc file I would certainly get f


but if I can use cljc when self-hosting, why would I ever want to confuse myself by having cljs and cljc


until very recently there wasn't support in the self-hosted compiler for the single .cljc file pattern


and current support doesn't work in every case


I see. OK. The rules help. Might make sense for those to end up in some kind of docs. Or perhaps they are and I didn't find them


there's lots of documentation missing for the self-hosted compiler


AFAIK it's considered an advanced feature


it's also very new comparatively


yeah, and I understand these things get "grown and corrected". Just in the interest of trying to get my libraries "right" for general consumption


I keep doing macros subtly wrong, and decided to dedicate today to at least understanding what I don't clearly understand


and while I'm already working on them, might as well at least make some effort to ensure I won't have to do it again.


thanks again for the help


I assume "looking for a macros namsepace: clj, then cljc if cljc doesn't exist" has a typo


How do I add an async attribute in hiccup? <script async src=…>


Ah duh, [:script {:async true}]...


@tony.kay It is interesting that this appears to be undocumented. (Perhaps that can be addressed.) Related aspect that might help: If in a REPL you do (require ‘foo.core) and it doesn’t exist, the error message indicates the order in which the loads were attempted. For (require-macros ‘foo.core) to work, needs to be accepted / landed.


thanks for the tip. At the moment I'm aimed at getting libraries that support both clj and cljs right.


the implicit loading (with refer on macros) also seems to be a bit buggy, I think. It looks like if I have a namespace pulling in something with require-macros that gets compiled before one that is trying to do implicit loading on a file that does not self-refer, then it will compile even though it should not.


it's like the earlier require macros has pre-loaded the macros so that the incorrect file "gets away" with it


yeah, I just verified that. Not nice to have a compilation that is order-dependent 😞


The ability to affect ordering of requires is actually very new


oh, that's something different


This is file a.cljs does an include-macros, and file b.cljs works "by accident" because it compiles later


Ahh. Perhaps a concrete example (maybe in a Gist) would help understand.


yeah, I'm working on a large library. Will have to distill, but don't want to get sidetracked just now 😕


It is all to easy to misinterpret English. 🙂


thanks again for the blog post. That helped me


anybody know how to get a def'd value to be a default when using goog-define? For instance, (def thing "abc") (goog-define foo thing) fails because goog-define is a macro and receives the symbol thing. Unfortunately, my go to of (goog-define foo ~thing) doesn't work either. do i need to do something weird like wrap the call in my own macro and call that?

Oliver George03:02:53

This is what I have, seems to work.

Oliver George03:02:09

(declare use-fragment) (goog-define use-fragment false)


Just tried using namespace aliasing ( with clojure.test, but it seems

(ns foo-test
    [clojure.test :refer :all]))
does not work, whereas
(ns foo-test
    [clojure.test :refer [deftest testing is]]))
does work. Is it a bug in ClojureScript?


I get clojure.lang.ExceptionInfo: Don't know how to create ISeq from: clojure.lang.Keyword at line 1 when using the former


:refer :all is not supported in CLJS


alias or not


@tomaas probably a better question for #reagent


I need some advice. I've agreed to teach a friend web development, starting from nothing. Right now he's just learning HTML and CSS, but soon we'll need to start doing some JavaScript. It feels like I ought to teach him vanilla JS to start with as it's an essential skill, but I'm very tempted just to jump in with ClojureScript because the experience is so much nicer, and I'm often told functional programming is easier to learn before procedural. Does anyone have any recommendations?


IMO in the context of web programming, cljs is probably harder because you can't get away with not understanding javascript


you need to understand the host to some degree -- not perfectly but enough to make educated guesses


JS has googleability on its side, and codepen etc. make it easy to collaborate and experiment


my vote is for some JS before diving into CLJS, as otherwise the fear is you'll get stuck eventually


+ get them hooked on 4clojure and klipse


the other thing is, you as a teacher also count so if you enjoy teaching cljs more, maybe that's a consideration?


I have a very good experience using re-frame, and done very little with JS before. So I think you could ‘skip’ the JS part, as long as you setup the project to some degree


try giving the learner jquery and let the guy experiment, then guide the guy how to implement that in cljs


Hi @conan 🙂 I guess it depends what for. I mean if it's in order to get a job right away, I would personally skip Cljs and go to JS only I think. I wouldn't put the burden of having to evangelize people to a friend of mine if all he wants is a career change, even if I wouldn't mind having a side-kick in my local area ^^ On the other hand if it's in order to work with you on a particular project where you happen to use Cljs, then, why not. My 2 cents.


I guess for a total beginner, it's html -> css -> jquery -> vanilla js -> clojurescript, there's too much advanced topics in clojure(script) that will hurt a beginner


No, it's just for getting a new job, and I think you're right


Oh, good idea on the jquery, as someone who doesn't write much JS i wouldn't have thought of that


i suppose i'll have to learn it first


@gklijs yeah, the aim is really for him to be able to set up his own projects, and of course i was only thinking about the project. i'm not convinced bower + npm is any easier than leiningen or boot, but there is a lot more help out there


@pesterhazy that's a good point about what i enjoy teaching, but to be honest it probably wouldn't hurt for me to brush up my js skills rather than sticking to what i know!


warn the guy about js fatigue though, at least while it's still early


@conan hi 🙂 congrats for the launch! Last year I gave a JS training course and one of the attendees was new to programming and used to "do" websites using jQuery, I noticed quickly he had no programming background at all, and the moment he had to do more advanced stuff or even debug, he was stuck in great pain. I took him appart and went back to basics with him. So don't skip the basic before introducing jQuery I would suggest.


js fatigue?


thanks! yeah, i'm a believer in the basics... i just need to learn them myself


i don't think clojure in itself is too advanced for a beginner, but i do think that the tooling is too hard even for an advanced user to pick it up from scratch


@conan I agree if you’re just trying to intro somebody into web programming - start with JavaScript


i would first try to show them Elm though


I’m on the fence about full stack though - I don’t personally like Node.js for backend stuff


bower and npm are definitely harder than boot/leiningen, but they're also more resume-friendly, sadly.


i would give up boot/leiningen for npm, bower is crap 😄


@dnolen yeah, it does seem a shame though. i wouldn't feel the need to teach somebody java before clojure


I don’t know about that


If you do Clojure you need to know Java if you do ClojureScript you need to know JavaScript


maybe there’s some variance for the beginners but that’s where you end up pretty quick


and I don’t mean expert by “know"


i definitely think it helps to understand the runtime, and you're always going to fall back on interop for some things. starting out though, you could build plenty of useful projects using just clojure, with no understanding of OOP and other things from the Java world. I'd say knowing how the JVM works is more valuable than actually learning Java for a Clojure engineer.


By the same token, knowing how the browser works is valuable for a ClojureScript engineer.


i think knowing how a VM works is already quite an advanced topic be it the JVM or v8 or whatever else


yeah true


but i do agree that you should be able to do a lot without knowing Java or Javascript, using just clojure/script. the fact that this is not the case is a huge missed opportunity imho, but i am alone with this view 🙂


@conan yeah you’re right - and that’s what I mean some platform understanding is necessary


not everyone can afford that. Halfway through learning clojure it seems to me that the learning curve is kept artificially high just so the practitioners can be conceited about their skills. Just the same what I see in academia everywhere.


too many choices (libraries, frameworks, platforms), too many concepts for each topic (react, ssjs, flux, etc.), and if you start with cljs, it's a diff way of thinking (immutable, atom, repl, macros, etc), it might look easy for us since we've past that understanding stage, but for someone who never touched JS, just imagine their horror


... and I don't think I even understood those well, hahaha


@ejelome I think I avoided this because since I got burned with jquery, I have been careful not to sit on any of the hype trains, and focused on things I could understand. I am using browserify, virtual-dom, toolings around these, for me there are not really too many choices, because there are too many drawback for each of them, there are not many concepts because I don't think they give more than what they require. I used cljs data structures from javascript and it is better than without, and you don't need to be very smart to see this. The different way of thinking appears already with libraries as Ramda or other languages like Elm. I admit that if people have no help, every large ecosystem looks scary, but my claim is that you can narrow javascript down to a minimal set of tools and concepts that give you just enough to do what you want, without causing fatigue. That's obviously not the case if you sit on one of these large hype trains and try to keep up with everything that's happening. Too much noise 🙂


someone hit me with this before and he was right, it changed the way how I think and approach beginners (esp. if you want to share something to them)


yeah, this link could be pinned here to be mentioned regularly when people ask beginners to write docs 😄


I agree if you always have the freedom to choose your tools, but on a work environment, where diff requirements and diff level of hype (or noise) exists, it becomes a diff story XD


so yeah, different experiences and different results 😄


i've been careful to choose my work environments ever since i was told that jquery != javascript


nowadays i mostly choose what i use depending on the needs of the project


that's great, really, back then, I wish I had someone to mentor me, I was self taught all these years, so I have to learn the hard mistakes just to realize I was/going to the wrong direction, haha


same here


i had a colleague at my first job as a "web developer" in 2004 who told me that lisp is stupid and a waste of time and i did not know it better, i had such respect toward them, i believed it completely and took me a lot of time to look again


huge mistake, i could've learned much faster about a lot of important things that are in any lisp


that's just life I guess, but at least we're still going in the right direction 🙂


anyone have any tips or tricks spec-ing js objects? wondering if that’s even possible


well, i think it's not the best way but clj->js or js/obj and then setting properties both are working possibilities


unless you mean clojure.spec in which case i don't think that is going to work, but i am curious


@mss it’s totally possible but you’ll have to dig in a bit into how spec works


the collection validators assume Clojure collections


but you just need to write your own thing for JS objects


admittedly it’s advanced but somebody should try to figure it out and share a gist or something


Question: My rest API now returns transit, but in clojurescript I now and then see [Tagged Value, f, 8] rendered, rather than 8


What is the solution to this, should I update/change the API on the server side?


or do something particular client-side


interesting, thanks for the feedback everyone


@kah0ona that’s a floating point value


yeah but before i didn't have to care, basically my rest api does a DB query using yesql, and I basically return that vector of maps (db records)


so i wonder what 's recommended, should i parse those?


client side


well now you have to care


yeah 🙂 hehe


if you want to pass integers, you need to make sure you’re doing that 🙂


i'd love not to tho;-)


ok so that implies making sure the server side returns int's in that case


well most people don’t want that behavior though, so I don’t know what to say


this basically 'happened' when upgrading both compojure (server-side) and clojurescript / cljs-ajax to the latest version if i remember correctly


good thing, it's now transit (if that's better than json that is ;-)), bad thing i have to deal with this some way


@mss: haven’t done any deep spec work yet, but had to write this and use it instead of s/* for js arrays:


def helpful, thank you


I jack-in cider and start node.js repl via

(require '[cemerick.piggieback]
(cemerick.piggieback/cljs-repl :repl-env (cljs.repl.node/repl-env))
Now I want to use core.async
core> (require '[cljs.core.async :as async])
core> (async/chan)
ExceptionInfo TypeError: Cannot read property 'chan' of undefined
    at repl:1:84
    at repl:9:3
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.exports.runInThisContext (vm.js:77:17)
    at Domain.<anonymous> ([stdin]:50:34)
    at (domain.js:221:14)
    at Socket.<anonymous> ([stdin]:49:25)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)  clojure.core/ex-info (core.clj:4617)
Im running on versoins
[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.456"]
[org.clojure/core.async "0.2.395"]
I've never used node.js repl much, but I can't see what could be causing it not to work core.async.


ok lesson learned, this error was caused by the piggieback cljs-repl. Core.async works okay like this

user=> (require 'cljs.repl) (require 'cljs.repl.node) (cljs.repl/repl (cljs.repl.node/repl-env))
ClojureScript Node.js REPL server listening on 54510
To quit, type: :cljs/quit
cljs.user=> (require '[cljs.core.async :as async])
cljs.user=> (async/chan)  


the simple cljs.repl/repl is severely underappreciated


With core.async working now with piggieback missing, I can't user cider, as it doesn't detect cljs repl.


ok for slack.logs storage, don't use old version of piggieback 🙂 bit confusing that the github releases has latest 0.1.5 but on clojars its 0.2.2. That was causing all of this confusion.


How does one change the URL location in cljs? /beginner's question

Oliver George21:02:35

@samcf here's a quick dump of my code for managing browser locations in a re-frame app:


Why can’t I seem to get compile time println to work? Calling this macro fails:

(defmacro printer [s]
  (println "Compile time:" s)
  (list 'println "Runtime:" s))


@vikeri try binding *out* to *err*


(binding [*out* *err*]
  (println "hi"))


@anmonteiro Thanks! It worked, not super obvious though


the problem is that *out* is bound to the file the compiler is outputting to at that moment


so you'll get your thing printed, just not to the console 🙂


it'll end up in your compiled output


I see, it is not possible to automatically bind *out* to *err* around println statements? It works in clj but not in cljs. At least it probably should be added to:


What is the best way to use a library that is not currently a clsjs package?


@vikeri I'm not sure what you're asking


*out* is explicitly bound to the IO writer for which we're outputing JS at that point in the compilation process


because cljs.compiler functions use print and println to compile CLJS->JS


@anmonteiro Ah ok, then it’s not a good idea


Didn’t know about the internals of the compiler


@petr have you looked at . I actually have Gun on my list and get around to looking at using it in the next couple of weeks


@rayk I haven’t. I’ll take a look at it shortly. Thank you


@rayk @petr speaking of externs, I stumbled upon this today: and kinda like this alternative approach (in theory at least)


open question: what would you use for an animations-heavy frontend? (i have the overall feeling that react-based stuff aren't quite the thing for it)