Fork me on GitHub
#beginners
<
2018-02-17
>
opsb14:02:07

Just been learning about lazy sequences, https://clojuredocs.org/clojure.core/lazy-seq

opsb14:02:10

user=> (take 5 (positive-numbers))
(1 2 3 4 5)

opsb14:02:08

is there any way to take 5 and keep the rest of the sequence? i.e. have both the first 5 items and the remaining sequence

opsb14:02:37

(I realise I can use drop to just lose the first 5)

opsb14:02:05

@tbaldridge thanks, I gave it a go but it appears to eagerly evaluate the rest of the sequence 🙂 got an integer overflow

bronsa14:02:08

user=> (let [[f r] (split-at 6 (range))] f)
(0 1 2 3 4 5)

bronsa14:02:13

no eager evaluation

opsb14:02:32

ah, of course, I was doing

(split-at 5 (fib))
but that must cause the repl to try and print the whole of the remaining sequence

derpocious15:02:25

hey all, I'm having trouble adding the "matchbox" firebox library to my project. https://github.com/crisptrutski/matchbox

derpocious15:02:03

I added [matchbox "0.0.9"] to my project.clj dependencies and then copied the smple code into my project

derpocious15:02:27

But all the matchbox methods, eg m/connect, say "unable to resolve"

derpocious15:02:39

I ran lein deps already too

lilactown16:02:32

did you restart the REPL and/or cljs build?

lilactown16:02:08

a simple test allows me to see the functions in Clojure just fine

derpocious17:02:49

sorry, I don't know what you mean by tha

derpocious17:02:29

@lilactown I'm trying to use it for a aws lambda function which makes it tricky

derpocious17:02:36

here is the codebase for it

lilactown17:02:01

I'm on mobile ATM so I can't run your code, but it looks fine

lilactown17:02:25

When you build it, it says that it can't find matchbox?

derpocious17:02:19

I only have "serverless deploy" which builds it and deploys

derpocious17:02:52

but I was trying to call the functions locally

derpocious17:02:11

for example, with lumo and then (load-file core.cljs)

noisesmith17:02:29

why would that work with lumo?

derpocious17:02:56

that's hw I've always done it

noisesmith17:02:15

lumo doesn't use your leiningen dependencies unless you do something to ensure it sees them

noisesmith17:02:27

sorry, maybe I misunderstand - how are you letting lumo know where the dependencies are?

derpocious17:02:45

I'm not. I guess that is my problem

derpocious17:02:50

but what do they mean by "lein classpath"

noisesmith17:02:10

leiningen is primarily a dependency managing tool

noisesmith17:02:24

a classpath is a way of describing a bunch of a places where you can find dependencies

noisesmith17:02:40

if you run lein classpath that will output a classpath that java or lumo will know how to use

derpocious17:02:05

that filled my entire console window

noisesmith17:02:08

so if you use lumo -c $(lein classpath) that should start lumo in a way that it can use your dependencies

noisesmith17:02:25

right, people make projects that use a lot of dependencies

derpocious17:02:28

I'm getting an odd error though now when I try to load the file

derpocious17:02:35

(load-file "src/joke_generator_firebase/core.cljs")

derpocious17:02:46

Could not require cljsjs.firebase in file matchbox/registry.cljc
	 (new)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:1928:72)
	 Function.cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2539:92)
	 (NO_SOURCE_FILE <embedded>:5845:320)
	 Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)
	 Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5825:60)
	 (NO_SOURCE_FILE <embedded>:5843:474)
	 Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)

Cannot read property 'navigator' of undefined
	 (evalmachine.<anonymous>:12:345)
	 (evalmachine.<anonymous>:277:278)
	 ContextifyScript.Script.runInThisContext (vm.cljs:44:33)
	 Object.runInThisContext (vm.cljs:116:38)
	 ()
	 lumo.repl.caching_node_eval (NO_SOURCE_FILE <embedded>:6373:68)
	 (NO_SOURCE_FILE <embedded>:5844:410)
	 Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)
	 Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5825:60)

noisesmith17:02:23

looks like an error inside cljsjs.firebase?

derpocious17:02:04

what do you suggest? use a different library? lol

derpocious17:02:13

I opened an issue on matchbox github

noisesmith17:02:06

you could try explicitly asking for the version on the cljsjs github https://github.com/cljsjs/packages/tree/master/firebase

noisesmith17:02:48

@derpocious also you can look at lein deps :tree to see if there are any version conflicts that might be causing incompatible versions of libraries to be pulled in

derpocious18:02:22

ah ok. thanks!

derpocious18:02:33

when I run lein deps :tree I get this

derpocious18:02:36

[org.clojure/clojurescript "1.8.51"] -> [org.clojure/tools.reader "1.0.0-beta1"]
 overrides
[io.nervous/cljs-lambda "0.3.5"] -> [org.clojure/core.async "0.2.395"] -> [org.clojure/tools.analyzer.jvm "0.6.10"] -> [org.clojure/tools.reader "1.0.0-beta2"]

Consider using these exclusions:
[io.nervous/cljs-lambda "0.3.5" :exclusions [org.clojure/tools.reader]]

 [clojure-complete "0.2.4" :exclusions [[org.clojure/clojure]]]
 [io.nervous/cljs-lambda "0.3.5"]
   [camel-snake-kebab "0.4.0"]
   [funcool/promesa "1.6.0"]
   [io.nervous/cljs-nodejs-externs "0.2.0"]
   [org.clojure/core.async "0.2.395"]
     [org.clojure/tools.analyzer.jvm "0.6.10"]
       [org.clojure/core.memoize "0.5.9"]
         [org.clojure/core.cache "0.6.5"]
           [org.clojure/data.priority-map "0.0.7"]
       [org.clojure/tools.analyzer "0.6.9"]
       [org.ow2.asm/asm-all "4.2"]
   [org.clojure/tools.macro "0.1.2"]
 [matchbox "0.0.9"]
   [cljsjs/firebase "2.4.1-0"]
   [com.firebase/firebase-client-jvm "2.5.2" :exclusions [[org.apache.httpcomponents/httpclient]]]
     [com.fasterxml.jackson.core/jackson-databind "2.2.2"]
       [com.fasterxml.jackson.core/jackson-annotations "2.2.2"]
       [com.fasterxml.jackson.core/jackson-core "2.2.2"]
     [com.firebase/tubesock "0.0.12"]
   [org.apache.httpcomponents/httpclient "4.5.2"]
     [commons-codec "1.9"]
     [commons-logging "1.2"]
     [org.apache.httpcomponents/httpcore "4.4.4"]
 [org.clojure/clojure "1.8.0"]
 [org.clojure/clojurescript "1.8.51"]
   [com.google.javascript/closure-compiler "v20160315"]
     [args4j "2.0.26"]
     [com.google.code.findbugs/jsr305 "1.3.9"]
     [com.google.code.gson/gson "2.2.4"]
     [com.google.guava/guava "19.0"]
     [com.google.javascript/closure-compiler-externs "v20160315"]
     [com.google.protobuf/protobuf-java "2.5.0"]
   [org.clojure/data.json "0.2.6"]
   [org.clojure/google-closure-library "0.0-20151016-61277aea"]
     [org.clojure/google-closure-library-third-party "0.0-20151016-61277aea"]
   [org.clojure/tools.reader "1.0.0-beta1"]
   [org.mozilla/rhino "1.7R5"]
 [org.clojure/tools.nrepl "0.2.12" :exclusions [[org.clojure/clojure]]]

derpocious18:02:57

but it doesn't let me change the deps

noisesmith18:02:24

you can add deps in project.clj - if they come before the one that pulls in the transitive dep, it will override

noisesmith18:02:23

that dep conflict doesn't look suspicious, but you could try overriding the cljsjs/firebase dep

Ian Fernandez18:02:05

I just have began with clojure

Ian Fernandez18:02:12

and I can't use clojure.set

Ian Fernandez18:02:25

user=> (:require clojure.set) CompilerException java.lang.ClassNotFoundException: clojure.set, compiling:(NO_SOURCE_PATH:1:1)

Ian Fernandez18:02:39

I don't understand why

noisesmith18:02:43

@d.ian.b that's not the valid syntax for require outside ns

noisesmith18:02:50

(require 'clojure.set)

Ian Fernandez18:02:58

I'm using repl in terminal

Ian Fernandez18:02:31

sorry that is too noob

noisesmith18:02:32

:require is a keyword, it's treated specially inside the ns macro

noisesmith18:02:42

it's OK, this is the right channel for noob questions

Ian Fernandez18:02:02

I'm urging to learn clojure hehe

Ian Fernandez18:02:10

I'm using the living clojure book

Ian Fernandez18:02:40

Could you recommend me some others on clojure for data stuff?

Ian Fernandez18:02:54

I don't have java background

derpocious18:02:08

clojure for brave and true is good beginner book

Ian Fernandez18:02:12

I'm pandas python/ bash guy

derpocious18:02:24

but @noisesmith what dep should I change? and how do I know what version?

noisesmith18:02:46

@derpocious I was suggesting trying a newer version of cljsjs/firebase - I linked to it above

Ian Fernandez18:02:05

I'm going back to study here

derpocious18:02:38

I tried to add te latest, but that didn't work either

derpocious18:02:48

:dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.8.51"] [io.nervous/cljs-lambda "0.3.5"] [cljsjs/firebase "4.9.0-0"] [matchbox "0.0.9"]]

derpocious18:02:51

like this right?

noisesmith18:02:23

oh, OK - if that doesn't help I'm not sure what to suggest next, other than to say the error looks like it's coming from matchbox

Henry22:02:27

Alohha. I have a question … :

["^ ","~:action","login","~:value",["^ ","~:user_id","asdf"]]
I’m getting this as a Websocket message and I don’t quite get what kind of Datatype this is. I thought it should be json, it doesn’t look like json to me though and therefore a json/reader doesn’t work … what I’d love to get out of is a Map, so I can access the values of different keys. Help would be much appreciated ❤️

noisesmith22:02:05

@Henry that's transit in the :json encoding

noisesmith22:02:45

it's actually valid json, but it turns into normal clojure data via transit

noisesmith22:02:34

this is the library that handles transit https://github.com/cognitect/transit-clj

Henry22:02:36

that sounds good 😄 can you help me out how i access my values from this?

Henry22:02:25

okay, I’ll check that out and if I don’t get it to work I’ll ask again:) thanks

noisesmith22:02:48

the Readme for that lib should have everything you need - also is this clj side or cljs side?

Henry22:02:18

(def reader (transit/reader in :json))
(log/info "Message backend:" (transit/read reader msg))
shouldn’t this be working?

noisesmith22:02:48

depends how you defined in, but yes

noisesmith22:02:33

also you can skip creating in if you already have an InputStream - if what you have is a String you can create in like in the Readme though

Henry22:02:38

So if i just get the message passed as a String I first neet to create an in?

noisesmith22:02:00

user=> (def in (java.io.ByteArrayInputStream. (.getBytes "[\"^ \",\"~:action\",\"login\",\"~:value\",[\"^ \",\"~:user_id\",\"asdf\"]]")))
#'user/in
user=> (require '[cognitect.transit :as t])
nil
user=> (def r (t/reader in :json))
#'user/r
user=> (t/read r)
{:action "login", :value {:user_id "asdf"}}

noisesmith22:02:20

yes - in isn't magic, it's just what the example called the input source