Fork me on GitHub
#clojurescript
<
2017-02-13
>
tony.kay01:02:34

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?

tony.kay01:02:41

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

anmonteiro01:02:32

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

anmonteiro01:02:50

the CLJC file is the macros file

tony.kay01:02:01

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

tony.kay01:02:06

and if so, in which order?

anmonteiro01:02:41

no merging happens

anmonteiro01:02:55

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

anmonteiro01:02:15

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

tony.kay01:02:22

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

tony.kay01:02:41

oh...so you're saying you would not put anything but macros in the cljc file?

tony.kay01:02:07

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

tony.kay01:02:51

do you see my concern here?

tony.kay01:02:04

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

tony.kay01:02:13

but not merged?

tony.kay01:02:17

how do I know what I get?

anmonteiro01:02:31

I don't understand what your problem is

tony.kay01:02:32

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

tony.kay01:02:41

Do I have both fns in my end product?

anmonteiro01:02:47

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

anmonteiro01:02:29

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

tony.kay01:02:02

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

tony.kay01:02:51

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

anmonteiro01:02:03

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

anmonteiro01:02:35

and current support doesn't work in every case

tony.kay01:02:20

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

anmonteiro01:02:00

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

anmonteiro01:02:14

AFAIK it's considered an advanced feature

anmonteiro01:02:26

it's also very new comparatively

tony.kay01:02:19

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

tony.kay01:02:46

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

tony.kay01:02:49

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.

tony.kay01:02:01

thanks again for the help

tony.kay01:02:24

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

sooheon01:02:39

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

sooheon01:02:30

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

mfikes01:02:16

@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, http://dev.clojure.org/jira/browse/CLJ-1797 needs to be accepted / landed.

tony.kay02:02:38

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

tony.kay02:02:12

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.

tony.kay02:02:50

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

tony.kay02:02:03

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

mfikes02:02:37

The ability to affect ordering of requires is actually very new http://dev.clojure.org/jira/browse/CLJS-1453

tony.kay02:02:24

oh, that's something different

tony.kay02:02:51

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

mfikes02:02:58

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

tony.kay02:02:19

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

mfikes02:02:32

It is all to easy to misinterpret English. 🙂

tony.kay02:02:46

thanks again for the blog post. That helped me

tdavis02:02:37

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)

grav09:02:49

Just tried using namespace aliasing (http://blog.fikesfarm.com/posts/2016-07-03-clojurescript-clojure-namespace-aliasing.html) with clojure.test, but it seems

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

grav09:02:03

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

thheller09:02:55

:refer :all is not supported in CLJS

thheller09:02:10

alias or not

thheller11:02:37

@tomaas probably a better question for #reagent

conan11:02:48

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?

pesterhazy12:02:53

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

pesterhazy12:02:31

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

pesterhazy12:02:27

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

pesterhazy12:02:06

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

pesterhazy12:02:53

+ get them hooked on 4clojure and klipse

pesterhazy12:02:42

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

gklijs13:02:16

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

ejelome13:02:59

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

arnaud_bos13:02:17

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.

ejelome13:02:20

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

conan13:02:34

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

conan13:02:43

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

conan13:02:00

i suppose i'll have to learn it first

conan13:02:32

@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

conan13:02:36

@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!

ejelome13:02:40

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

arnaud_bos13:02:08

@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.

Aron13:02:20

js fatigue?

conan13:02:49

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

Aron14:02:12

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

dnolen14:02:22

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

Aron14:02:37

i would first try to show them Elm though

dnolen14:02:40

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

mikebelanger14:02:41

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

Aron14:02:37

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

conan14:02:10

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

dnolen14:02:55

I don’t know about that

dnolen14:02:18

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

dnolen14:02:34

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

dnolen14:02:06

and I don’t mean expert by “know"

conan14:02:25

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.

conan14:02:56

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

Aron14:02:19

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

conan14:02:46

yeah true

Aron14:02:25

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 🙂

dnolen14:02:29

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

Aron14:02:36

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.

ejelome14:02:44

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 https://clojurians.slack.com/archives/clojurescript/p1486994360018581

ejelome14:02:39

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

Aron14:02:16

@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 🙂

ejelome14:02:24

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) https://en.wikipedia.org/wiki/Curse_of_knowledge

Aron14:02:01

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

ejelome14:02:26

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

ejelome14:02:40

so yeah, different experiences and different results 😄

Aron14:02:14

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

Aron14:02:30

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

ejelome14:02:05

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

Aron14:02:39

same here

Aron14:02:47

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

Aron14:02:06

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

ejelome14:02:14

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

mss15:02:38

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

Aron15:02:03

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

Aron15:02:43

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

dnolen15:02:41

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

dnolen15:02:54

the collection validators assume Clojure collections

dnolen15:02:07

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

dnolen15:02:23

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

kah0ona15:02:57

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

kah0ona15:02:14

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

kah0ona15:02:22

or do something particular client-side

mss15:02:24

interesting, thanks for the feedback everyone

dnolen15:02:57

@kah0ona that’s a floating point value

kah0ona15:02:44

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)

kah0ona15:02:10

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

kah0ona15:02:14

client side

dnolen15:02:27

well now you have to care

kah0ona15:02:34

yeah 🙂 hehe

dnolen15:02:38

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

kah0ona15:02:42

i'd love not to tho;-)

kah0ona15:02:00

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

dnolen15:02:04

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

kah0ona15:02:52

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

kah0ona15:02:28

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

darwin15:02:00

@mss: haven’t done any deep spec work yet, but had to write this and use it instead of s/* for js arrays: https://github.com/binaryage/cljs-oops/blob/master/src/lib/oops/spec.clj

mss15:02:30

def helpful, thank you

hlolli18:02:31

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

(require '[cemerick.piggieback]
         '[cljs.repl.node])
(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])
nil
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.run (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.

hlolli18:02:42

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))
nil
nil
ClojureScript Node.js REPL server listening on 54510
To quit, type: :cljs/quit
cljs.user=> (require '[cljs.core.async :as async])
true
cljs.user=> (async/chan)  
#object[cljs.core.async.impl.channels.ManyToManyChannel]

pesterhazy18:02:47

the simple cljs.repl/repl is severely underappreciated

hlolli18:02:56

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

hlolli19:02:04

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.

sova-soars-the-sora21:02:01

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: https://gist.github.com/anonymous/e9e4c1c1c3d40afaf49cf6be154ae87a

vikeri22:02:04

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))

anmonteiro22:02:06

@vikeri try binding *out* to *err*

anmonteiro22:02:19

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

vikeri22:02:44

@anmonteiro Thanks! It worked, not super obvious though

anmonteiro22:02:18

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

anmonteiro22:02:29

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

anmonteiro22:02:00

it'll end up in your compiled output

vikeri22:02:16

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: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure

PB22:02:51

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

anmonteiro22:02:55

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

anmonteiro22:02:28

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

anmonteiro22:02:05

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

vikeri22:02:02

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

vikeri22:02:22

Didn’t know about the internals of the compiler

rayk22:02:20

@petr have you looked at https://clojurescript.org/guides/externs . I actually have Gun on my list and get around to looking at using it in the next couple of weeks

PB22:02:26

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

metametadata23:02:50

@rayk @petr speaking of externs, I stumbled upon this today: https://github.com/binaryage/cljs-oops#externs-from-hell and kinda like this alternative approach (in theory at least)

rafaelzlisboa23:02:43

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)