This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-26
Channels
- # admin-announcements (4)
- # beginners (3)
- # boot (78)
- # cider (13)
- # cljs-dev (29)
- # cljs-edn (8)
- # cljsjs (11)
- # cljsrn (15)
- # clojure (81)
- # clojure-beijing (2)
- # clojure-belgium (3)
- # clojure-canada (1)
- # clojure-dusseldorf (8)
- # clojure-greece (6)
- # clojure-russia (40)
- # clojure-sg (1)
- # clojure-uk (59)
- # clojurebridge (1)
- # clojurescript (101)
- # core-logic (1)
- # cursive (3)
- # data-science (1)
- # datomic (60)
- # emacs (4)
- # error-message-catalog (12)
- # funcool (1)
- # hoplon (60)
- # jobs (1)
- # jobs-discuss (40)
- # leiningen (5)
- # liberator (1)
- # mount (22)
- # off-topic (8)
- # om (16)
- # onyx (53)
- # re-frame (11)
- # reagent (2)
- # specter (4)
- # testing (18)
- # untangled (51)
What is the string type in clojurescript? e.g. If I have a multimethod defined like below, how would I dispatch on the string type?
(defmulti my-method type))
(defmethod my-method ;;string type goes here
)
@tel what do you want to achieve? depending on that you might want to go bootstrap
I’m trying to get unique strings which reference symbols defined statically in a namespace
So you might want to use a clojurescript in clojurescript approach and inspect the compiler state available at runtime, ClojureScript does not reify namespaces as in Clojure
@maria: Do you know how inheritance works in cljs? I am not sure how to dispatch a multimethod on an ISeq. This works fine in Clojure but in Clojurescript you need to call satisfies?
instead of instance?
to get the proper "inheritance" check.
@tel I suggest you to have a look at the cljs.js
namespace of clojurescript itself, and ask back here whenever you need help, basically you will need to do something among these lines:
1) create an atom to contain the compiler state
2) find out which part of your state is useful for you
3) query the ast
I described part of all this here: http://lambdax.io/blog/posts/2016-03-22-replumb-ast.htmlnp feel free to ask here afterwards, we are pretty responsive on bootstrap topics 😄
Is there a way to create the inheritance relationship in such a way that isa?
will recognize that relationship?
@maria: Do you know if there is a way to get multimethods to dispatch on protocol inheritance then?
@kenny: Not really sure how this would look like, since an object can implement multiple protocols.
@maria: I think I am asking the wrong question.. The multimethod dispatching would work on interfaces if the object had a hierarchy. For example:
;; in clojure
(parents (type '()))
=>
#{clojure.lang.IPersistentList
clojure.lang.Obj
java.util.List
clojure.lang.IHashEq
clojure.lang.ISeq
clojure.lang.Counted}
;; in clojurescript
(parents (type '()))
=> nil
I think this is the problem. The parents
function is returning nil.Also in Clojure:
(parents (class '()))
=>
#{clojure.lang.IPersistentList
clojure.lang.Obj
java.util.List
clojure.lang.IHashEq
clojure.lang.ISeq
clojure.lang.Counted}
I believe if (parents (type '()))
returned the protocols and types inherited by '()
(in this case cljs.core/EmptyList
) the multimethod would properly dispatch.
I'm designing an audio pipeline that shall eventually record audio, filter it with a lookahead gate, then chunk it up into short audio blobs and encode those separately.
For this, I've set up an AudioSourceBufferNode that is fed with input data (44100 samples linearly distributed from -1.0 to 1.0). The chunker uses a ScriptProcessorNode that at the moment simply copies all audio from in- to output and, in parallel, adds samples to chunks that are then delivered using a callback once they are complete.
So far so good. What troubles me is that in my test code, the ScriptProcessorNode doesn't receive exactly the same samples that I feed the AudioSourceBufferNode with.
Here's the test code: https://github.com/Jannis/cljs-audio-utils/blob/jannis/audio-chunker/src/devcards/audio_utils/devcards/audio_chunker.cljs#L11
Here's a graph visualizing the original input data and the data passed through the script processor: https://i.imgur.com/fxw3RVM.png
The values don't start at -1.0, there are sudden jumps and the overall number of samples is way less than 44100.
Ok. You can try the whole thing by running boot dev
and opening http://localhost:3000/public/index.html#!/audio_utils.devcards.audio_chunker in your browser.
I've experimented with different buffer sizes for the script processor - the image was generated with 4096. It gets better with 8192 and 16384 but still there are samples missing.
Note: As of the August 29 2014 Web Audio API spec publication, this feature has been marked as deprecated, and is soon to be replaced by Audio Workers.
Yeah, sadly I don't believe AudioWorkers are a thing yet: "These are not implemented in any browsers yet"
It doesn't make a difference whether or not you connect a MediaStreamAudioDestinationNode to the script processor or the default destination of the AudioContext. That eliminates one potential source of the problem.
A question about self-host: what’s the difference between :context :expr
and :context :statement
in cljs.js/eval-str
??
@bronsa: I don’t understand (cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21) (+ 1 2)" "bla" {:eval cljs/js-eval :context :statement} identity)
returns {:ns cljs.user, :value 3}
the return value is 3. right?
and it’s not discarded
what do u mean by “not needed”?
in the clojure compiler statement means it will get discarded, I guess that's not necessarily true for cljs
(cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" "bla" {:eval cljs/js-eval :context :statement} identity)
returns {:ns cljs.user, :value 12}
here the return value is discarded
Are you saying that with :statement
the return value is sometimes discarded and sometimes not?
@viebel: I'm saying that if you need the return value, it's not a :statement
. I have no idea what cljs compiles to and what's actually returned in :statement
expressions, but taking the return value of a :statement
is meaningless
what’s the scenario where :statement
is relevant?
1 and 2 are analyzed as :statement
, that whole expression will compile down to just 3
and discard 1&2 alltogether
i thought everything was an expression in clojure?
is this just for special forms like if?
what :context
should I use when I want to evaluate all the expressions?
:expression
if you're interested in the value of the last expression, :statement
if you're just compiling them
@bojan.matic: in clojure, yes. In javascript/jvm no
(cljs/compile-str (cljs/empty-state) " (if (> 45 10) 23 21)" "bla" {:eval cljs/js-eval :context :statement} identity)
returns {:value "if(((45) > (10))){\n} else {\n}\n”}
please don't highlight me to get answers, I reply when I can, I'm working ATM.
again, if you want the results, use :expr
, if you are ok with ignoring them use :statement
. In what you just pasted you're trying to access the result and using :statement
, which I told you doesn't make sense
:expressions
seems to work fine
But I can’t find any clue to it in cljs
source code
Is it documented somewhere?
how could :expressions
work in self-host if it’s not on the source code?
@mmeix: I've investigated the audio issue more closely now. The skipped samples and jumps in the data received by the script processor are caused by it processing data too slowly, resulting in the audio system trying to "keep up the pace". If I let the script processor do nothing apart from copying from in to out and if I trigger the playback/recording only after the web page has finished loading, it's ok. No skipped samples, no jumps.
But as soon as the script processor takes a bit too long or if the machine/browser is under heavier load (like during the initial page load/render), it'll show these problems.
I guess that's why audio workers are the future - too much interference with the script processor and the rest of the JS running in the same thread.
Yeah. Data processing needs to be really fast to not cause glitches. And trying to achieve that in the same thread as the UI is using for rendering... not a good idea. 😉
is each library generally required to be explicitly ported to cljs before its accessible, most work out of the can, its spotty, or something else?
i ask because, while I am not a clojure expert by any stretch, i have a little experience in clojure and am now trying to utilize cljs…i am running into some problems that I am not yet experienced enough to know whether I am just not doing something right or whether its something not available within the cljs environment