Fork me on GitHub
#hoplon
<
2016-07-04
>
jumblerg08:07:30

@micha: there’s some real craftsmanship in that commit. nice work.

jumblerg11:07:21

works like a charm

(ns+ human-dynamics.computeable-law
  (:page
    "index.html")
  (:refer-clojure
    :exclude [- name])
  (:require
    [javelin.core           :refer [defc defc= cell=]]
    [hoplon.core            :refer [defelem for-tpl when-tpl case-tpl]]
    [hoplon.ui              :refer [component elem button image toggle form window *scroll*]]
    [hoplon.ui.attrs        :refer [- c r s b d]]
    [hoplon.material.colors :refer [white grey grey-300 black]]))

jumblerg11:07:20

exposed a previously undetected error in my code too where, yet again, a symbol was getting rebound to one of the element constructors.

jumblerg11:07:52

it is also quite nice being able to refactor a function to a macro and back without having to update every ns declaration in my code.

jumblerg11:07:08

major improvement

jumblerg13:07:12

@micha: incidentally, how does ns+ resolve the ambiguity that arises when there’s a fn and a macro with the same name in the same ns?

micha13:07:58

good morning, happy fourth!

micha13:07:24

it doesn't, it leaves that to the cljs compiler

jumblerg13:07:32

ditto. sadly, they don’t allow sparklers at the office.

micha13:07:14

that should never happen with sane libraries

jumblerg13:07:42

yeah… but technically, cljs permits it.

micha13:07:57

it uses the cljs compiler to resolve the names in the first place

micha13:07:44

then transforms your ns into separate require and require-macros clauses

jumblerg13:07:33

so which one wins out, in ns+? do i get the fn or the macro?

micha13:07:04

yeah i didn't see any benefit to all the complexity to support that perverse case

micha13:07:21

test it and see lol

jumblerg13:07:19

i don’t plan on doing this anytime soon, so i’m not complaining. i already did that and got what i wanted. 🙂

micha13:07:20

you can still use the other clauses in this case btw

micha13:07:53

require-macros or use-macros

micha13:07:09

if you want to be specific

micha13:07:53

and :use with :exclude

jumblerg13:07:56

back to complaining… could probably do without use, maybe? i know clj supports it, but if its there ppl will use it.

micha14:07:18

use is important

jumblerg14:07:30

what is the case for it?

micha14:07:31

it supports :exclude

jumblerg14:07:55

ah, and refer doesn’t.

micha14:07:58

like refer all except these

jumblerg14:07:40

it is quite the jungle in there

micha14:07:45

with latest release you really only need :use and :require

micha14:07:46

i would say that :require is the one that's redundant

micha14:07:45

with :use you can achieve anything you can do with :require, plus the :exclude that :require does not support

micha14:07:59

i think you can do for example (:use [foo.bar :as bar :only []])

jumblerg14:07:07

i guess the thing i care about is that it is explicit where dependencies are coming from, i find it annoying when i open up some ns and there are multiple :use or :requires with :refer :all, and symbols are being referenced without any way to tell where they’re coming from within that file.

micha14:07:52

well that's a tradeoff, you will not find a file where everyone agrees on whether it's good style or not

jumblerg14:07:21

i also just reproduced that bug i mentioned to you in my “report” a couple days ago: create file that compiles to index.html, create another file that compiles to helloword.html, load index.html in the browser, save the helloworld file with boot-reload in the pipeline.

jumblerg14:07:41

you get helloworld at the index path

jumblerg14:07:30

it loads it whatever file was saved last

micha14:07:57

haha that's a feature!

micha14:07:10

i mean if you're editing helloworld then you want to see the results

jumblerg14:07:51

heh. yeah. feature.

jumblerg14:07:11

ideally this feature would load it at the correct path

micha14:07:39

yeah i dunno, reload is tricky

micha14:07:49

there is a simple solution

jumblerg14:07:56

use one file?

micha14:07:20

no, just do (with-page-load (.. js/window -location reload))

jumblerg14:07:10

excellent. can we put that in reload?

micha14:07:22

no, just put it in your page file

micha14:07:56

or in a namespace that is loaded by your page namespaces

micha14:07:16

you can preserve state across reloads with storage-atom

jumblerg14:07:17

i’ll try to be content with my ns+ macro for now.

micha14:07:12

i do the with-page-load thing myself because it ensures that there is no stale state hanging around

micha14:07:04

i'm thinking about adding the ns stuff as an option to boot-cljs task

jumblerg14:07:23

heh. do it.

jumblerg14:07:42

you can start extending the language from there.

micha14:07:22

i'm curious if there is a fatal flaw in the concept

micha14:07:28

that's a good way to flush it out

jumblerg14:07:03

it is working nicely for me so far, i’ve switch all my projects over to ns+

micha14:07:38

if the boot-cljs thing happens it would be regular ns with the page as metadata, and enable an option in the cljs task

jumblerg14:07:32

you could also throw an exception whenever the same definition is used for a macro and a fn.

micha14:07:03

which one does the compiler choose?

jumblerg14:07:47

i didn’t check, but this way you could explicitly disallow it since you’re compiling everything in there.

micha14:07:47

i'm not sure i have that information, since i use the compiler to analyze the requires anyway

micha14:07:56

i think it just chooses one

micha14:07:09

if you can try a test check out the transformed ns decl

micha14:07:21

and see which one it appears in, :require or :require-macros

micha14:07:32

i think it will appear in only one

micha14:07:10

my guess is that it will prefer the cljs instance

micha14:07:51

performing my test now

micha14:07:12

it chooses the clojure macro

micha14:07:16

interesting

micha14:07:56

no wait, there was a complicating factor

micha14:07:27

ok it doesn't see the macro in the simple case

micha14:07:45

i made foop2.lib namespaces in clj and cljs

micha14:07:51

with testing fn and macro

micha14:07:11

(:require [foop2.lib :as lib]) and (lib/testing 100) in the page

micha14:07:22

it chooses the cljs fn

micha14:07:51

if i do (:require-macros [foop2.lib :as lib]) in the lib.clj file, it then chooses the macro

micha15:07:09

so wtf don't do that

micha15:07:08

aaaand, if i do (ns+ foop2.lib (:require [foop2.lib :as lib])) in lib.cljs, i get a circular dependency error, which makes sense

micha15:07:38

but this is all far saner than the current situation, it seems to me

jumblerg15:07:52

my results are the same

micha15:07:11

this is not vietnam, walter, there are rules

micha15:07:43

don't make macros that have the same name as functions

micha15:07:48

is a good start

jumblerg15:07:30

i wonder how that became an option in the first place

micha15:07:59

initially people made different namespace names

micha15:07:08

like foo.lib and foo.lib-macros

micha15:07:33

but i imagine it gets tricky with the bootstrapping

micha15:07:38

to detect this situation

micha15:07:34

with opensource software it's cool to leave footguns like this in there, because someone will submit a PR to a useful library that does the bad thing to fix it

micha15:07:53

if it's really complicated to detect the condition and warn

micha15:07:18

like my code only sees one or the other

micha15:07:24

i can't throw an exception there

micha15:07:26

i could do some sneakiness maybe, but not sure if the added complexity is worth it

jumblerg15:07:36

try it out in cljs and see what happens. it would be a nice-to-have everywhere, i think.

micha15:07:57

yeah i don't know what the reasons are why this isn't the default

jumblerg15:07:27

if there are some, i suspect you’ll find out this way soon enough

micha15:07:36

maybe some concern for compiled js size with advanced optimizations, :refer :all would bring in unnecessary names potentially

micha15:07:54

but that seems like a non-issue, as we're all adults here and can decide for ourselves if that's what we want

micha15:07:18

oh btw, if you will be packaging those cljs files in a jar, make sure you run the hoplon task when you make the jar

micha15:07:25

so it can compile the namespaces

micha15:07:37

boot hoplon build-jar or whatever

micha15:07:05

that way the consumer of your library doesn't need to do anything to use it

micha15:07:35

i mean so it can rewrite the namespaces, you don't need to compile them

jumblerg15:07:51

i don’t think i have any libraries that use .hl files anymore

micha15:07:03

if you make a library using ns+ i mean

micha15:07:19

the hoplon task will rewrite that into a normal ns

micha15:07:25

then you can package that in the jar

jumblerg15:07:17

yeah, even before the introduction of ns+, all my libs were already using cljs files. they’re only in my applications.