Fork me on GitHub
#hoplon
<
2016-01-01
>
laforge4901:01:48

@micha I've got a loop-tpl question. simple_smile When I use an anonymous cell= inside a loop-tpl, the value of the cell never seems to change. Would having the cell='s in a map fix that? Here's the code: (loop-tpl :bindings [buddy rpc/buddies] (li :toggle (cell= (not (or (str/blank? buddy) (= rpc/user buddy)))) (span :class "buddy" (text "~{buddy}")) (input :type "checkbox" :value (cell= (contains? rpc/active-chat buddy)) :click #(rpc/toggle-chat! buddy)))))) The thing is, when a buddy logs off I want to clear the checkbox. The code runs fine the first time, but after checking the box a second time and doing a second logoff, the display remains checked even while the active-chat set has been updated.

micha01:01:37

which version of hoplon are you using?

laforge4901:01:39

Oh, yes. this is the cell I'm talking about: :value (cell= (contains? rpc/active-chat buddy))

micha01:01:22

ah there is a bug with that one, alpha10 should work

micha01:01:31

it's a known issue

micha01:01:40

i need to revert that change

laforge4901:01:17

Sounds good.

levitanong05:01:23

@micha: What caused the bug? 😮

laforge4908:01:02

@micha I've been reading up on lenses and it strikes me that it is all really very simple, only the explanations are scary. So I've written up my own: https://github.com/laforge49/dewdrop#readme

laforge4908:01:11

Now why mention this here? I wanted to give you a sample of my writing. I think hoplon should be as simple as I've made lenses. 😄

raywillig16:01:14

is clojars closed for New Year?

laforge4917:01:39

Except for the ones who don't know enough to come in from the cold. 😄

micha18:01:29

@laforge49: did you see the javelin lens implementation? https://github.com/hoplon/javelin#lenses

micha18:01:29

maybe "lens" isn't precisely the correct terminology, the javelin one is more general than the lenses i've seen elsewhere

raymcdermott20:01:09

Quick question … are there some editor / tabs / code layout conventions for the demos? I use Cursive and would like to set up a code style template that matches your preferences

laforge4922:01:11

@micha the reference to lenses in the javlin docs got me to studying lenses. But having gone so far as implementing my own lenses, I still can not figure out javlin's. Sigh. Something for another day.

micha22:01:31

it's simple though

laforge4922:01:44

from the right perspective, I'm sure.

micha22:01:52

like in your example you have a lens that focuses on a path in nested maps right?

micha22:01:18

so you can query it to get a value (i.e. clojure's deref or @ reader macro)

laforge4922:01:22

nested anything, given the right lenses.

micha22:01:43

and you can set the value (i.e. clojure's swap!, reset!)

micha22:01:09

so in your example you've baked in the semantics of query and set

micha22:01:26

each lens instance has that baked into the implementation

micha22:01:35

the javelin one is a generalization of that idea

micha22:01:00

so for example, a lens that is equivalent to your lens is the one in the first javelin lens example

micha22:01:32

(defn path-cell [c path]
  (cell= (get-in c path) (partial swap! c assoc-in path)))

micha22:01:47

the cell= macro usually is just a formula expression

micha22:01:58

i meanit usually takes a single argument, the query expression

micha22:01:19

that defines the behavior of the query part, so it's like half a lens

micha22:01:35

but cell= can take a second argument that makes it into a full lens

micha22:01:45

this second argument is just a callback

micha22:01:08

a function that given the desired new value for the lens, does something to make that heppn

laforge4922:01:12

just a callback? which means?

micha22:01:21

so look at the example

micha22:01:34

(partial swap! c assoc-in path)

micha22:01:57

that's the same as (fn [new-val] (swap! c assoc-in path new-val))

micha22:01:31

so you can see, we can use this same abstraction to make lenses of any complexity

micha22:01:05

so in the example:

laforge4922:01:30

so the cell updates the cell it references?

micha22:01:43

the callback does

micha22:01:58

when you call swap! or reset! on the cell

micha22:01:01

the lens cell

laforge4922:01:03

so the cell with the callback updates the referenced cell.

micha22:01:21

well when you make the javelin lens you have a query and a callback

laforge4922:01:25

the swap is in the callback

laforge4922:01:31

when does the callback get called?

micha22:01:37

when you call swap or reset

micha22:01:41

on the lens cell

micha22:01:07

the callback provides the update implementation for that lens

laforge4922:01:12

so updates to the formula cell cause the referenced cell to be updated. cool!

micha22:01:30

yeah it's a very generalized version of functional lenses

micha22:01:52

and what's great about it is that it doesn't invent new protocols or new functions to do it

laforge4922:01:55

but what does that do to your non-cyclic dependency graph???

micha22:01:07

it's still not cyclic

micha22:01:15

because you're not actually setting the lens value

laforge4922:01:17

just bi-directional

micha22:01:37

the value in the lens cell isn't necessarily what you tried to set it to with reset or swap

micha22:01:43

that's the key thing actually

micha22:01:52

i think a big improvement on the usual functional lenses

micha22:01:04

you're sending a request to update

laforge4922:01:07

you can't actually set a formula cell

micha22:01:15

but the query and the update are effectively decoupled

micha22:01:25

crucial, i think

laforge4922:01:51

otherwise too many underlying assumptions break

micha22:01:19

yeah, you don't want to complect the representation of a thing with the semantics of changing it

laforge4922:01:57

now I've got a new assignment--update javelin docs

laforge4922:01:08

(I suspect very very small changes)

micha22:01:47

a crucial thing with the javelin lenses is that the code that calls swap! or reset! doesn't need to know anything about the underlying structure of the data that backs up the lens

micha22:01:57

because the callback knows how to do the right thing

micha22:01:05

it's encapsulated there

laforge4922:01:19

transparently. simple_smile

micha22:01:43

this is exactly in line with the design of clojure's reference types

laforge4922:01:53

yes, feels the same

micha22:01:01

like when you call swap! or reset! on an atom you're only expressing a desire to change something

micha22:01:15

clojure then handled the mechanics of doing so in an atomic way

laforge4922:01:26

and beware side-effects in the swap function!

micha22:01:34

exactly, same with lenses

laforge4922:01:49

very very cool man

laforge4922:01:13

we need to work on accessibility

micha22:01:25

the relationship between lenses and transactions in javelin is also interesting

laforge4922:01:51

yes, but you manage to complexify everything

micha22:01:05

my goal was the opposite

laforge4922:01:29

you want to use the referents in your head in explaining things.

laforge4922:01:43

but your audience has different referents.

laforge4922:01:28

so I read the javelin doc and spent 3 days working on lenses, but gave up on javelin

laforge4922:01:37

being a newbie puts me in a better position as a tech writer. Though I'd rather be working on my own stuff

laforge4922:01:00

and not on docs, let alone some one else's docs! 😄

laforge4922:01:11

But the cause is a noble one

laforge4922:01:40

happy holidays to you!

micha22:01:54

oh right, i forgot!

micha22:01:57

likewise!

laforge4922:01:26

My wife and I have a mild case of the flu, having gotten flu shots 2 weeks ago. go figure

laforge4922:01:04

all the best!

micha22:01:18

have some chicken soup

laforge4922:01:32

I can, but she's Hindu

laforge4922:01:47

--strict lacto vegitarian

micha22:01:28

i guess she's in god's hands then, chicken soup is the only thing my people know for when you're sick

laforge4922:01:32

Personally, I prefer motza ball or wonton soup. simple_smile

micha22:01:54

man wonton soup sounds good

laforge4922:01:40

15 years in India and they know how to ruin everything. No pork fat in chinese food nor in tai food either!

micha23:01:27

vindaloo though

laforge4923:01:17

Not that I wanted to eat pork in india though. Discussions of what indian pigs eat is not a fit topic.

micha23:01:49

also people get lynched, or so they say on the news

laforge4923:01:06

But as the chinese ambassador said when taken to a chinese resturant in Delhi, best indian food I've ever eaten!

laforge4923:01:25

no one care if you eat pork

micha23:01:34

oh interesting

laforge4923:01:42

cows are sacred

micha23:01:01

luckily there are a lot of indians in my area

laforge4923:01:02

in every cow resides 100,000 gods

micha23:01:07

excellent restaurants

laforge4923:01:17

Sounds great!

micha23:01:42

extra spicy vindaloo, that's the thing

micha23:01:51

cure your flu i bet

laforge4923:01:30

we are unfamiliar with this. South indian perhaps.

micha23:01:37

the chinese ambassador is a funny guy

laforge4923:01:03

ALL food in india is adjusted to indian expectations.

micha23:01:18

my brother was in korea for his job

micha23:01:33

he said the same kind of thing, kimchee and squid in everything

laforge4923:01:11

In india you often get served kimchee as a free side dish in Chinese restaurants. But it is not fermented. It is just cabage with a sweet barbeque souse. Retch!

laforge4923:01:02

I've been to too many restaurants in India where the cook obviously had never tasted the food described on the menu.

laforge4923:01:40

Or at least, what I thought was described on the menu!

laforge4923:01:18

Many dishes, like the kimchee, tasted strangely similar from place to place. simple_smile

laforge4923:01:35

When taco bell first opened in bangalore, it was nice. But over time they replaced all the non-native ingredients and seasonings with native ones. I lost interest, though I am sure business picked up.

micha23:01:05

that's interesting

micha23:01:14

most places the process works the other way

micha23:01:38

i'm very curious what indian taco bell tastes like

laforge4923:01:42

Indians want food adventures, but in name only

laforge4923:01:16

It tastes indian of course. Complete with paneer burritos.

laforge4923:01:39

And nacho chips made with untreated corn flower.