Fork me on GitHub
#beginners
<
2017-11-14
>
adi04:11:01

@rinaldi Another idea, for kicks... IF each sub-vector of the data structure is regular in the following form:

["question" "x%" "y%" "z%"]
then
(defn flatten-questionnaire [qs]
  (->> qs flatten (partition 4)))
Will always work, for any level of nesting, because order is guaranteed in the qs vector. The result is also a sequence in which order is guaranteed.

reborg06:11:26

Also some spec based pattern matching @rinaldi (`coll` being your snippet):

(require '[clojure.spec.alpha :as s])
(s/def ::col (every-pred string? #(not (re-find #"(?i)(question|display)" %))))
(s/def ::row (s/coll-of ::col :kind vector?))
(filter #(s/valid? ::row %) (tree-seq vector? identity coll))
It has the advantage to work for any nested level and independently from display/question positioning.

derpocious13:11:05

Hi, has anyone used leiningen repl before to load a namespace?

derpocious13:11:55

I posted my issue in the leiningen room. Would appreciate some help. If only this all was as easy as npm 😁

vuuvi15:11:51

@derpocious did you load the namespace? did you use the in namespace keyword?

vuuvi15:11:16

checkout this article if you need some more context to how it works -

javazquez18:11:31

how does one call a clojurescript function from javascript that is not in namespace.core?

gdeer8118:11:13

@javazquez since clojurescript compiles to javascript you can use the ^:export metadata flag to make it available to your javascript code. like if you had cool_code.cljs that looked like this (ns cool-code) (defn ^:export chill [] "Im chillin") then you could call it from your javascript code like this cool_code.chill()

javazquez18:11:58

Hi @gdeer81 Thanks for the reply. That doesn't seem to work for me (ns scrappy-guitar.google-aws) (defn ^:export signin-callback [] (js/console.log "testing" )) chrome console >scrappy_guitar.google_aws.signin_callback() VM5442:1 Uncaught TypeError: Cannot read property 'signin_callback' of undefined at <anonymous>:1:27

gdeer8118:11:54

in the chrome console you can see your compiled clojurescript code in the "sources" tab?

javazquez18:11:08

yes. However I don't see the google-aws.cljs file represented

gdeer8118:11:02

that's odd

gdeer8118:11:15

does the compiled js file have your function in it?

javazquez18:11:37

very odd, there is not a google-aws.cljs file or google_aws.js file

javazquez18:11:26

I am used lein figwheel template and re-frame.. if that changes things

javazquez18:11:34

if I modify the file, I see the following in chrome console not required: ("resources/public/js/compiled/out/scrappy_guitar/google_aws.js")

javazquez18:11:39

@gdeer81 I successfully invoked that function from the repl and now it works in chrome console

javazquez18:11:26

I think its related to the not required message I was getting

javazquez18:11:32

not sure what is happening there

javazquez19:11:42

refreshed the browser and the files are now gone

gdeer8119:11:05

are you using figwheel or just cljsbuild?

javazquez19:11:07

Do I have to make reference to it within my core.cljs file? If I do that, I notice that the file then gets put into the sources directory

javazquez19:11:29

Thanks for helping me work through. I never knew about looking at the compiled sources 🙂

aconanlai20:11:26

is there something like take-while but works when beginning of set is false?

aconanlai20:11:38

e.g. given a sorted seq, and you want all the numbers in a range

aconanlai20:11:47

or is there a better way of doing it?

chris20:11:48

composition of drop-while and take-while?

aconanlai20:11:51

ohh yes good one!

gdeer8120:11:17

@javazquez yes there is even source mapping so you can trace a js error back to the cljs source. Everyone that works on clojurescript and all the tools around it are my heroes for taking something that used to make me cry myself to sleep at night and turning it into a tolerable development experience.