Fork me on GitHub
#clojurescript
<
2015-08-04
>
malcolmsparks08:08:11

nice to see Håkan's cljs2go project on HN this morning

maleghast08:08:57

@malcolmsparks: Yep, I up-voted it; that man is a unique genius, and I’m being serious, there is just nothing he can’t do as far as I can tell! simple_smile

robert-stuttaford09:08:35

@andrewmcveigh: are you around? i have a cljs-time question

robert-stuttaford09:08:03

to format local-dates as strings, i need to make them date-times. this appears to apply a utc modifier, turning march 3 into march 2 at 22:00. how do i stop it from doing this? i want march 3, 00:00

robert-stuttaford09:08:56

looks like i need to rub some cljs-time.local on it

robert-stuttaford09:08:20

running the dates to be formatted for display with cljs-time.local/as-local-date-time-to-time-zone works

andrewmcveigh09:08:29

Yeah, I’m here

andrewmcveigh09:08:51

Just catching up...

andrewmcveigh09:08:15

If you start with a ‘local-date-time’ the formatting should work I think.

andrewmcveigh09:08:40

How do you obtain the local-dates?

robert-stuttaford09:08:51

core/today, core/minus, core/first-day-of-month, etc

robert-stuttaford09:08:03

it’s all good now

robert-stuttaford09:08:08

thanks for a great library, btw!

andrewmcveigh10:08:22

cool. The local stuff is something I’ve not used personally in a while, so let me know if you find any weirdness!

borkdude12:08:58

I suddenly realized that with self hosted clojurescript, things like 4clojure etc can now be entirely client side

borkdude12:08:06

except for storing scores etc of course

dnolen12:08:45

@borkdude: I’m waiting with bated breath for a full ClojureScript executable gist-like service.

dnolen12:08:08

something more like JSFiddle, http://jsfiddle.net

hmadelaine12:08:19

@borkdude: Yes it is very good for tutorial and learning in general. I am in the process of using it to set up a playground for one of my oss project.

dnolen12:08:32

cljsfiddle is OK, but with bootstrapped but could be way simpler better experience

dnolen12:08:42

I’m sure @jonas is already on it 😉

hmadelaine12:08:11

@dnolen: I am struggling a little bit with cljs.js but it is good to understand how it works. I was very interested bay the discussion you had with @mhuebert yesterday. I hope a nice blog post will come 😉

dnolen12:08:40

@hmadelaine: I might write up something about using it but unsure there are some things that are just tricky to explain

dnolen12:08:41

ClojureScript JS keeps the var environment separate just like ClojureScript JVM, so this complication is just something people need to understand

dnolen12:08:15

but it introduces lots of brain warping issues around the fact that the thing that bootstraps does not really pass anything on to the bootstrapped thing in terms of the var environment

hmadelaine12:08:59

@dnolen: yes you talked about it yesterday. I have to keep that in mind. Thank you very much for this invaluable gift !

hmadelaine12:08:39

Is there a way to export conversations from slack ? This is a gold mine but the nuggets are ephemeral

dnolen12:08:38

@hmadelaine: np, I think in a couple of months or so people will have a better grasp how it works and I suspect things will move pretty quickly thereafter. This conversation has convinced me to write up a brief advanced tutorial on bootstrapping that at least covers the subtleties people are likely to encounter.

hmadelaine12:08:26

@dmich thank you very much !

mhuebert16:08:49

I wrote up a gist explaining what I have learned about loading analysis caches in cljs.js (to eval code using existing namespaces in a project): https://gist.github.com/mhuebert/18a1ef480d1bb0b0a270. Of course, all feedback is welcome, I’m still learning. Many thanks to @mfikes and @dnolen for helpful conversations as I’ve tried to get this all working.

mfikes16:08:14

@mhuebert: One additional fun thing to consider: If the expression you are evaluating is a def or derived from it, then it will add to the analysis cache. (This is how Planck does tab completion on things you define at the REPL, for example.)

mfikes16:08:15

@mhuebert: (Instead of leting the state, you can do a top-level def of it and keep it around—it is an atom internally.)

mfikes16:08:20

(It is also fundamentally how bootstrapped REPLs don’t complain when you try to call fns defined in the REPL.)

mhuebert16:08:47

@mfikes: good point. Understanding that the compiler state is an atom is also very helpful for debugging- I found myself going in there to see what was being defined, etc

hmadelaine17:08:23

@mhuebert: thank you very much ! I will put this into practice tomorrow simple_smile It will save me a lot of time !

exitcode017:08:28

are letfn local functions discouraged in clojure?

exitcode017:08:04

and is a 55 line fnction considered too long? even if there are no clear reusable parts?

potetm17:08:51

@exitcode0: letfn isn’t discouraged. It’s just not often used. People tend to prefer just letting a fn (like (let [my-fn (fn [] ..)] …)) unless they need recursion.

potetm17:08:46

Length of a fn is in part a stylistic choice. But breaking it up isn’t all about reusability (i.e. how many times will this chuck of code be called). It’s about simplicity (i.e. is this chuck of code one thing). Reusability informs simplicity, but it doesn’t define it.

potetm17:08:58

I tend to try to put an emphasis on simple functions, regardless of length. If I’ve broken it up as far as I can, and it’s still hard to read, I might let a variable or a fn, give it a good name as documentation.

exitcode017:08:10

@potetm here is the code in question http://pastebin.com/

exitcode017:08:23

oops hold on

exitcode017:08:40

I am being informed right now that I should divide up the individual html elements being drawn on the page - this one function is the only place they would be called though

potetm17:08:02

It looks like this component handles tabs yes?

exitcode017:08:47

and the entire webpage around it

exitcode017:08:53

include a side navigation

potetm17:08:11

That seems like a reasonable boundary.

potetm17:08:56

What you can do is move static styling to css. That’ll create a little let line noise if you’re worried about that. That’s somewhat stylistic, but I tend to prefer it.

exitcode017:08:34

hm, yes i do enjoy keeping out of css though

exitcode017:08:42

thank you for sharing your thoughts

potetm17:08:27

I would also use let instead of letfn there. And I would inline the short callbacks to bring them closer to the invocation point. But that’s all stylistic. You do what you prefer. simple_smile

exitcode017:08:27

reallly 72 to 88 is a bit messy and the area i am not really happy about

potetm17:08:50

On the whole though, it seems to be centered around one thing. Which is the most important part.

exitcode017:08:52

oh yea i already moved them out of inlines do to pressure from others xD

exitcode017:08:10

glad to hear

exitcode017:08:39

wait, could you define what you mean by inline?

exitcode017:08:19

like use the let form instead of letfn or move them directly into button on-lick

potetm17:08:52

I mean I would move them down into the dom declarations so it’s clearer what each callback does.

potetm17:08:58

into the on-click

exitcode017:08:13

ah ok, thats what i thought

potetm17:08:25

But, if others on your team prefer something else, it isn’t worth quibbling over.

exitcode017:08:50

like you said it is style

exitcode018:08:28

is it possible to put a "defn" inside of a function or are you forced to use a let or letfn

dnolen18:08:33

@exitcode0: not possible, defn def declare all these things must be top-level

potetm18:08:43

Haha. You most certainly can. But it probably doesn’t do what you hoped.

potetm18:08:56

@dnolen: Oh cljs doesn’t support?

dnolen18:08:01

@potetm: you really cannot unless you like bugs that are impossible to deciper

dnolen18:08:31

the reasons it’s not rejected out right are largely academic in nature

dnolen18:08:34

don’t do it

potetm18:08:10

@dnolen: Is there some kind of fundamental difference there between clj and cljs, or are you just worried about confusing semantics in both cases?

dnolen18:08:32

@potetm: don’t have any more time to explain it more than I have

dnolen18:08:40

read the sources if you want to understand all the problems

dnolen18:08:45

I’ve given my advice simple_smile

exitcode018:08:39

thank you for the response dnolen : ) http://giphy.com/embed/MUeQeEQaDCjE4

chancerussell18:08:16

@wildermuthn: Any luck with your issue? Wondering if tap works in a side-effecty way, and if you should be using its return value, or the original channel you passed in to be tapped

wildermuthn18:08:48

turned out to be a problem with a logging macro!

wildermuthn18:08:04

macros can be evil, hah 😉

edbond19:08:47

Hey, cljscriptians! How do you store form fields and validation errors? Records, meta or something else?

roberto19:08:54

generally, I have a central app state that is a simple atom that tracks the application state.

roberto19:08:07

I consider validation errors part of the app state.

shaunlebron19:08:14

dnolen: are you transferring ownership of the mies template project?

dnolen19:08:34

@shaunlebron: I haven’t yet but if somebody wants to take it happy to give it up

dnolen19:08:43

I don’t have time to maintain it anymore really

shaunlebron19:08:54

I won’t volunteer for it yet, but just wondering since the cljs unraveled book is referencing it as the quick way to get started on leiningen

shaunlebron19:08:35

so anyone here who wants to maintain it, let us know!

edbond19:08:48

@roberto: thanks, I also think validation errors should be in state. Neither record nor meta, just plain map. I am trying https://github.com/leonardoborges/bouncer

edbond19:08:26

and initially build (defrecord FormField [value error]). It requires some ceremony to extract values for validation, I think I'll just drop validation results in state

roberto19:08:19

interesting, hadn’t seen that. I normally just have my own validation functions and the output is placed in the state. For example:

(def app-state (atom {my-model: {}
                                                errors: {}}))

roberto19:08:30

damn slack’s formatting

edbond19:08:39

and there may be global errors (base in rails) like two email fields are the same while should be unique.

edbond19:08:47

I was started with my own too, very similar to bouncer. Don't want to reinvent the wheel

dnolen20:08:38

@shaunlebron: well mies is leinengen-less now, only the Quick Start approach

dnolen20:08:02

@shaunlebron: far as I can with the Lein the fastest thing by far as is Figwheel

shaunlebron20:08:02

@dnolen: oh I didn’t notice that, does the current mies setup work with dependency retrieval?

shaunlebron20:08:33

that’s the main motivation behind moving to leiningen in this book, for transitive dependency installation that lein provides

dnolen20:08:26

@shaunlebron: ah yeah it only uses lein for deps

shaunlebron20:08:11

replacing mies in the book with figwheel might be an option. I think it would be really valuable to see those build scripts though

maria21:08:39

@shaunlebron @dnolen: I would be happy to maintain it, if that would be ok with you?

dnolen21:08:07

@maria absolutely, I feel bad for having let it languished for so long

shaunlebron21:08:57

only two versions behind though

shaunlebron21:08:12

and yeah dnolen, you just don’t do enough 😉

maria21:08:36

@dnolen: what’s the best way to go about it? will you just add me as a collaborator to the project?

bensu21:08:05

@shaunlebron: is putting the scripts also in the figwheel template also an option?

shaunlebron21:08:31

I don’t know enough about cljsbuild, but I think figwheel is a fork of it. If the build scripts were added to the figwheel template, I would hope that they produce the same files, for consistency between lein figwheel, lein cljsbuild and script/build

shaunlebron21:08:38

and are configured with the same data

shaunlebron21:08:51

syncing the compile settings between them might be troublesome

bensu21:08:58

hhmm good point.

bensu21:08:35

last time I checked figwheel was respectful of the compiler's defaults

bensu21:08:46

but better to check

bensu21:08:15

the template could use a little work to add Emacs integration and I thought I could add the mies scripts in the process.

dnolen22:08:47

@maria: I can also pass ownership to you, I think GitHub is good about redirects if you do this.

martinklepsch22:08:17

Maybe also a good match to move into some org like cljs-info? (just a thought)

dnolen22:08:30

@martinklepsch: @shaunlebron: that’s also a cool idea, but I leave the final decision to @maria simple_smile

shaunlebron22:08:09

I wouldn’t move it under cljsinfo, that’s mainly for website stuff, for now atleast

shaunlebron22:08:37

wouldn’t be bad to create a clojurescript org

shaunlebron22:08:27

actually, I’m not sure how much stuff would go under a clojurescript org, I’m fine with cljsinfo filling that role

maria22:08:11

@dnolen: I would be happy, if you would just add me as a collaborator for now. Should be the easiest for now and then we can still move it later if we want to 😉

dnolen22:08:27

@maria: works for me!

maria22:08:43

@dnolen: cool, thank you!

jonr22:08:59

Hey guys, totally off topic here, anyone know how I would go about accessing the eval-str method in cljs 1.7?

jonr22:08:22

David's recent post on GH has me excited to experiment with it

dnolen22:08:50

@jonr there’s really not much beyond the docstrings in cljs.js - but I’ve gone out of the way to make them clear

dnolen22:08:58

there’s a bunch of examples at the bottom of the file

jonr22:08:03

awesome docs in the ns

jonr22:08:21

I was just expecting to be able to use eval-str from the console via cljs.js or something

jonr22:08:52

I was having ideas about making a chrome extension for a cljs in-browser repl

dnolen22:08:07

@jonr it’s relatively advanced functionality

dnolen22:08:23

@jonr sure start a REPL and require cljs.js

dnolen22:08:30

if you want to play with it

jonr22:08:55

is cljs.js not exposed to js? I was thinking i would be able to access that in the browser console

dnolen22:08:22

@jonr I don’t know what you mean. It’s not any more exposed than any non-core ns, like clojure.set or clojure.zip

shaunlebron22:08:30

oh you wanna do cljs.js.eval_str(…) in the browser console

jonr22:08:42

yeah that's what I was hoping

jonr22:08:57

I might be missing something though

jonr22:08:03

Generally I am wondering if these most recent cljs updates would allow for an in browser cljs repl instead of connecting through figwheel

dnolen22:08:41

@jonr definitely possible

dnolen22:08:03

bootstrapped ClojureScript cannot reasonably be optimized beyond simple so top-level names don’t ever get munged

jonr22:08:04

seems like it should be doable without too much. Seems like you've done the hard parts 😉

dnolen22:08:32

@jonr well the really hard parts, there’s still lots of hard parts left simple_smile

jonr22:08:31

would an in browser cljs REPL be cool? I have been marinading on it today trying to think about if that would makes sense in tandem with figwheel file watching, compiling and updating source maps etc

dnolen22:08:47

@jonr Joel Martin actually has got one up and running here http://clojurescript.net

jonr22:08:37

hmm... that throws errors on anything I try but awesome to see other people trying this

jonr22:08:45

I'll investigate further

jonr22:08:55

glad to hear it should be possible though!

jonr22:08:09

might make for a cool chrome/firefox extension

dnolen22:08:35

@jonr oh huh, it’s in a bad state at the moment

dnolen22:08:57

@jonr one thing to consider is that Clojure(Script) programmers like to work from their source file

dnolen22:08:21

the only time I use the browser REPL is I have to debug something in a frame because I set a breakpoint

dnolen22:08:43

I haven’t seen a Chrome/FF/Safari extension that can eval in frame

jonr22:08:26

great feedback. I have been battling with figwheel and emacs as of late so that got me thinking about other options

dnolen22:08:35

(this is just thinking through dev integration ideas)

dnolen22:08:53

for other dev tools like snippet sharing or a http://jsfiddle.net clone, yes a browser based REPL would rock

jonr22:08:15

ah, good call

jonr22:08:35

really it just seemed like these updates should make it pretty easy and it sounded fun to make

jonr22:08:48

I wouldn't imagine it would be a power tool like an editor with integrated repl

jonr22:08:30

thanks for sharing the link. That might be enough to get me started towards a proof of concept

pre22:08:34

@dnolen @maria, would you be open to curating and maintaining all lein/boot cljs templates in a single org?

pre22:08:55

I maintain a few lein templates, and I know many boot based templates. Rather than expecting new cljs developers to figure out where these templates exist, we can maintain them in an org.

pre22:08:09

Here’s a start

pre22:08:52

Happy to volunteer and ask other owners of templates

dnolen22:08:23

@pri: I don’t have a problem with that, but I’ll let @maria sort out when / how that should happen simple_smile

pre22:08:53

Great. I think a lot can happen with your recommendation, hence I asked.

pre22:08:35

I’d hate to see boot vs lein templates scattered around. We can bring them together.

dnolen22:08:52

@pri: I’m not a big templates person so I don’t have strong opinions about these things

pre22:08:36

@dnolen: please know, many cljs developers (including myself long back) started their life with templates

maria22:08:58

@pri: yes, I agree, I think it’s a good idea to have them in one place

dnolen22:08:16

@pri: yes I understand that it's a huge help for people getting started out

martinklepsch22:08:01

@pri: I think where those templates are maintained is not really important and a documentation/index site for the various choices might be a better option?

pre22:08:50

@martinklepsch: an org can facilitate that in its site.

aengelberg22:08:08

Weird cljs.tools.reader behavior... is this by design?

cljs.user=> (cljs.tools.reader/read-string "017") ; octal number
15
cljs.user=> (cljs.tools.reader/read-string "018") ; number format exception?
18

shaunlebron22:08:56

@aengelberg: looks like a bug, evaling 018 in latest cljs causes reader exception

aengelberg23:08:51

ok. I should submit a jira ticket then

aengelberg23:08:13

Sorry, didn't mean to interrupt. wasn't sure if there was another more appropriate channel for this.

dnolen23:08:17

@aengelberg: that throws an exception in Clojure too

aengelberg23:08:15

in clojure.tools.reader it throws a NullPointerException. That might be a totally separate issue

dnolen23:08:44

@aengelberg: yeah that sounds like a bug, but not throwing on invalid octal, this seems intentional

dnolen23:08:04

@aengelberg: Bronsa on Clojure IRC is the one to talk to

maria23:08:57

I’ve added a new wiki page for ClojureScript project templates: https://github.com/clojure/clojurescript/wiki/ClojureScript-project-templates

maria23:08:23

Would be great if people would add templates they know of 😉

dnolen23:08:11

might make sense to move the templates higher and include in sidebar since new users benefit from them a lot?

dnolen23:08:22

(the link to the templates higher I mean)

dnolen23:08:51

like right after Tutorials

dnolen23:08:05

then the top of the page is very new user focused (I don’t think most of us need that part anymore simple_smile

maria23:08:22

Ah, I didn’t see those. One more reason to move them up a bit. Will do that now 😉