#clojure logs

2016-01-30

00:01Malnormalulogoing to have to go source diving some day to wrap my head round that
00:02justin_smithessentially whenever the reader finds # it takes the next form, and that form decides what to do with following data (and how much to consume)
00:02justin_smitheg #_ is a reader macro that says "take the next form and don't do anything beyond reading it"
01:04macroliciousin Emacs, when I C-x C-e (defn myfunction [foo] (str foo)), I get => #'testapp.core/myfunction in the minibuffer, but when I try to run (myfunction "bar") in the cider repl, I get an 'Unable to resolve symbol' error… what's going on?
01:05macroliciousTo clarify, myfunction was in another buffer than the cider repl.
01:06macroliciousI'm not sure where/how to test individual functions after 'running' them with C-x C-e.
01:28macroliciousI guess it's more of an #emacs question, now that I think about it.
04:47kenrestivonamespace it was defined in was testapp.core. namespace you're running your repl buffer in is probably user
04:48kenrestivoif you change the namespace of your repl, it'll work.
04:48kenrestivo(ns testapp.core) might do ya
07:53spuzhow do I load my clojure file into the repl such that I can call functions without giving the namespace?
08:04kungispuz: you can use (:require [your.ns :refer [function-1 function-2]]) in your ns form
08:05spuzkungi, is there a way to do it without knowing the function names in advance?
08:17loopholespuz (:require [your.ns :refer :all])
08:17spuzloophole, thanks!
08:20spuzloophole, that doesn't seem to work
08:20spuzdoes it need some specific version of clojure?
08:20loopholespuz: one moment i will try it myself
08:23loopholespuz: (use 'your.ns)
08:23loopholespuz: I have to check the exact rquire syntax myself nut use should work anyways
08:24loopholespuz: s/nut/but/
08:24spuzbut the style guide says: "Prefer :require over :use; the latter form should be considered deprecated for new code"
08:24spuzhttps://github.com/bbatsov/clojure-style-guide
08:24loopholespuz but you are talking about the repl?
08:24spuzyes
08:25lumain the repl, it's (require '[your.ns :refer :all])
08:25lumainside the ns form, it's (:require [your.ns :refer :all])
08:25spuzthanks luma
08:25loopholeluma: haha... the ':'
08:26spuzyes that was it
08:26loopholenever cut and paste
08:26loophole*note to self*
08:26spuzhow do I unrequire something?
08:27loopholespuz: i have no idea
08:27luma(remove-ns '
08:27luma(remove-ns 'your.ns)
08:28loopholespuz: why not (require '[your.ns :as y])
08:28spuz?
08:28loopholespuz then you don't have to ubnload at all
08:29loopholespuz (y/the-command)
08:29spuzseems strange
08:29loopholespuz: instead of (your.ns/the-command)
08:29spuzis there somewhere where I can find all namespace functions enumerated?
08:29lumabut why would you need to "unrequire" something?
08:30loopholespuz importing all function into your namespace is not a good thing outside the repl
08:31spuzluma, so that i can unpolute the current namespace
08:31loopholespuz that is what the the :as syntax is for
08:32loopholespuz: to keep aliases short so that it is convinient enough to use them instead of the full blown namespace
08:32spuzmaybe I don't understand what refer does but I don't see how :as helps
08:33loopholespuz say you want to use clojure.string/join
08:33loopholespuz without refer you have to write (clojure.string/join ...)
08:34loopholespuz: with refer :as you give the clojure.string part an alias say 's'
08:34loopholespuz: now you can write (s/join ....)
08:35loopholespuz: you can now have a function in your own code that is named join and it won't interfere with s/join
08:36loopholespuz: when you use :refer :all
08:36loopholeyour own join method will collide with the clojure.string/join method
08:40loophole,(require '[clojure.string :as s])
08:41clojurebotnil
08:41loophole(s/join "X" [1 2 3])
08:41loophole,(s/join "X" [1 2 3])
08:41clojurebot"1X2X3"
08:42loophole,(defn join [xs] [:haha_no_join [xs]])
08:42clojurebot#'sandbox/join
08:42loophole,(require '[clojure.string :refer :all])
08:42clojurebot#error {\n :cause "denied"\n :via\n [{:type java.lang.SecurityException\n :message "denied"\n :at [clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]}]\n :trace\n [[clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]\n [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkPropertyAccess nil -1]\n [java.lang.System getProperty ...
08:43spuztry just refering join
08:45spuz,(require '[clojure.string :refer [join]])
08:45clojurebotnil
08:45spuz,(join "foo")
08:45clojurebot"foo"
08:45spuz,(join "foo" "foo")
08:45clojurebot"ffooofooo"
08:45spuzso that's the clojure.string join ^
08:45spuznow how do i get my custom join back?
08:45loopholespuz that's ok too. I think it depends a bit on style. the prfix makes it clear that you use some external function when you read the code.
08:46spuz,(defn join [xs] [:haha_no_join [xs]])
08:46clojurebot#error {\n :cause "join already refers to: #'clojure.string/join in namespace: sandbox"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalStateException: join already refers to: #'clojure.string/join in namespace: sandbox, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6875]}\n {:type java.lang.IllegalStateException\...
08:46loopholespuz I always use the :as version
08:46loopholespuz in my code
08:47spuzso how do i get the previous definition of join back here?
08:47loopholespuz afaik the environemt repl will be restarted after a while
08:48spuzloophole, right... does that mean I have to restart everytime I want to change my own code?
08:48spuzit seems to defeat the point of the repl
08:49lumayou can reload your file
08:49ridcully_just eval your defn again
08:53spuzif I use (require) to reload the file into the repl, it doesn't seem to actually bring in the changes
08:57spuzuse of the repl in general just seems incredibly complex: https://github.com/clojure/tools.namespace#reloading-code-motivation
08:58spuzand as far as I understand the main motivation for using it slow compilation times?
09:01mgaareSlow repl startup
10:04bcoburnI'm trying to make a 'two-way' map where I can lookup key given val or val given key, is there a better way than doing (assoc {} key val val key) every time I want to add an entry?
10:15dadinnhi everyone
10:15dadinnanyone here is familiar with clojure zippers?
10:17dadinnI have found a behaviour which I cannot explain and it seems like a bug
10:18dadinnhere is an example testcase presenting the behavior: http://pastebin.com/wQzH826Q
10:20kwladykadadinn you don't have seqzip
10:20dadinnsorry I missed it from the example lol
10:20dadinn(def seqdat (list (list 1 2 3) (list 4 (list 5 6) 7) (list 8 9)))
10:20dadinn(def seqzip (zip/seq-zip seqdat))
10:21dadinnit's essentially the same structure as the veczip, but from seqs
10:23dadinnkwladyka: updated the link: http://pastebin.com/iWHUSnDC
10:23dadinnthis one should have seqzip too
10:25Malnormalulobcoburn: Per https://stackoverflow.com/questions/1183232/a-bi-directional-map-in-clojure, looks like it's either use a Java lib or roll your own bimap. Guava has one, reportedly
10:25dadinnoh noo, with sinax error too :P
10:25kwladykadadinn for first look of eye it is not the same. your vector is nested one time more
10:26kwladyka,(list (list 1 2 3) (list 4 (list 5 6) 7) (list 8 9))
10:26clojurebot((1 2 3) (4 (5 6) 7) (8 9))
10:26kwladykavs [[[1 2 3] [4 [5 6] 7] [8 9]]]
10:27kwladykadadinn use '(1 2 3) instead of (list 1 2 3) - will be easier to read
10:27dadinnkwladyka: I didn't notice that ... oops
10:28bcoburnI think just having more keys is easier than both of those. I really should have searched first :(
10:28dadinnthat vectorzipper was an example on clojuredocs so I just copied it to see if it really works like in the example
10:28bcoburnI guess all I'd need is a little function to call assoc
10:29dadinnand was a bit worried I don't get it why the down was behaving wierd..
10:29Malnormalulobcoburn, Yeah, should be easy enough to abstract away. And assuming the map doesn't get too ginormous, the performance penalty of a naive approach won't be too bad
10:30dadinnthanks for helping
10:59vise890hey all. emacs question. has anyone managed to get cljr-find-usages and cljr-rename-symbol when working with clojure 1.5
11:10dysfuni get this strange error compiling a cljc file as cljs: Exception in thread "main" java.lang.AbstractMethodError: Method cljsbuild/compiler/SourcePaths._find_sources(Ljava/lang/Object;)Ljava/lang/Object; is abstract
11:10dysfuncode is here https://github.com/jjl/automat/blob/cljc/src/automat/fsm.cljc#L25
11:11dysfunno line number or anything :)
11:47justin_smithdysfun: clojure 1.5 supports cljc?
11:48justin_smithdysfun: cljc is a 1.7 feature
11:48justin_smithoh, never mind, reading comprehension fail
12:33dysfunjustin_smith: don't suppose you found the bug? :)
12:34justin_smithhaha, no, that is the kind of error that is so weird that I would just run lein clean and try again
12:34dysfunyeah, but lein clean doesn't fix it :/
12:34dysfunit's probably a bug in potemkin.types/deftype+ :)
12:36justin_smithbut that shouldn't even be a possibility when you are compiling cljs...
12:37dysfunyou'd think, but notice it talks about java.lang.Object
12:37justin_smithit's a compilation error, cljs is compiled by clojure
12:38dysfunyeah, and i'm moderately ignorant of clojurescript's internals
14:04sdegutisWhat's a reasonably simple way to do different things to a value based on whether it's a string, keyword, sequence, or map, without needing extensibility for new types?
14:05dysfun(cond (string? p) ... (vector? p) ... :else ...)
14:05justin_smithor even condp class p
14:06justin_smithnever mind, not that
14:06dysfunplus you're asking for cljs portability issues doing that
14:07sdegutisjustin_smith: I was about to do condp type v but it seemed weird.
14:07sdegutisdysfun: I hate cljs so that's ok
14:07dysfunhate is a strong word
14:08sdegutisCorrect.
14:08dysfunwhy do you hate cljs?
14:08sdegutisPerhaps hate is wrong.
14:08sdegutisLoathe?
14:11sdegutisjk hate works
14:11sdegutisClojure is great and Datomic is genius.
14:12dysfuni think most of us don't use datomic actually
14:12dysfunwe aren't their target customers
14:42sdegutisdysfun: who is?
14:42sdegutisdysfun: datomic is basically just a reall nice compromise between nosql and sql, I can't imagine who it's not right for
14:44sdegutisAnyway this task is too hard for my cognition to process.
14:48justin_smithsdegutis: it's not right for people who have large datasets or large throughput
14:48justin_smithI wish I could use it - we had to scale back our product because mongo wasn't delivering documents fast enough, and that was the fastest thing we found
14:58sdegutisjustin_smith: mongo sucks when you have high-write and high-read, because every write slows down reads by locking /the entire db/
14:59sdegutisjustin_smith: datomic is cool in how all reads/queries are basically free, because they happen in-process, and require no locking at all
15:00sdegutisjustin_smith: with mongo and sql you have to have a super fast db server and your web server can be slow because it doesnt do much of the work on processing queries, but with datomic its reverse, the db server can be slow but the web server can be way faster
15:00sdegutisetc
15:00justin_smithsdegutis: multiple processes using the db, using it to send data, thus requiring frequent updates, datomic does not manage that nicely
15:00sdegutisjustin_smith: meh
15:01justin_smithsdegutis: where datomic shines is if you can hold onto the same client side cache of things for a while - I'm not saying it doesn't work, but it doesn't work for our specific case
15:01justin_smithsdegutis: also we are using wired tiger, which does not lock the entire db for writes
15:01sdegutisjustin_smith: you can put memcache between the web clients and the db server
15:03justin_smithsdegutis: will this work for thousands of writes a second?
15:08sdegutisnaturally yes
15:58creeseHas anyone created a back end for om.next that isn't datomic?
16:30thesaskwatchHi, anyone here using cljs with node? I'm not sure I understand the dev workflow. Do you use cljs compiler watching and rebuilding and nodemon to autorestart the server or just cljs node repl somehow?
16:35BRODUShow can I `load-file` in a from a parent directory? Using ".." is not working
16:41ridcully_load-file from a plain repl with "../file.clj" works for me
16:41ridcully_is the error any useful?
16:48BRODUSridcully_: no
16:48BRODUSridcully_: just "No Such File or Directory"
16:49BRODUSridcully_: I should mention that I'm not working in a project, its a just a .clj file in a directory that needs to read a clojure file in a directory above it
16:53BRODUScould it be because i started CIDER from another project?
16:55trastoHi , I am new in clojure and have one question , how I can put one value for default in this form (let [[ v k] list]) ,is possible?
16:55BRODUSyep, that was the problem
16:56trastoI do not know how to do it
17:00MokusoHi. Would you recommend to someone to start learning Clojure, if he doesn't have much experience with Java and the Java environment? I have some experience with python and C# though.
17:01Mokuso(I don't mind the lisp/like looks of Clojure, what annoys me so far is that I don't really get the error messages, since they're Java related)
17:02Mokusothx
17:11dysfunMokuso: you get used to java. clojure was my first serious jvm programming experience
17:18Mokusothanks dysfun. Just saw your answer, but I've got a dc as well
17:24dysfuner, dc?
17:28Mokusodisconnect
17:33dysfunwell in any case, i think clojure is an entirely reasonable first language
17:33dysfunand you get used to the parentheses
17:38MokusoYeah, I don't mind. It's cool that the repl has autocompletion for the parentheses as CL
17:39Mokusoanyways, we'll see how it goes
18:05justin_smithtrasto: what does "one value for default" mean?
18:30justin_smithMokuso: the state of the error messages is because clojure per se doesn't really have error messages or error handling for the most part. If you make a mistake that hits the vm then you get a trace showing the state of the vm and who the callers were and some implementation details revealed by the problem - which is distinct from a true error report of course.
18:31justin_smithMokuso: it's as if python didn't do error handling and you just got operating system level access errors
18:31Mokusoaha, interesting
18:31Mokusoyeah, it sounds cool
18:31Mokusobut you'll have to know how your VM works, to decipher the errors msgs
18:31justin_smithMokuso: cool, haha - the error handling (or lack of any explicit sort of error handling) is probably the worst thing about clojure
18:31justin_smithMokuso: exactly
18:32MokusoI don't mind, investing time in the JVM seems promising.
18:32MokusoEsp. since I don't have in mind writing code for low level applications
18:32justin_smithMokuso: on the plus side, it's not hard to find out what was happening at a low level, on the minus side, it's not hard to find out what was going on at a low level :)
18:33Mokusouhm, what's the difference between happening and going on ?
18:33justin_smithMokuso: editing error on my part, I meant them to both be the same
18:33MokusoAh ok :>
18:34justin_smithMokuso: but more seriously, the art of dealing with the traces is mostly digging through and looking for your own code, then use other things in the trace as needed as context clues to see where it went wrong
18:35justin_smiththe usual culprits are numeric operations, string methods, or calling methods on null - clojure code actually tends to be very resiliant it's just that these things blow up when they hit the vm implementation level
18:35justin_smithgenerally clojure itself is very optimistic and instead of checking that args are valid just pass them to the next layer of abstraction hoping for the best
18:36justin_smith,(get 1 :a "default") ; obvious nonsense, works for implementation reasons
18:36clojurebot"default"
18:38MokusoI'll probably start with a relevant book that explains how clojure is connected with JVM and all that stuff
18:38justin_smiththe clojure.org docs are pretty good too
18:39justin_smithMokuso: my "big picture" version is that clojure is a java library that generates jvm bytecode
18:39Mokusoheh
18:39Mokusoor a lisplike wrapper around Java classes perhaps
18:40justin_smithit's literally the truth though. It's a java lib (also runnable as a standalone program), you feed it text, it outputs bytecode, and it also contains the components needed to launch that bytecode as a program
18:40justin_smithMokuso: kind of, yeah, but the outer layer is java - clojure itself is java code at the core, bootstrapped to clojure code for all but the most central stuff
18:41Mokusoaha..
18:41justin_smithso you have a java program, that defines a small lisp, then a bunch of lisp code it knows how to load, and all together that forms a usable bytecode compiler plus the stub needed to load and run that bytecode it generates
18:41MalnormaluloWe call it a functional language, but really they're just IFn objects...
18:41justin_smithclojure programs are not standalone - they need the clojure runtime (since clojure is so meta / allows runtime definitions)
18:41justin_smithMokuso: exactly!
18:42justin_smithso that's the bare basics, the code of clojure, and a good book or three, and you'll know all of it as well as any of us here
18:46Mokusojustin_smith, thanks a lots !!
18:46justin_smithnp, glad I could help
18:46justin_smithMokuso: oh, another cool thing that I can mention here is that clojure only has one mode of operation
18:46justin_smithMokuso: what clojure does in the repl is exactly what it does when it reads your file and visa-versa
18:47Mokusohow else could it be ?
18:47justin_smithmost languages allow using symbols before they are defined if they are defined in the same file
18:47justin_smithclojure doesn't, because it loads a file exactly the same way it reads your input at the repl, and if something isn't defined that's an error
18:48justin_smithMokuso: if you look closely most languages have all sorts of special cases about how things run when the program is executing versus when things are being compiled and defined, but in clojure there is no split between those things
18:49MalnormaluloSo it sounds like its compilation isn't super complex. It's more like ahead-of-time interpretation.
18:49justin_smithwell, everything is always compiled
18:52LucidTortoiseI am sure I will get some positive answers to this question: has anyone seen this talk?: http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey
18:53LucidTortoiseI don't want to discuss the talk per se, but I do have one question?: What are the languages that embody his philosophy?
18:53LucidTortoiseI suppose we have Clojure, Haskell, and other functional oriented languages. But what else fits the mold?
18:54justin_smithperhaps erlang?
18:54LucidTortoiseWell, he does make a statement that "the world does not run by message passing", or something like that.
18:54justin_smithlokien: yeah, I grouped that with "other functional languages" - all mls would fit there ocaml included
18:55justin_smithLucidTortoise: oh yeah, fair enough, it's been a while since I saw that
18:55LucidTortoiseSo, is Erlang Smalltalk done right/functionally?
18:55justin_smithLucidTortoise: well you already mentioned the functional languages :)
18:55lokienjustin_smith: but I'm sad when it's put together with "others"
18:55justin_smithit's not functional, I was trying to think of non-functional languages that come close to doing it right
18:56LucidTortoiseI don't want to say I lost my enthusiasm for Smalltalk... but I think what I like most about Smalltalk is the contained, image based environment. Hm, maybe I should take a closer look at Self or Newspeak
18:57LucidTortoiselokien justin_smith That is my concern exactly, a paradigm does not sufficiently qualify a language.
18:57LucidTortoiseSo, any suggestions?
18:58lokienLucidTortoise: for how long have you been programming? I'm not trying to insult you or anything, I'm curious
18:59LucidTortoiseHaha. Not long enough to even remotely be insulted by the question,.
19:00lokienso, for how long? :D
19:01LucidTortoiseAbout 2 years, which honestly adds up to 2 months. I have been to inconsistent. I am one of those poser programmers who like talking and learning more about the language itself, then actually building something.
19:02LucidTortoiseI have in the past month changed my mindset to actually be productive. I didn't realize how much of a book 4Clojure would be until I started using it today.
19:02lokienhey, I was like you for my first 10 months or so
19:02lokienand still am, but less
19:02MalnormaluloYo same
19:02LucidTortoiseYeah, but got so boring being so... impotent.
19:02lokienLucidTortoise: we could do stuff together if you wanted
19:02MalnormaluloSpent my first year of programming doing pretty much nothing. I learned pretty much nothing.
19:03lokienI learned a lot, but did almost nothing :D
19:03MalnormaluloIt didn't help that I found myself doing web development, which is exactly what I didn't want to be doing
19:03LucidTortoiselokien that would be fun. If you got a project going on, I would love to be another brain or just eyes. Or, if I think of something clever, you will be one of the first people I ask for help.
19:04LucidTortoiseMalnormalulo Web Dev is such a trap. I think it is important, but unless you literally want to be making websites, there are so many other ways to use your programming skills.
19:06MalnormaluloWell see I applied for a job asking for SQL and Java knowledge. Offered, accepted, started work. They put me on an ASP.NET site.
19:06MalnormaluloIt literally was a trap.
19:06LucidTortoiseI say this because I actually tried Web Dev. A family friend wanted a website. I took this as an opportunity to learn a new technology, but didnt realize how much their is to learn.
19:06justin_smiththere's companies out there that look for haskell experience then make you do java :P
19:06LucidTortoiseThe guy ended up getting what he need by signing up to Weebly
19:06Malnormalulojustin_smith, oh god why
19:07justin_smithMalnormalulo: they want java written by the kind of people that know haskell
19:07justin_smithMalnormalulo: also, they must think frustrated / resentful programmers write good code or something?
19:07justin_smithlol
19:07MalnormaluloI mean I guess they'll know better than to use instance variables like local variables
19:07Malnormalulo(Some of my coworkers do this.)
19:17justin_smithMalnormalulo: I mean that's just fine because you never use an object in more than one thread ever, I mean everyone knows that
19:18justin_smithof course if you use an object in more than one thread that would be totally insane but who uses objects in threads anyway
19:18MalnormaluloHa well see, we don't. Want to know how we do multithreading? We start up a new JVM.
19:18justin_smithsee, everything's fine then
19:18justin_smithlol
19:18MalnormaluloBut we do reuse objects to avoid the overhead of instatiating new ones, so we have the same problem anyway
19:19justin_smithMalnormalulo: that's a great advantage with clojure actually, immutability makes thread stuff so much simpler
19:19MalnormaluloYawp. One of many reason I really want to introduce it to our codebase.
19:30trastojustin_smith: one value default , sorry my english is bad
19:32justin_smithtrasto: so something like (let [[v k] (or (not-empty list) [1])] ...) so that v would default to 1 but k would be nil if the input is less than 2 elements long?
19:36trastoyes but I need the second argument take the default value
19:36justin_smithoh, I misunderstood
19:40trastowith maps is possible with :or but is possible with vectors?
19:40justin_smithtrasto: I don't know of a way - there might be but I don't think so
19:43trastoso the best form is transform this vector in one map... I think
19:58justin_smith(defn vec-default [v defaults] (concat v (drop (count v) defaults)))
19:58justin_smith,(defn vec-default [v defaults] (concat v (drop (count v) defaults)))
19:58clojurebot#'sandbox/vec-default
19:58justin_smith,(let [[a b c d] (vec-default [1 2] [:a :b :c :d])] {:a a :b b :c c :d d}) ; trasto
19:58clojurebot{:a 1, :b 2, :c :c, :d :d}
20:03trastothanks justin_smith , to me it makes me complicated clojure
20:04Mokusobah, dictionaries are annoying in any language :/
20:07trastoin clojure more than others XD
20:45pulse207 /msg NickServ VERIFY REGISTER pulse207 nbrtbrukopxq
20:45tolstoyHeh. Oops!
20:47justin_smithhey that guy's password is a second teir superman villian
20:48pulse207dang guess I shouldn't use another superman villain, huh?
20:48tolstoyAh, like Mister Mxyzptlk?
20:48Mokusosounds like an alien friend of Rick's from Rick n Morty show to me
20:48justin_smithyeah, the one who fills in when Mxyzptlk is busy
20:49justin_smithhaha
20:49Mokusohehe, I think Mxyzptlk is a cool name
20:49MokusoI'd name my dog that :P
20:51tolstoyMy dog came pre-named. Jet. Not that he doesn't have a dozen names, depending on the time of day and my mood.
20:54tier2villianlets try this again
20:54Mokusoheh
20:58tier2villianso does anyone talk here?
20:58justin_smithyup, all things clojure are talked about here
20:58tier2villianwell that's good. I figured I'd lurk, but there wasn't anything going on
20:59justin_smith,((get get get get) (get get get get) (get get get get) 42)
20:59clojurebot42
20:59Malnormalulowat
20:59justin_smithMalnormalulo: it'll work in your own repl too
20:59tolstoyWell, it's Saturday night, and Clojurists are much in demand on the party circuit.
20:59tier2villianAh, I should have known
21:00justin_smithtolstoy: funny enough, the above snippet is my favorite clojure party trick
21:00MalnormaluloI'm still trying to figure out why it works
21:00justin_smithjust let me know if you need a hint
21:02MalnormaluloI'd expect it to try to cast `get` to a map and then fail
21:02justin_smithMalnormalulo: remember what I was saying about clojure and failures?
21:02justin_smithclojure is optimistic, it rarely validates inputs, if things are absurd it just keeps going unless it hits the bytecode (where things really do fail hard)
21:03MalnormaluloI guess I'd need to go dig into the implementation code to make sense of how it gets that far without a casting error
21:03justin_smithturns out get doesn't need a hash-map (there are other valid types to get from), and getting is not something that fails hard
21:04justin_smithMalnormalulo: if you took out the 42 it would return nil, if you turned the second (get get get get) into #{(get get get get)} it would return #'clojure.core/get
21:06tolstoy(get map key default-value) ... make sense. ((_ _ _ get) (_ _ _ get) (_ _ _ get) 42) -> (get get get 42) -> 42. Huh.
21:07justin_smithtolstoy: yup
21:07tier2villianI was wondering if it was just a trick to pass the default value back out
21:07justin_smith,(+(*)(*))
21:07clojurebot2
21:08tolstoy,(get map reduce 42)
21:08clojurebot42
21:08Mokuso(* 2 3 5 7 11 13 17 19)
21:08clojurebot*suffusion of yellow*
21:08Mokuso:(
21:08Mokuso(* 2 3 5 7)
21:08clojurebot*suffusion of yellow*
21:08justin_smithtier2villian: the base form is (get nil nil 42), then we add to this the fact that any instance of get can be replaced by (get get get get) and either of those nils can be replaced by just about anything...
21:09Mokuso(* 2 3)
21:09clojurebot*suffusion of yellow*
21:09tier2villianjustin_smith: got it. that's cool
21:10tolstoyLooks like an excellent code-review troll.
21:10justin_smith,(+(+(*)(*))(/(*)))
21:10clojurebot3
21:11justin_smith,(+(/(+(*)(*)))(/(*)))
21:11clojurebot3/2
21:11tier2villianwell I'm intrigued
21:12justin_smiththat's just some second rate swearjure - the real deal is amazing but I am no master of swearjure
21:12justin_smithhttp://hypirion.com/musings/swearjure
21:13tier2villianThat's one up on me. I don't actually know clojure, just looking for a new language to learn
21:13justin_smithoh shit this stuff makes clojure look terrible I'm so sorry
21:14justin_smithit's actually a very sane and readably language and these are bad code jokes we would never do in real code
21:14tier2villianOh, I know. I never judge a language too quickly
21:15Mokusodoes this bot get only the swearjure ?:P
21:15tier2villian(* 2 3 5 7 11 13 17 19)
21:15clojurebot*suffusion of yellow*
21:16tier2villian,(* 2 3 5 7 11 13 17 19)
21:16clojurebot9699690
21:16tier2villianweird
21:16Mokusoaha, maybe the comma
21:16Mokuso,(* 2 3)
21:16clojurebot6
21:16tier2villianI was watching you and wondering haha
21:16justin_smithMokuso: absolutely not, the point of swearjure is that it is normal clojure - or at least understood by the normal clojure compiler
21:16Mokusoyeh :>
21:17Mokuso,(defn ackermann [m n] (cond (zero? m) (inc n) (zero? n) (ackermann (dec m) 1) :else (ackermann (dec m) (ackermann m (dec n)))))
21:17clojurebot#'sandbox/ackermann
21:17Mokuso,(ackermann 2 3)
21:17clojurebot9
21:17Mokuso,(ackermann 3 3)
21:17clojurebot61
21:17Mokuso,(ackermann 4 1)
21:17tier2villianI was very worried you were gonna pass it one of the big ones
21:17clojureboteval service is offline
21:17hyPiRion4 1 is one of the big ones :p
21:17Mokusonot really
21:18Mokuso4 3 is one of the big ones
21:18tier2villianspeak of the devil
21:18Mokusoand 4 2
21:18Mokusobut it should be able to calc 4 1
21:18justin_smithit was big enough for clojurebot to ditch
21:18justin_smithMokuso: it can, but not in the tiny time slice you are allowed
21:18Mokusoyeh, it's ok
21:18Mokusoaha :)
21:18justin_smiththis is to protect the poor bot from trolls, of course
21:19Mokusoyou know guys, I found some lisp code at the rosetta stone project for this monster function, and even if it's optimized it crashes at (ack 4 3)
21:19MokusoI was wondering what kind of optimization one would need to use to calculate such a big integer
21:19hyPiRionOh and yeah, you don't have to know Swearjure-related things to learn Clojure. I don't think I've ever seen anything I've learned from Swearjure in production quality Clojure code
21:19justin_smithheh, I'd hope not!
21:19Mokusoheh :)
21:20justin_smithhyPiRion: maybe very basic things, like knowing you can do (apply * l) and if l is empty it returns 1
21:20MokusoI'm trying to translate the code from CL to clojure anyways, but it crashed for the time being. Would you like to have a look? I can provide the lisp code as well for comparison (that works fine).
21:21justin_smithMokuso: feel free to share a link
21:21hyPiRionjustin_smith: oh yeah, right. (*) and (+) is handy to learn just to know what happens when you do reduce on an empty list
21:21justin_smithright
21:21justin_smith,(/ 2) ; related but not sweary
21:21clojurebot1/2
21:22justin_smith,(iterate / 2)
21:22clojurebot(2 1/2 2N 1/2 2N ...)
21:25hyPiRionKnowing about %& inside #(...) is also worthy. Rarely useful, but that one time you need it it's good to know
21:25Mokusojustin_smith, http://pastebin.com/9B3teGEw
21:25hyPiRion,(#(reduce + %&) 1 2 3 4 5 6)
21:25clojurebot21
21:25justin_smithMokuso: so what's the error you get - stack overflow?
21:27Mokusohttp://pastebin.com/EtLUf0YV
21:27justin_smithMokuso: oh, you have the case syntax all scrambled
21:27Mokusooh ?
21:28justin_smithMokuso: every match clause in case needs the outer parens removed
21:28justin_smithcl -> (case x (m a) (m a)) clj -> (case x m a m a)
21:28justin_smithwe use one less level of parens
21:28Mokusoah !!
21:29Mokusoa bit confusing, but I'll give it a try
21:29Mokusothanks :)
21:30justin_smithMokuso: one more thing - remove the :else
21:30Mokusomaybe I'll use a cond instead
21:30hyPiRionMokuso: https://www.refheap.com/114278 I think
21:30justin_smithjust having an odd number of args suffices
21:30justin_smithwith cond you also need to remove the parens around the matches
21:31justin_smithand replace each one with an equality test
21:31justin_smith*with case
21:31Mokusothis looks how it should be hyPiRion :)
21:33Mokusoyeah, it worked in the repl, but not through the core.clj, so I'll dig a bit more on that
21:33justin_smithso I use Math/pow instead of numeric-tower and (ackermann 4 2) simply returns Infinity
21:33justin_smithhah
21:33justin_smithwait, what worked in the repl?
21:33Mokusothe link hyPiRion gave :>
21:33Mokusoit's the correct 'translation' with the changes you mentioned
21:34justin_smithindeed (plus removing the redundant () on each case, which was not needed but is idiomatic)
21:34Mokusoack 4 2 works fine, 4 3...I don't think I'll get a result :>
21:37justin_smithMokuso: it took me for ever to stop writing (let [[a 0] [b 1]] (+ a b)) and variants, as someone who has coded scheme and common lisp in the past
21:39MokusoIt makes sense justin_smith. If you don't mind asking, what made you switch to clojure from those two?
21:39Mokuso*some habits are hard to break
21:40justin_smithMokuso: I switched because I got hired to do clojure. I was hired because I had lispy experience, they were doing clojure and not one of the others because they needed to deploy to the jvm or at least have all the libs jvm would provide.
21:40KamuelaWhat’s a good explanation of the let form? I think it’s one that I’m not picking up so easily
21:41justin_smithKamuela: it allows setting values to symbols that don't effect other cide
21:41tier2villianI could be wrong, but it's just a way to scope variables, right?
21:41justin_smith*other code
21:41justin_smithright
21:41Mokusojustin_smith, nice. Would you say that your background help you to learn clojure faster or had you wished you didn't know lisp/scheme before so you wouldn't have to unlearn all the extra stuff those languages had?
21:41justin_smithwhen you use def, you are changing something at namespace level, which could effect any of your other code
21:42tier2villianOkay, it's been a little while since I messed with scheme and that's my only lisp experience
21:42justin_smithMokuso: definitely helped, most stuff was just simple translation - but I jumped ahead by far when I stopped treating clojure as "a weird lisp" and just dug into learning clojure as clojure
21:42MokusoI'm asking, 'cos I'm considering some clojure related jobs for the future, and I'm wondering if I should go straight there or pass through scheme first.
21:42justin_smithtier2villian: so, in scheme you can use def to create locals
21:43justin_smithin clojure that's not a thing
21:43MokusoAha..thanks :)
21:43tier2villianjustin_smith: oh so in clojure anything "def"'d is global?
21:43justin_smithMokuso: if clojure gets to weird and confusing, plt-scheme or whatever they call it now is great, and is meant to be a language used to teach programming, so it has great tooling and documentation.
21:44justin_smithtier2villian: well, namespace level, so practically global, yeah
21:44tier2villianMokuso: the racket community is also pretty welcoming, which is a plus
21:44Mokusothat's very interesting, Java is still calculating (ack 4 3). In scheme and CL it just crashed after a short time.
21:44tier2villianjustin_smith: got it, thanks
21:45justin_smithMokuso: numeric tower does promotion to unbounded bignums iirc
21:45justin_smithyour cl may or may not do that
21:46justin_smith,(inc' Long/MAX_VALUE)
21:46clojurebot9223372036854775808N
21:46justin_smith,(inc Long/MAX_VALUE)
21:46clojurebot#error {\n :cause "integer overflow"\n :via\n [{:type java.lang.ArithmeticException\n :message "integer overflow"\n :at [clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]}]\n :trace\n [[clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]\n [clojure.lang.Numbers inc "Numbers.java" 1839]\n [sandbox$eval49 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval49 invoke "NO_SOURCE_FIL...
21:50Mokusook, I've got an overflow after all, or close to that :>
21:50MokusoArithmeticException BigInteger would overflow supported range java.math.BigInteger.reportOverflow (BigInteger.java:1153)
21:50justin_smiththat's a kind of overflow I have never seen
21:51justin_smith,(iterate *' Long/MAX_VALUE)
21:51clojurebot(9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 ...)
21:51justin_smithoh wait, with one arg it's just identity
21:51justin_smith,(iterate #(*' % %) Long/MAX_VALUE)
21:51clojurebot(9223372036854775807 85070591730234615847396907784232501249N 7237005577332262210834635695349653859421902880380109739573089701262786560001N 52374249726338269874783614880766155793371912454611337886264179577532000370919343764787541041733925104025910035567032750922845842742640075519159173120001N 27430620343968443368695140184646988379527410343527824317354069354225552356596046115747958004859021025898780...
21:54tier2villianSo question. I'm going to a 24 hour hackathon next weekend. Would it be unreasonable to try and pick up clojure and hope to have something to show for it?
21:55justin_smiththat's one way to learn - you might want to make sure you have the basics for packaging and dependency management in check so you don't waste hackathon time on stupid stuff :)
21:56tier2villianalright. it really depends on my team I guess. If i end up flying solo, I'll probably give it a shot
21:56justin_smithnot that clojure is bad at those things (far from it), but our tooling is weird at first to most people
21:56tier2villianweird in what way?
21:57justin_smithtier2villian: no global installs, instead you configure each individual project for hte lib versions it expects
21:57justin_smithwhich solves a lot of problems, but requires a bit more tedium up front when first starting
21:57Mokusotier2villian, I've tried a hackathon like six months ago, but I went there without some concrete plan.
21:57MokusoI'd advise you to have some idea before you go there
21:57rhg135Too awesome, controlling dependencies is something I miss when doing js
21:57Mokusotime flies fast :)
21:57tier2villianoh okay gotcha
21:58tier2villianYeah, my first was last weekend actually
21:58Mokusogreat experience though, no matter how you do in the end
21:58tier2villiangot to try out mobile dev for the first time
21:58Mokusoyou'll meet some people as well, so it's nice
21:58tier2villianYeah, that was the best part
22:04Mokusoanyways, I'll better go get some sleep :)
22:05Mokusothanks for the ack hack xD
22:25princeso_,(clojure.walk/postwalk #(do (prn %) %) [1 {:2 3}])
22:25clojurebot#error {\n :cause "clojure.walk"\n :via\n [{:type java.lang.ClassNotFoundException\n :message "clojure.walk"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :trace\n [[java.net.URLClassLoader$1 run "URLClassLoader.java" 366]\n [java.net.URLClassLoader$1 run "URLClassLoader.java" 355]\n [java.security.AccessController doPrivileged "AccessController.java" -2]\n [java.net.U...
22:26justin_smith,(require 'clojure.walk)
22:26clojurebotnil
22:26princeso_,(clojure.walk/postwalk #(do (prn %) %) [1 {:2 3}])
22:26clojurebot1\n:2\n3\n[:2 3]\n{:2 3}\n[1 {:2 3}]\n[1 {:2 3}]
22:26justin_smithfyi :2 is an abomination
22:26princeso_what does that mean?
22:27justin_smithprinceso_: it's an exaggerated why of saying "Not only do I not see any point to using :2 as a keyword, seeing it used makes me twitch with annoyance". Kind of joking.
22:27justin_smithwhy not just use the number 2?
22:28princeso_well the point was, there is a vector in the result [:2 3].
22:29justin_smith,(clojure.walk/postwalk #(doto % prn) [1 {2 3}])
22:29clojurebot1\n2\n3\n[2 3]\n{2 3}\n[1 {2 3}]\n[1 {2 3}]
22:29justin_smithprinceso_: yes, hash-maps are made of entries, which are each two element vectors
22:29justin_smith,(seq {2 3})
22:29clojurebot([2 3])
22:29justin_smith,(seq {2 3 4 5})
22:29clojurebot([2 3] [4 5])
22:29justin_smith,(into {} [[2 3] [4 5]])
22:29clojurebot{2 3, 4 5}
22:31princeso_justin_smith: mmm ok. didnt know that. Im working on vectors, so there is going to be a hack
22:32justin_smith,(map-entry? [1 2])
22:32clojurebotfalse
22:32justin_smith,(map-entry (first {1 2}))
22:32clojurebot#error {\n :cause "Unable to resolve symbol: map-entry in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: map-entry in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: map-e...
22:32justin_smith,(map-entry? (first {1 2}))
22:32clojurebottrue
22:32justin_smith(= (first {1 2}) [1 2])
22:32justin_smith,(= (first {1 2}) [1 2])
22:32clojurebottrue
22:33justin_smithprinceso_: the map-entry? function might help you
22:33princeso_godd: thanks justin_smith. you always rock!
22:36princeso_justin_smith: haha that "makes me twitch with annoyance" was epic. any way i kind of like how it looks :D
22:38justin_smithprinceso_: I deal with learners a lot, so it makes me wonder if the person using it thinks : is a syntax that means "lookup key in a hash map"
22:38justin_smithkind of like in js
22:42Malnormaluloyeah, the keyword syntax isn't the most intuitive thing in the world
22:43justin_smith,(keyword " :: ::: ::: / / / ::: /")
22:43clojurebot: :: ::: ::: / / / ::: /
22:43justin_smithgotta love that clojure
22:43justin_smithto be clear, that returns a single keyword
22:43justin_smith,(namespace (keyword " :: ::: ::: / / / ::: /"))
22:43clojurebot" :: ::: ::: "
22:43justin_smith,(name (keyword " :: ::: ::: / / / ::: /"))
22:43clojurebot" / / ::: /"
23:12princeso_justin_smith: what could be possibly wrong whit postwalk, it says false to map-entry? [2 3]. And prewalk says yes.
23:13justin_smithprinceso_: aha! post-walk is reconstructing the input, before your code gets to it
23:13justin_smithin retrospect I should have predicted that would be an issue
23:15justin_smithbbl