Fork me on GitHub
#clojurescript
<
2017-03-31
>
john00:03:29

extending the type of an instance

john00:03:37

question: using that with something like delay: https://cljs.github.io/api/cljs.core/delay

john00:03:06

would it be possible to, upon realization of the value, extend the instance of the container type to that of the new value? Such that, if one were to then apply the object to values, it would act like the realized value?

john00:03:36

Basically, a delay that tries to turn into a real value, when it realizes

john00:03:04

or at least acts like the new realized value, when used by other functions

mikerod01:03:58

@john that sounds confusing, but I think you Mean:

(def d (delay <MyProtoImpl>))

;; “magically" `specify!` is applied to the `delay` object
<@U1DHX2E5V>

;; later on call the protocol fn directly on the delay instead of the `@d`

(my-proto-fn-call d)

mikerod01:03:25

that seems weird to me, but just trying to wrap my head around what you were asking 😛

mikerod01:03:20

I’d think you would need to know at compile time what you want to implement.

(def d (specify! (delay 1) INumberThing (num-val [this] @this))

<@U1DHX2E5V>

(+ 1 d) ; assuming `+` worked against a protocol

mikerod01:03:20

specify{!} are macros

mikerod01:03:39

being macros, I think you need to know at compile-time what you are specifying

mikerod01:03:55

so you can’t wait to determine it at runtime whenever the delayed is derefed

mikerod01:03:16

except you probably could do some hacker’y to accomplish what you are saying

mikerod01:03:32

since it comes down to digging in and mutating the JS object to support the protocol

mikerod01:03:36

probably not a great pattern though 😛

john01:03:09

sort of like doing a redef of the delay to the value, after it is realized.

mikerod01:03:32

well you could mutate it in place even

mikerod01:03:38

I just realized that cljs doens’t have extend the fn

mikerod01:03:43

I wonder why

john01:03:55

I think you can extend IFn

mikerod01:03:12

in clj you can call extend at runtime to impl new protocols

mikerod01:03:22

but it is at a class level, so affects all object instances

mikerod01:03:40

it would seem natural that since cljs has specify that it could be called at runtime and just alter a single instance

mikerod01:03:51

I’m guessing there is some underlying reason for this, just don’t know

mikerod01:03:07

specify! looks to be written in terms of extend-type

mikerod01:03:19

(another macro

john01:03:29

well what were you thinking, re: mutating?

mikerod01:03:52

I don’t have an answer. just thought that this was a curious topic now that I looked at it closer

john01:03:55

I know it can be done with promises

john01:03:29

This library's readme shows how to populate a data structure using asynchronous calls with promises: https://github.com/jamesmacaulay/cljs-promises

john01:03:54

Though maybe those values are channels?

john01:03:20

They seem to be promises

mikerod01:03:52

not sure on that one

mikerod01:03:55

first I’ve seen that

jamesmacaulay02:03:45

@john they are promises, but the library lets you work with them like channels by implementing the right protocols

ballpointpenguin04:03:18

be careful what you wish for 😉

ballpointpenguin04:03:36

We now have a repo for putting together a ClojureScript tack on http://exercism.io

baptiste-from-paris12:03:12

hello guys, anyone can explain to me what Volatile type is ?

dnolen13:03:38

@baptiste-from-paris it exists for portability with Clojure

dnolen14:03:50

@baptiste-from-paris the volatile ref type was introduced to Clojure for transducers, and all of that got ported to ClojureScript

baptiste-from-paris14:03:10

Ok, I was checking the cljs code - I’ve got to check the clj one then

baptiste-from-paris14:03:31

looks like it’s only a value holder

baptiste-from-paris14:03:41

more flexible than atom

dnolen14:03:06

different concurrency semantics in Clojure than Atom

Jon15:03:08

Where did the original idea of Cursor come from? I saw react-cursor today, not sure it's the same as the one in ClojureScript. https://github.com/dustingetz/react-cursor

dnolen15:03:18

@jiyinyiyong from the first version of Om

Jon15:03:52

a created concept?

Jon16:03:51

I read the Wiki for many times, since it's coupled with Om, I'm not sure if I really get it. By the way I never really used Om..

dnolen16:03:15

somewhat inspired by zippers / lenses, but works by wrapping the data structure itself

Jon16:03:23

not understand lens yet, saw the concept many times..

Jon16:03:06

I remembered you said Om Next has switched away from Cursor, not very sure..

Jon16:03:44

I thought for quite long time today, Cursor(at least react-cursor) did a very good job, compared to this.setState in React.

dnolen16:03:25

yes no cursors in Om Next, queries take care of the problem

Jon16:03:28

guessing it would just take me very long time to catch up..

sjol20:03:45

Has anyone successfully used martian https://github.com/oliyh/martian with other swagger api servers like django-rest?

caryfitzhugh20:03:21

hello - I have a javacsript iterator. Was looking around for some "standard" way to convert to something Seq-able. I shall continue to google - but if anyone has an idea...

caryfitzhugh20:03:18

(es6-iterator-seq ...)