2015-07-12
| 00:00 | justin_smith | imagine taking english lessons from someone who doesn't understand basic grammar... |
| 00:00 | vas_ | Hey guys, I'm using postal to send stuff, it works great, but how do I include line breaks or html formatting in my :body clause for emails? |
| 00:00 | freeman42 | have to bend the mind to use fewer language features... which are quite utterly important :/ |
| 00:02 | freeman42 | and this gives the same error: http://i.imgur.com/U5ewrcc.png |
| 00:03 | vas_ | " probably the worst possible way to learn clojure, a compiler that doesn't even work" LOL |
| 00:03 | turbofail | freeman42: well you don't want to call `leattack' when you pass it in |
| 00:03 | turbofail | freeman42: should be (times 2 leattack) |
| 00:03 | freeman42 | turbofail, removed, but now it does not attack :) http://i.imgur.com/oi17QI5.png |
| 00:04 | turbofail | hm. well, it should |
| 00:04 | turbofail | depending on what the hell `this' is |
| 00:04 | justin_smith | freeman42: yeah, that's just a broken compiler / env |
| 00:05 | justin_smith | freeman42: keep using it if it's fun I guess, but it will teach you nothing interesting about clojure |
| 00:05 | justin_smith | worse it will "teach" you things about clojure that are totally false |
| 00:05 | freeman42 | right now it would force me to implement some times function which uses recursion |
| 00:06 | freeman42 | hmmm, false? |
| 00:07 | justin_smith | freeman42: because it doesn't interpret your code properly, I'm all but certain code will succeed in that environment that would be invalid in a real clojure environment. And beyond that, the style you need to use in order to solve those puzzles is the wrong way to be coding clojure. |
| 00:08 | turbofail | yeah, that side-effecting API there is pretty un-clojurific |
| 00:08 | tomjack | I wonder what the codecombat-in-cljs-bootstrap apis will look like |
| 00:08 | tomjack | in-game apis I mean |
| 00:08 | turbofail | that said i've done plenty of side-effecting in clojure myself |
| 00:15 | justin_smith | turbofail: it goes beyond that though |
| 00:16 | justin_smith | turbofail: for example (.goLeft this) (.goRight this) (.hokeyPokey this) is better expressed as (doto this .goLeft .goRight .hokeyPokey) which is totally invalid in that environment |
| 00:42 | vas_ | what's a simple way to check if an email address in properly formed? regex? |
| 00:43 | justin_smith | vas_: oh man emails are crazy, and most email programs don't even get them right |
| 00:43 | vas_ | こんにちは |
| 00:44 | justin_smith | the only simple, and fully reliable way to check an email is to send a message to it |
| 00:44 | justin_smith | vas_: did you know emails allow inline comments? |
| 00:44 | vas_ | Hahah |
| 00:44 | vas_ | justin_smith: what. |
| 00:44 | vas_ | justin_smith: like /* this is not my real email? */ |
| 00:45 | justin_smith | like me(this part is a comment)smith@some(this is also a comment)host.com |
| 00:45 | vas_ | justin_smith: I use a + sign in my gmail all the time... |
| 00:45 | vas_ | Wow. I had no idea that was valid according to the 80s |
| 00:45 | justin_smith | that's a gmail convention - emails is a crazy spec, and I doubt many people even implement it properly |
| 00:46 | justin_smith | including email providers |
| 00:46 | vas_ | Okay. I will just leave it up to the user to not have any typos before they click 'take a bunch of my points to invite a friend' |
| 00:47 | justin_smith | "john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com." |
| 00:47 | justin_smith | https://en.wikipedia.org/wiki/Email_address |
| 00:47 | justin_smith | vas_: haha, or you could use one of the many many half assed and incorrect validators (all regex based) that work on 99.99% of addresses people use |
| 00:47 | justin_smith | vas_: but it's just a sad state of affairs |
| 00:49 | justin_smith | vas_: read this list and weep for any validator https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses |
| 00:51 | justin_smith | http://i.imgur.com/nZS5OB7.jpg |
| 00:53 | vas_ | #!$%&'*+-/=?^_`{}|~@example.org |
| 00:53 | vas_ | Even has that hysterical winky face |
| 00:54 | vas_ | Hahahaha mathematical sobbing |
| 00:54 | vas_ | crying deltas |
| 00:57 | vas_ | Man I'm excited. I've been working on the first phase of this website/app for a few months on and off now, and I am almost ready to go live. |
| 00:57 | vas_ | Thank you Clojure |
| 00:58 | vas_ | Anyone played around with titanium (graph [as in directed] library) ? |
| 00:58 | justin_smith | vas_: I looked at it but didn't actually end up using it |
| 00:59 | vas_ | justin_smith: do you know of any alternatives to doing graphy things? |
| 00:59 | vas_ | for* |
| 00:59 | justin_smith | my tech lead just ended up impelmenting a bunch of stuff from scratch (but I'm still not convinced that is the best way to do it) |
| 01:00 | vas_ | Yeah that would be a great learning exercise.. _but_ |
| 01:01 | vas_ | not really where I wanted to spend the next few weesk ^_^ |
| 01:01 | vas_ | weeks (read as months years eons) |
| 01:03 | freeman42 | both of the last 2 lines work in Clojure REPL but not in CodeCombat :( http://i.imgur.com/a7QM0xU.png |
| 01:04 | justin_smith | freeman42: I am amazed you haven't given up on that thing yet |
| 01:04 | freeman42 | no macros? ok..., but no lambdas?!?! nooooo :'( no point in continuing to play using Clojure |
| 01:04 | freeman42 | well, the whole point was to learn something |
| 01:04 | justin_smith | heh, I spoke just a little too soon I guess :) |
| 01:05 | freeman42 | is there a 3rd way to do lambdas? :p |
| 01:05 | justin_smith | it would be cool to make something like that game, but using cljs (no need for sandboxing, since everything is evaluated browser side) |
| 01:06 | justin_smith | #() is just a reader macro for (fn []) but there is also eg. comp, and partial |
| 01:06 | justin_smith | but I seriously doubt those would be supported if fn isn't :P |
| 01:06 | vas_ | I was reading earlier that (fn []) has an implied (do) |
| 01:07 | justin_smith | indeed! |
| 01:07 | vas_ | not sure what difference that makes in practicality |
| 01:07 | justin_smith | (fn [] (println "what") 42) for example |
| 01:07 | justin_smith | let also has an implied do |
| 01:07 | justin_smith | for does not |
| 01:07 | justin_smith | doseq does |
| 01:08 | justin_smith | when does |
| 01:08 | freeman42 | argh :( that last console message http://i.imgur.com/lBipW2d.png |
| 01:11 | vas_ | so would something like "for" eventually terminate on a "nil" ? |
| 01:11 | justin_smith | vas_: ? |
| 01:11 | justin_smith | I don't even understand that question |
| 01:12 | vas_ | that's okay, I did not understand it when asking |
| 01:12 | vas_ | don't worry about it |
| 01:12 | vas_ | You answered it earlier with justin_smith> (fn [] (println "what") 42) for example |
| 01:13 | justin_smith | vas_: since for is explicitly only for lazy operations, they intentionally did not add an implicit do, because those are for side effects |
| 01:14 | justin_smith | whereas just about every other macro that has a "body" has a do |
| 01:14 | vas_ | Ahh that makes perfect sense |
| 01:14 | vas_ | because a lazy body, like the universe, only exists when you're measuring. |
| 01:14 | vas_ | ;D |
| 01:14 | justin_smith | something like that |
| 01:15 | vas_ | Haha i will have to work on my quantum standup.. |
| 01:15 | justin_smith | side effects inside lazy things make code go wrong in so many weird ways |
| 01:22 | freeman42 | I give up, this will have to do for now http://i.imgur.com/UzSICco.png |
| 01:24 | freeman42 | vas_, is it idiomatic enough? |
| 01:25 | vas_ | freeman42: Beeeauuuuutiful |
| 01:25 | vas_ | =) |
| 01:25 | freeman42 | vas_, lol, not sure if serious or joking :p |
| 01:25 | vas_ | well i think it is beautiful |
| 01:25 | vas_ | others have their opinions no doubt |
| 01:26 | freeman42 | ok, cool then :) got some abstractions learned for now |
| 01:26 | clojurebot | Pardon? |
| 01:26 | vas_ | the way you implemented that looks a lot like ->> |
| 01:27 | vas_ | try (->> ["Rig" "Gurt" "Ack"] (attack 2)) |
| 01:27 | freeman42 | ah yeah, we never spoke about -> and ->> |
| 01:27 | freeman42 | reads up |
| 01:27 | vas_ | they're very cool! |
| 01:27 | justin_smith | vas_: that wouldn't work in regular clojure |
| 01:28 | vas_ | it's like operator pizza |
| 01:28 | vas_ | justin_smith: yeah i had my suspicions.. what would be the proper way? or is it not really the appropriate circumstance |
| 01:28 | justin_smith | vas_: it would require a map and dorun or something |
| 01:28 | justin_smith | and a partial maybe |
| 01:28 | turbofail | there's run! |
| 01:29 | turbofail | in 1.7 |
| 01:29 | justin_smith | (doc run!) |
| 01:29 | clojurebot | "([proc coll]); Runs the supplied procedure (via reduce), for purposes of side effects, on successive items in the collection. Returns nil" |
| 01:29 | justin_smith | turbofail: I doubt his weird env supports that |
| 01:29 | turbofail | oh i thought we were talking about regular clojure |
| 01:29 | justin_smith | turbofail: but yes, run! would be perfect |
| 01:29 | vas_ | what would it look like using run? |
| 01:30 | justin_smith | (->> ["Rig "Gurt" "Ack"] (run! (partial attack 2)) |
| 01:30 | freeman42 | tried to read about -> but I understood that this it not even his final form (I don't know what a form is) |
| 01:30 | justin_smith | freeman42: a form is a unit of a clojure program |
| 01:31 | vas_ | like a brick for building a house out of? |
| 01:31 | justin_smith | "(+ 1" is not a form, "(+ 1 2)" is, as is "+" |
| 01:31 | freeman42 | for me that is like explaining that a bloopeedy doop is a unit of goopidy foo |
| 01:31 | vas_ | mmm goopidy foo |
| 01:31 | justin_smith | freeman42: a form is a valid input to a clojure compiler |
| 01:31 | freeman42 | uhm,... ok :) |
| 01:31 | vas_ | Whoa |
| 01:31 | vas_ | I just put + |
| 01:31 | vas_ | into my repl |
| 01:31 | justin_smith | freeman42: in clojure, most places where you can use a value, you can also use a form |
| 01:31 | vas_ | and got |
| 01:32 | vas_ | #<core$_PLUS_ clojure.core$_PLUS_@6c3c0ef2 |
| 01:32 | justin_smith | right, that is the value of + |
| 01:32 | freeman42 | justin_smith, I think this for another day for me :) |
| 01:45 | freeman42 | still hoping for a times function, too many _-es http://i.imgur.com/cyxqDOi.png |
| 01:46 | freeman42 | there is a way to create a range easily I assume |
| 01:47 | justin_smith | ,(range) |
| 01:47 | clojurebot | (0 1 2 3 4 ...) |
| 01:47 | freeman42 | was thinking to implement repeat using a range as recursion is not supported |
| 01:55 | freeman42 | justin_smith, any other way? ^^ (defn times [n f] (doseq [_ (take n (range))] (f))) does not seem to work in closer.js either |
| 01:55 | freeman42 | or rather, in codecombat at least, works in clojure repl just fine |
| 01:55 | justin_smith | freeman42: (take n (range)) is just (range n) |
| 01:55 | freeman42 | oh |
| 01:55 | justin_smith | maybe that version works? |
| 01:56 | freeman42 | I'll try |
| 01:57 | freeman42 | justin_smith, nope, it seems it does not know the range function |
| 01:57 | freeman42 | guess it could be implemented... with some other thing? :) |
| 01:58 | justin_smith | loop? |
| 01:58 | clojurebot | loop is a macro of last resort |
| 01:58 | freeman42 | I'll give it a try |
| 01:58 | justin_smith | clojurebot: yes, but he appears to be out of other options |
| 01:58 | clojurebot | Pardon? |
| 01:58 | justin_smith | haha |
| 01:58 | amalloy | it sounds like you are not writing clojure, so much as just trying to guess at an arbitrary set of undisclosed rules |
| 01:58 | justin_smith | indeed |
| 01:59 | freeman42 | amackera, you are pretty much correct, but it is still fun |
| 01:59 | justin_smith | broken compiler as game |
| 01:59 | freeman42 | hahaha, funny way of putting it |
| 02:06 | freeman42 | so loop/recur is the equivalent of for/while loops in some other languages? |
| 02:06 | justin_smith | exactly |
| 02:08 | justin_smith | freeman42: well, we also have while |
| 02:08 | justin_smith | but loop is usually more convenient because it provides updated bindings, and while requires some mutable object to test |
| 02:08 | freeman42 | justin_smith, is it easier to comprehend? |
| 02:10 | freeman42 | clojure docs seem to think it is pretty idiomatic "While for is somewhat like a loop, recur is a real loop in Clojure. recur represents such a remarkable idea that we might even say, “this is Clojure.” " |
| 02:10 | justin_smith | freeman42: while is loop without the bindings (and a test instead). easier to comprehend depends - is a mutable object easier to comprehend than a recursive call with new bindings? |
| 02:10 | freeman42 | ah wait, that is not clojure docs... |
| 02:11 | freeman42 | hmm, dunno, looking over them now |
| 02:12 | justin_smith | freeman42: loop is like a recursive function, except only allowing self-calls from the tail position |
| 02:13 | freeman42 | that sounds quite nice |
| 02:21 | justin_smith | freeman42: as the clojurebot factoid indicates, we consider it the low level way to do things usually, but it sounds like you don't have the other options |
| 02:26 | rritoch | Loops aren't easy to use or read, at least for people new to lisp, so there are now a number of higher level abstractions which provide easier to use and read flow-control. Unfortunatly your not guaranteed any portability because there's no LISP standard (such as ANSI). Technically loops are more portable but they're low-level and part of CLISP. |
| 02:27 | rritoch | If you care about portability, loops are really the way to go. If you care about your sanity, use anything but. |
| 02:36 | rritoch | Well, I guess Common Lisp (Clisp) is technically an ANSI standard, but it's extremly outdated and doesn't fit well into modern applications. |
| 02:38 | rritoch | justin_smith: Is clojure CLISP compliant? I've never actually tried to run CLISP apps on clojure, I just assumed they wouldn't work. |
| 02:38 | Chousuke | Clojure is very different from Common Lisp |
| 02:39 | Chousuke | about the only thing they have in common is that both have lots of parentheses :P |
| 02:46 | justin_smith | rritoch: CLISP is a specific implementation of the common lisp standard, it is not a shortcut for common lisp. Clojure does not intend or attempt to implement common lisp. |
| 02:47 | justin_smith | clisp: http://www.clisp.org/ - just an implementation |
| 02:51 | justin_smith | Chousuke: to be fair, clojure macros owe more to common lisp than any other language |
| 02:55 | rritoch | justin_smith:I wouldn't say clojure has no intent of implementing common lisp. The political environment of clojure is clearly ruled by $$, the first time a big company goes to cognitect asking for compatiblity with their legacy apps, I'm sure clojure will fall in line with common lisp. |
| 02:56 | H4ns | rritoch: sorry, but that is utter nonsense. you need to know more before making such claims. |
| 03:00 | rritoch | H4ns: Clojure doesn't qualify as not-for-profit, and certainly isn't backed by the Free Software FOundation. |
| 03:01 | rritoch | H4ns: These are facts which should be readily available to anyone taking up clojure. Clojure is open source and still proprietary. |
| 03:05 | rritoch | H4ns: I guess I was wrong about the free software foundation status |
| 03:06 | rritoch | H4ns: I really don't know the relationship between clojure and FS |
| 03:06 | rritoch | err, FSF |
| 03:10 | rritoch | H4ns: It is something I'd be interested in learning though because when I was working for a venture capital firm developing apps in clojure I submitted feature requests based on features that they needed for their systems, the requests were not flat out denied, but they made it very clear that the requests would probably never be integrated with clojure. |
| 03:12 | rritoch | H4ns: It seemed to me as if the reason was based on the fact hat cognitect clients had no need for the features. |
| 03:12 | H4ns | rritoch: what makes you think that? |
| 03:13 | rritoch | H4ns: Checking my old emails. |
| 03:13 | H4ns | rritoch: maybe you want to discuss one of your language feature proposals instead. |
| 03:14 | rritoch | H4ns: No need. I was able to implement it (recently) without any support for clojure by using reflection. |
| 03:14 | H4ns | rritoch: that is probably the reason why your feature request was denied. |
| 03:18 | rritoch | H4ns: The request was never denied, and at the time it wasn't known that it could be implemented with reflection. |
| 03:20 | H4ns | rritoch: in any event, you're mixing up many things: common lisp, free software, clojure features, cognitect customers, reflection - too many for me, i need to drop out of this discussion. |
| 03:24 | rritoch | H4ns: These are all different issues, but related. Clojure isn't standards compliant, clojure is proprietary property of cognitect, if clojure is backed by FSF there is at least some guarantee that it will remain free software. Reflection is just an implementation detail, unrelated to the feature. It was an alternative implementation, or more like hack, to get around clojure politics. |
| 03:25 | chelseaclinton | got problems installing leiningen on windows |
| 03:26 | chelseaclinton | i've installed leiningen but when i hit lein into a cmd prompt, then i get this standalone-jar not found. When I do lein self-install "unable to locally verify the issuers authority" |
| 03:29 | chelseaclinton | got it working using this fix: https://github.com/technomancy/leiningen/issues/1902 |
| 06:19 | j-pb | urgh, clojures numeric tower is even more broken than I though, `denominator` and `numerator` are not safe to use except if you do a manual type check for ratio? |
| 06:20 | j-pb | for example + will recast them into bigints and on those numerator and denominator are invalid |
| 06:20 | j-pb | ,(nominator (+ 1/2 4/3)) |
| 06:20 | clojurebot | #error {\n :cause "Unable to resolve symbol: nominator in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: nominator in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: nomin... |
| 06:21 | j-pb | ,(denominator (+ 1/2 4/3)) |
| 06:21 | clojurebot | 6 |
| 06:21 | j-pb | ,(denominator (+ 1/2 1/2)) |
| 06:21 | clojurebot | #error {\n :cause "clojure.lang.BigInt cannot be cast to clojure.lang.Ratio"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.BigInt cannot be cast to clojure.lang.Ratio"\n :at [clojure.core$denominator invoke "core.clj" 3468]}]\n :trace\n [[clojure.core$denominator invoke "core.clj" 3468]\n [sandbox$eval72 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.Compiler eval "Compi... |
| 06:36 | bpr | does anyone know why tools.reader.edn can't read "(get @*rmq-publications* 0)" but clojure.core/read-string can? |
| 06:37 | bpr | I mean what's the rationale? It's clear that there's no reader-macro defined for \@ in the edn reader, but why? |
| 06:41 | hiredman | edn is a data format, the reader macro @x expands in to a call to the deref function, edn having a reader macro for that would be like json having special syntax for encoding a call to javascripts toString method |
| 06:43 | bpr | so if i'm writing a code analyzer i should use c.t.r/read-string instead? |
| 06:43 | bpr | ok |
| 07:09 | freeman42 | ehm, why would this give a null-pointer exception? http://i.imgur.com/LWtsqdg.png |
| 07:09 | lumafi | because you're calling runit and passing to it the return value of println, which is nil |
| 07:09 | lumafi | so you try to call nil inside runit |
| 07:10 | freeman42 | ah |
| 07:10 | freeman42 | I'm doing it wrong, thank you :) |
| 07:15 | gmanny | what are clojures main advantages over python? |
| 07:31 | H4ns | gmanny: they're different languages and fulfill different needs. there is no way to meaningfully specify one as the other with certain advantages. |
| 07:35 | H4ns | gmanny: that said, the main advantage of clojure over python is that it is much better :D |
| 07:35 | catonano | exploring clj-date, I'm having |
| 07:35 | catonano | (f/parse multi-parser "2013-03-07 17:00:00") |
| 07:35 | catonano | => #<DateTime 2013-01-07T17:00:00.000+01:00> |
| 07:36 | catonano | the month, 03, is being parsed as "01" |
| 07:36 | catonano | look |
| 07:36 | catonano | (f/unparse multi-parser (f/parse multi-parser "2013-03-07 17:00:00")) |
| 07:36 | catonano | => "07/00/2013 17.00" |
| 07:36 | catonano | I had created the parser with |
| 07:36 | catonano | (def multi-parser (f/formatter (t/default-time-zone) "dd/mm/YYYY HH.mm" "YYYY-mm-dd HH:mm:ss")) |
| 07:36 | catonano | What am I doing wrong ? |
| 07:37 | H4ns | catonano: you're using mm for both month and minutes |
| 07:37 | gmanny | H4ns: :). can you expand on that a bit, what things does it do better? |
| 07:37 | catonano | H4ns: Oh gosh. I had completely missed that ! |
| 07:37 | catonano | H4ns: thanks ! |
| 07:38 | H4ns | gmanny: it caters better for my taste. really. |
| 07:39 | H4ns | gmanny: "good/better/best" is not a helpful category when judging languages. you need to ask more specific. |
| 07:39 | H4ns | gmanny: for example, you could ask whether python or clojure support object oriented programming better, and the answer would be "python". |
| 08:27 | freeman42 | was wondering, does . at the begining of a function name has any special purpose? eg. (.moveRight this) or is it just valid part of the identifier? |
| 08:28 | freeman42 | was thinking to refactor (.moveRight this) into something called like (go :direction count) and/or (go :direction) for count = 1 |
| 08:30 | H4ns | freeman42: . at the beginning of a "function name" indicates that the form is not a function call, but rather a java method invocation (http://clojure.org/java_interop) |
| 08:32 | freeman42 | H4ns, thanks, interesting to know, that sheds some light on where the code is interpreted |
| 08:33 | crocket | Does clojure support bitwise operations like & and | ? |
| 08:33 | crocket | >, >> |
| 08:34 | freeman42 | crocket, https://clojuredocs.org/clojure.core/bit-and |
| 08:34 | freeman42 | https://clojuredocs.org/clojure.core/bit-or |
| 08:35 | freeman42 | https://clojuredocs.org/clojure.core/bit-shift-right |
| 08:36 | freeman42 | crocket, what does > and >> mean? :) I assume one of them is bit shift right |
| 08:37 | crocket | 2 >> 3 means shift '2' three times. |
| 08:37 | crocket | 2^3 |
| 08:37 | crocket | 2*2^3 |
| 08:38 | freeman42 | crocket, can't seem to find a shift right/left n times function |
| 08:39 | freeman42 | guess you could easily create one by repeatedly applying shift |
| 08:40 | dottedmag | freeman42: >> is the same as bit-shift-right |
| 08:41 | freeman42 | dottedmag, oh, it does take a number of shifts to apply, didn't notice |
| 08:41 | crocket | How efficient is bit-shift-left compared to << in C and java? |
| 08:42 | freeman42 | probably as efficient as java, best bet is to try it |
| 08:42 | crocket | ok |
| 08:42 | crocket | java has '>' operator. |
| 08:43 | dottedmag | erm, "greater then"? |
| 08:43 | freeman42 | dottedmag, funny :) |
| 08:44 | crocket | Oops |
| 08:44 | dottedmag | crocket: do you mean >>>? |
| 08:44 | crocket | >> |
| 08:44 | crocket | '>>' operator |
| 08:44 | dottedmag | crocket: bit-shift-right |
| 08:44 | dottedmag | crocket: >>> is unsigned-bit-shift-right |
| 08:44 | crocket | https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html |
| 08:45 | freeman42 | or maybe the `goes to` operator while (n --> 0) :D http://stackoverflow.com/questions/1642028/what-is-the-name-of-the-operator |
| 08:46 | crocket | I was worried that clojure couldn't do bitwise operations. |
| 08:46 | crocket | Clojure seemed to operate at such a high level that I thought it couldn't do bitwise operations. |
| 08:48 | freeman42 | another beginner question... say I want to match on the 4 directions (need someting like a C# enum in Clojure) what can I use for that enum? |
| 08:48 | freeman42 | related to "was thinking to refactor (.moveRight this) into something called like (go :direction count) and/or (go :direction) for count = 1" |
| 08:49 | freeman42 | think I heard before that symbols (:symbolName) can be used for that |
| 08:49 | H4ns | freeman42: those are keywords, and they can be used for the purpose you describe. |
| 08:49 | freeman42 | just not sure how/if they are needed to be declared and and example of matching on them |
| 08:49 | freeman42 | *an example |
| 08:50 | H4ns | freeman42: keywords are not associated values, though, so if you need to map to numbers, you'll have to manually translate them or use variables instead. |
| 08:50 | H4ns | freeman42: keywords need not be declared. you can just use them. |
| 08:51 | freeman42 | H4ns, not sure what you mean by map to numbers, I'm thinking to refactor (.moveRight this) into something called like (go :direction count) |
| 08:51 | freeman42 | so inside the go function I'd pattern match on a direction |
| 08:51 | H4ns | freeman42: as you know, .moveRight is not a function invocation, but a java method call, and as such, you cannot replace it by a function directly. |
| 08:52 | oddcully | s/:direction/:east/ ? |
| 08:52 | freeman42 | and call the corresponding (.moveRight this), (.moveUp this) etc |
| 08:52 | freeman42 | oddcully, yeah, something like that |
| 08:52 | H4ns | freeman42: java methods are not first class objects, so you'll have to use (case direction :left (.moveLeft this) :right (.moveRight this) ....) |
| 08:53 | terom | maybe just use :left, :right, :up, :down - you don't need enum like thing |
| 08:53 | freeman42 | oh, there is a case statement cool, is that prefered to core.match? |
| 08:54 | H4ns | freeman42: case is a more specific tool than core.match, which can do more things at the expense of being generally slower. |
| 08:54 | freeman42 | terom, yes, I will probably do that, even though an enum would be nice to limit the possible values |
| 08:54 | freeman42 | H4ns, ok, I'll give it a try, thank you for all the help |
| 08:54 | H4ns | freeman42: if you use case, you'll get a run-time error when no clause can be matched and no default clause exists. |
| 09:03 | freeman42 | hmmm |
| 09:03 | freeman42 | H4ns, I see, so it is like the C# case statement, that is ok |
| 09:08 | freeman42 | oh boy, nothing works in this game :D http://i.imgur.com/gPuHmH6.png |
| 09:13 | chelseaclinton | freeman42: sauce? |
| 09:13 | freeman42 | oh, I'm drunk nvm |
| 09:13 | freeman42 | does not support case either, aw man :( http://i.imgur.com/xGzeSuH.png |
| 09:13 | chelseaclinton | what kind of game is that |
| 09:14 | freeman42 | chelseaclinton, https://codecombat.com |
| 09:14 | freeman42 | it has an option to switch to clojure when playing but it is experimental |
| 09:15 | chelseaclinton | I am most grateful |
| 09:16 | freeman42 | chelseaclinton, after you see how flawed the clojure engine is you might wanna hunt me down :D |
| 09:16 | freeman42 | doesn't even support function as values |
| 09:19 | chelseaclinton | i'm doing basic syntax for now |
| 09:21 | freeman42 | no cond either o.O' http://i.imgur.com/NO04EX1.png |
| 09:21 | Wild_Cat | quick poll: SublimeText's support for Clojure seems to suck. Should I settle for what little it does and leverage the (Windows) command-line for the rest, or should I attempt the switch to IntelliJ for Clojure work? |
| 09:22 | freeman42 | Wild_Cat, switch to IntelliJ :D I think the community edition gives you all that you need |
| 09:22 | freeman42 | Wild_Cat, I'm using Cursive plugin right now, but that won't be free for long afaik |
| 09:22 | freeman42 | the default clojure plugin should be not bad either |
| 09:23 | Wild_Cat | how much should I expect to pay for that? |
| 09:23 | freeman42 | Wild_Cat, not sure, check https://cursiveclojure.com/ |
| 09:24 | Wild_Cat | that's... vague :p |
| 09:25 | Wild_Cat | ty for the info, still |
| 09:25 | freeman42 | Wild_Cat, might want to give Atom a try also http://i.imgur.com/23F725m.png |
| 09:25 | freeman42 | Atom got quite... or rather very fast lately |
| 09:26 | oddcully | the authors wording here was like this here in the past: cursive will be sold as a third party addon to intellij in the price range of webstorm etc (the smaller packages, not ultimate) |
| 09:26 | Wild_Cat | freeman42: ha. Would that mean there's actually something Atom does *not* suck at? Interesting, I'll take a look |
| 09:26 | freeman42 | Wild_Cat, the Atom Haskell plugins are really amazing lately, and setup is very very easy using stack for dependencies |
| 09:26 | freeman42 | probably similar for Clojure |
| 09:27 | Wild_Cat | (my early experience with Atom was thoroughly unimpressive. It really felt like a slow, bad version of Sublime that can't open log files) |
| 09:27 | Wild_Cat | freeman42: sweet. |
| 09:27 | freeman42 | Wild_Cat, ah yeah, Atom when it appeared was really slow and quite bad, now it is quite amazing (not bad) |
| 09:28 | gmanny | what is clojure better at than python? |
| 09:28 | mmeix | more fun to program :-) |
| 09:28 | freeman42 | gmanny, clojure is better than python because it is not python :) |
| 09:29 | oddcully | gmanny: questions like this will only provoke opionionated answers (especially, if you ask them about @language in #language) |
| 09:29 | freeman42 | gmanny, this is my favorite site for getting a general idea of language comparisons based on their qualities: |
| 09:29 | freeman42 | http://hammerprinciple.com/therighttool/items/clojure/python |
| 09:30 | oddcully | gmanny: do you know python and want to learn clojure? or do you want to know in what of those languages to "invest" next? |
| 09:30 | gmanny | oddcully: I know, which is what I expect. |
| 09:30 | gmanny | I know python |
| 09:31 | freeman42 | lol "THIS LANGUAGE HAS A STRONG STATIC TYPE SYSTEM" |
| 09:32 | gmanny | that is an interesting page. it is vote based? |
| 09:32 | freeman42 | gmanny, seems so |
| 09:36 | freeman42 | Wild_Cat, if you are giving Atom a try, please tell us how it goes |
| 09:39 | Wild_Cat | freeman42: will do! |
| 09:40 | Wild_Cat | gmanny: as a seasoned (8+ years) Pythonista currently learning Clojure, the main selling points are immutable data structures, metaprogramming, interop with the JVM, ability to run in the browser (ClojureScript) and performance. Specifically, parallel processing performance and STM. |
| 09:41 | freeman42 | should have just read the issues ^^ it seems when IS implemented... now let's see what `when` does |
| 09:41 | Wild_Cat | it is my belief that Clojure systems are easier to scale up than Python systems. |
| 09:41 | Wild_Cat | that, and Leiningen rocks, too. |
| 09:44 | Wild_Cat | FWIW, I want to use Clojure to generate boring C++ code. |
| 09:44 | liuchang | boring C++ code ..... |
| 09:45 | freeman42 | Wild_Cat, shhh, that might offend someone :p |
| 09:45 | freeman42 | too late |
| 09:45 | Wild_Cat | it's the code that is boring, not C++. |
| 09:45 | Wild_Cat | I'm talking hundreds of lines of near-identical boilerplate crap. |
| 09:45 | freeman42 | Wild_Cat, ah, badly written C++ |
| 09:46 | freeman42 | C++ certainly has the abstractions of making it non-redundant |
| 09:46 | Wild_Cat | stuff that should be autogenerated but isn't, and that I'm tired of cut&pasting |
| 09:47 | freeman42 | Clojure question: can I use `when` in place of a `case`? |
| 09:47 | liuchang | do you think about Template and Macro in C++ to solve the problem |
| 09:47 | Wild_Cat | (and crap conversions between near-identical types because the idea of standardized types hit C++ stupidly recently) |
| 09:48 | Wild_Cat | liuchang: yes, and sadly the need to support MSVC 2010 and Clang on the same codebase means I'm locked out of a ton of features (variadic templates, ##__VA_ARGS__ ...) that *would* significantly reduce the size of my codebase were I able to use them. |
| 09:51 | liuchang | sorry, i can't get your point. you mean that Templates and ##__VA_ARGS__ can't be supported by diff compilers ? |
| 09:52 | Wild_Cat | liuchang: MSVC 2010 doesn't support variadic templates, and it doesn't support ##__VA_ARGS__ either (or rather, it does, as a special-case to __VA_ARGS__ which Clang does *not* support) |
| 09:53 | Wild_Cat | so to answer your question, yes, the need to support different compilers makes our codebase bigger, less elegant and more auto-generated :( |
| 09:54 | nooga | is there a way to inspect running threads? I'm fighting with async manifold code and my laptop is getting hot once in a while when there's not much going on |
| 09:54 | liuchang | ok.. thanks |
| 09:56 | freeman42 | any idea what I'm doing wrong here? or is it not possible? http://i.imgur.com/RBMHvk4.png |
| 09:58 | nooga | freeman42: see http://conj.io/store/v1/org.clojure/clojure/1.7.0/clj/clojure.core/case/ instead of when |
| 09:58 | nooga | when is like (if something something nil) |
| 09:58 | freeman42 | nooga, can't use case cause of https://github.com/vickychijwani/closer.js/issues/3 this is for use in CodeCombat using closer.js, a subset of Clojure |
| 09:58 | nooga | so your first when evaluates as you'd expect, but the second one evaluates to nil and that's what your function returns |
| 09:59 | freeman42 | nooga, oh, I see |
| 09:59 | freeman42 | so then I can solve it with if chain :( |
| 10:00 | nooga | wait, they're talking about cond |
| 10:00 | nooga | cond != case |
| 10:01 | freeman42 | nooga, yeah, but I mentioned in last comment that case is not supported either |
| 10:01 | nooga | ah, didn't notice, sorry |
| 10:01 | oddcully | freeman42: at first glance i found the whole idea there really a nice idea (gamification of learning programming languages). but the code indenting is off and things like case/for are not even working |
| 10:01 | oddcully | so they basically want to type me in (.moveRight this) |
| 10:02 | freeman42 | oddcully, you could probably reinvent some abstractions, and it would also be fun :) |
| 10:02 | oddcully | to me this looks like pretty odd way to let me learn clojure |
| 10:02 | freeman42 | oddcully, ah yeah, definitely a bad way to learn clojure, takes away a lot of the critical functionality |
| 10:02 | freeman42 | like, no functions as values, no case/cond :/ |
| 10:03 | freeman42 | I wonder how hard it would be to implement them in their open source repo of closer.js |
| 10:04 | oddcully | well that is basically the nail into the coffin for me. why would i learn closer instead of clojure(script) |
| 10:05 | freeman42 | oddcully, cause it could be still more useful than playing some other game which does not teach a programming language |
| 10:06 | freeman42 | and working with a subset of clojure is still something cool to learn |
| 10:06 | freeman42 | you could probably recreate different functions yourself |
| 10:06 | nooga | I started by implementing scheme :D |
| 10:06 | freeman42 | hahahahaha xD that was hilarious :D |
| 10:07 | freeman42 | nooga, when you finish, please post a link to your blog post on it to HN, reddit etc. |
| 10:07 | freeman42 | will be a fun thing to read |
| 10:07 | freeman42 | "How I implemented Scheme in a bad subset of clojure in CodeCombat" |
| 10:08 | freeman42 | good example of monsters crawling out of the turing tar-pit |
| 10:09 | nooga | :] |
| 10:10 | liuchang | I would like to implement a scheme :) |
| 10:10 | freeman42 | is this idiomatic indentation of if piramid of doom? http://i.imgur.com/yy5Kkeb.png |
| 10:14 | oddcully | looks like idiomatic closer code :X |
| 10:29 | freeman42 | this works http://i.imgur.com/BcqfIvB.png , but I will have to paste it almost all of the time since they do not provide any way to store user functions accross levels |
| 10:30 | liuchang | what's this game? |
| 10:31 | freeman42 | hadou ken!!! http://i.imgur.com/BtjZedW.jpg |
| 10:31 | freeman42 | liuchang, www.codecombat.com |
| 10:31 | liuchang | thanks |
| 10:31 | freeman42 | liuchang, yw |
| 10:32 | crocket | Is it possible to include two versions of the same jar in a leiningen project? |
| 10:33 | liuchang | No |
| 10:34 | crocket | Does leiningen pull dependencies recursively as npm does? |
| 10:34 | H4ns | crocket: yes. |
| 10:36 | crocket | ok |
| 10:36 | crocket | What about clojurescript? |
| 10:37 | freeman42 | really funny, used dotimes on the previous levels xD http://i.imgur.com/cOhsutc.png |
| 10:41 | mmeix | could someone lend me an eye on https://www.refheap.com/106013 - can't load a lib in boot ... |
| 10:41 | mmeix | (maybe some silly typo) |
| 10:43 | freeman42 | and then can't use the (go direction count) function cause of line limit bonus :D DRY - do repeat yourself http://i.imgur.com/04lun3P.png |
| 10:44 | freeman42 | mmeix, maybe you don't have the jar containing that namespace added as a dependency |
| 10:45 | freeman42 | oh wait, you do |
| 10:45 | freeman42 | maybe it needs that :scope "test" thing too? |
| 10:45 | mmeix | reagent didn't need it, and gets loaded without problem |
| 10:46 | mmeix | hm |
| 10:48 | mmeix | just tested - this is not the problem |
| 10:49 | oddcully | mmeix: this is clojurescript code? |
| 10:50 | freeman42 | mmeix, what IDE are you using? |
| 10:50 | mmeix | Clojurescript, yes |
| 10:50 | mmeix | IDE = Light Table |
| 10:50 | oddcully | i am not sure about this, but are generic clj libs compatible with cljs at all? |
| 10:51 | oddcully | in the browser even a js/JSON could be enough for what you are up to |
| 10:51 | mmeix | ah, maybe data.json is not cljs compatible |
| 10:51 | oddcully | also transit is a popular choice for the client |
| 10:52 | mmeix | the use case is another: I just need to convert a lengthy JSON once to a Clojure(Script) map |
| 10:52 | mmeix | it doesn't change |
| 10:52 | mmeix | (a huge map of settings for a music font) |
| 10:52 | mmeix | will do this in Clojure instead |
| 10:52 | mmeix | and just copy paste in |
| 10:52 | mmeix | thanks |
| 10:56 | freeman42 | mmeix, maybe: http://swannodette.github.io/2014/07/26/transit--clojurescript/ |
| 10:56 | mmeix | ah, thanks! |
| 10:56 | freeman42 | mmeix, and this might be helpful too http://stackoverflow.com/questions/9820869/idiomatically-accessing-json-objects-with-clojurescript |
| 10:56 | freeman42 | mmeix, yw |
| 11:01 | freeman42 | is there an int.max in clojure? (dotimes [_ intMaxHere] (.attack this "Door"))) |
| 11:02 | freeman42 | ah, found it: Integer/MAX_VALUE |
| 11:03 | freeman42 | only it does not work in closer.js, gosh (dotimes [_ Integer/MAX_VALUE] (.attack this "Door"))) |
| 11:04 | liuchang | interesting game |
| 11:09 | freeman42 | liuchang, wish they would give better use cases when introducing new concepts |
| 11:09 | freeman42 | liuchang, not sure if having let bindings is any use here http://i.imgur.com/JbQ0S6B.png |
| 11:10 | freeman42 | or rather, could just say that it is not, cause it is not :) |
| 11:10 | freeman42 | when introducing let bindings they should at least tought of a case when they wouuld have been actually useful, as in reusable |
| 11:10 | liuchang | just introduce the variable |
| 11:10 | liuchang | i think |
| 11:11 | liuchang | *let* is local bind |
| 11:11 | liuchang | it's not easy to introduce this |
| 11:12 | liuchang | so, I think this game will introduce it again, with more words |
| 11:12 | freeman42 | it just started badly, as in, here's a tool... there is no problem it solves in this case, but use it anyway! |
| 11:13 | freeman42 | here's the solution, now find a problem :) |
| 11:13 | liuchang | : ) |
| 11:14 | liuchang | It's too slow to learn clojure.... |
| 11:14 | liuchang | I prefer to read book... |
| 11:16 | freeman42 | doing it mostly for the fun, there are definitely better ways of learning clojure |
| 11:16 | liuchang | yes : ) |
| 11:16 | freeman42 | this game has the benefit of forcing me to actually use clojure, with learning clojure optional :) |
| 11:16 | liuchang | It's very interestring |
| 11:17 | freeman42 | easier to get trapped in the opposite, reading a lot and almost never doing anything |
| 11:17 | freeman42 | doing automatically forces a minimal ammount of thinking, not the same way with reading |
| 11:18 | freeman42 | now they shown an actual reuse of let http://i.imgur.com/7tdlPH2.png |
| 11:19 | liuchang | I am here too~ |
| 11:19 | freeman42 | you are playing much faster |
| 11:19 | freeman42 | liuchang, how much Clojure experience do you have? |
| 11:20 | liuchang | a litter... |
| 11:20 | liuchang | just read some books |
| 11:20 | liuchang | programing in clojure, the joy of clojure, 7 weeks 7 concurrents |
| 11:22 | liuchang | freeman42, and you? |
| 11:22 | freeman42 | liuchang, actually this still has no use as it is highly redundant http://i.imgur.com/Pt11C2C.png |
| 11:23 | freeman42 | liuchang, this is my entire Clojure experience, read it 2 or 3 times http://learnxinyminutes.com/docs/clojure/ |
| 11:23 | freeman42 | liuchang, plus a few meetups I attend |
| 11:24 | liuchang | where are you from :) |
| 11:24 | liuchang | i use cpp and python in work, clojure is just for fun. |
| 11:25 | freeman42 | liuchang, currently Dublin, Ireland, I use C# at work |
| 11:26 | liuchang | beautiful Ireland |
| 11:26 | liuchang | i come from China |
| 11:29 | freeman42 | liuchang, let was completely unneded now too :( 1 liner http://i.imgur.com/D1xTAr4.png |
| 11:29 | virmundi | hello. does anyone have a systemd configuration example for a ring app? |
| 11:32 | drwin | it there a variant of threading macro -> which would pass object further in the pipeline when fn returned nil? |
| 11:34 | freeman42 | liuchang, I wonder when it will actually have a level when let is actually needed |
| 11:35 | oddcully | drwin: did you mean "which would NOT pass"... ? |
| 11:36 | drwin | oddcully: no, I want it to pass, I don't want to reinvent some-> |
| 11:37 | oddcully | but isn't -> just passing it? |
| 11:37 | drwin | oddcully: I'm going to modify some-> macro to do it, it has the test there |
| 11:37 | drwin | oddcully: no, if expr returns nil, then nil flows down the pipe |
| 11:38 | drwin | I want when any expr return nil, it would not modify existing input, and pass it down |
| 11:38 | drwin | s/return/returns/ |
| 11:39 | drwin | basically "nil" answer means, I don't want to touch "it" |
| 12:16 | gfredericks | drwin: I don't think anything exists, no, but it's not hard to make it |
| 12:18 | gfredericks | ,(defmacro heck-> ([x] x) ([x form] `(-> ~x ~form)) ([x form1 form2] `(let [x1# ~x x2# (-> x1# ~form1)] (-> (if (nil? x2#) x1# x2#) ~form2))) ([x form1 form2 & more] (heck-> (heck-> ~x ~form1 ~form2) ~@more))) |
| 12:18 | clojurebot | #'sandbox/heck-> |
| 12:18 | gfredericks | ,(heck-> [1 2] next next next next) |
| 12:18 | clojurebot | #error {\n :cause "Attempting to call unbound fn: #'clojure.core/unquote"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.core/unquote, compiling:(NO_SOURCE_FILE:0:0)"\n :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 6644]}\n {:type java.lang.IllegalStateException\n :message "Attempting t... |
| 12:18 | gfredericks | whoopsiedoodle |
| 12:18 | gfredericks | ,(defmacro heck-> ([x] x) ([x form] `(-> ~x ~form)) ([x form1 form2] `(let [x1# ~x x2# (-> x1# ~form1)] (-> (if (nil? x2#) x1# x2#) ~form2))) ([x form1 form2 & more] `(heck-> (heck-> ~x ~form1 ~form2) ~@more))) |
| 12:18 | clojurebot | #'sandbox/heck-> |
| 12:18 | gfredericks | ,(heck-> [1 2] next next next next) |
| 12:18 | clojurebot | nil |
| 12:19 | gfredericks | I guess that makes sense |
| 12:19 | gfredericks | ,(heck-> [1 2] next next next next next identity) |
| 12:19 | clojurebot | nil |
| 12:19 | gfredericks | hmmm |
| 12:19 | gfredericks | oh yeah |
| 12:19 | gfredericks | er no I'm not sure |
| 12:29 | gfredericks | ,(defmacro heck-> ([x] x) ([x form] `(-> ~x ~form)) ([x form1 & more] `(let [x1# ~x x2# (-> x1# ~form1)] (heck-> (if (nil? x2#) x1# x2#) ~@more)))) |
| 12:29 | clojurebot | #'sandbox/heck-> |
| 12:29 | gfredericks | fixed it; the recursion was wrong; didn't need that many clauses anyhow |
| 12:29 | gfredericks | ,(heck-> [1 2] next next next next next identity) |
| 12:29 | clojurebot | (2) |
| 12:30 | gfredericks | oh wait I'm treating the last function differently but I bet that's not how it's supposed to work |
| 12:30 | gfredericks | ,(heck-> [1 2] next next next next next next) |
| 12:30 | clojurebot | nil |
| 12:30 | gfredericks | yeah that's bad |
| 12:34 | gfredericks | ,(defmacro heck-> ([x] x) ([x form1] `(let [x1# ~x x2# (-> x1# ~form1)] (if (nil? x2#) x1# x2#))) ([x form1 & more] `(heck-> (heck-> ~x ~form1) ~@more))) |
| 12:34 | clojurebot | #'sandbox/heck-> |
| 12:34 | gfredericks | ,(heck-> [1 2] next next next next next next) |
| 12:34 | clojurebot | (2) |
| 12:34 | gfredericks | okay all better |
| 12:35 | gfredericks | drwin: ^ |
| 12:35 | justin_smith | ,(heck-> [1 2] next next next next next next first inc) |
| 12:35 | clojurebot | 3 |
| 12:45 | cfleming | oddcully freeman42 Wild_Cat: the pricing for Cursive for an individual dev will almost certainly be $100. |
| 12:47 | freeman42 | wat? stumped http://i.imgur.com/c9voA5N.jpg |
| 12:48 | justin_smith | freeman42: I don't know what your issue is, but remember that = is not assignment in clojure, it's an equality test |
| 12:49 | freeman42 | justin_smith, my issue is just the way they ask us to solve the problems :) solution looking for a problem... completely unneeded conditions |
| 12:49 | justin_smith | yeah, that's pretty dumb |
| 12:50 | justin_smith | I mean they could have designed a puzzle where you needed conditionals |
| 12:50 | freeman42 | yeah, exactly |
| 12:50 | freeman42 | this is like teaching bad programming |
| 12:54 | freeman42 | correct way, no if's needed (doseq [text ["Hey!" "Yes, you!" "Come at me!" "You are an OGRE!"]] (.say this text)) |
| 12:56 | freeman42 | (O_O) http://i.imgur.com/HcB9uTA.jpg |
| 13:00 | gfredericks | (dotimes [n 4] (.say this (case n 0 "Hey!" "Yes, you!" "Come at me!" "You are an OGRE!"))) |
| 13:00 | gfredericks | ^ another wrong way |
| 13:01 | oddcully | closer does not have case |
| 13:02 | freeman42 | gfredericks, ah the amazing for-case paradigm, even clojure has it http://thedailywtf.com/articles/The_FOR-CASE_paradigm |
| 13:03 | justin_smith | I'd think you'd need some numbers to make that case work |
| 13:08 | freeman42 | what is opposite of https://clojuredocs.org/clojure.core/nil_q ? |
| 13:09 | freeman42 | ah "nil counts as false for the purposes of conditional expressions" |
| 13:10 | oddcully | some? |
| 13:10 | freeman42 | is that for single elements also? not just collections? |
| 13:10 | freeman42 | this is somehow not working: http://i.imgur.com/SUwP2RD.png |
| 13:11 | oddcully | ,(map some? [1 :1 nil]) |
| 13:11 | clojurebot | (true true false) |
| 13:12 | freeman42 | , (some? nil) |
| 13:12 | clojurebot | false |
| 13:12 | freeman42 | , (some? 1) |
| 13:12 | clojurebot | true |
| 13:12 | freeman42 | oh, it works, thank you |
| 13:14 | freeman42 | ah, it actually worked, didn't need to use dotimes which was probably broken in that context |
| 13:27 | lodin_ | freeman42: Still talking about dotimes?! ;-) |
| 13:28 | freeman42 | lodin_, lol no :D |
| 13:28 | freeman42 | lodin_, doseq is all the hype now ;) |
| 13:30 | lodin_ | It would make more sense to use Clojure if the game was functional, instead of using side effects for all game interaction. |
| 13:31 | freeman42 | lodin_, clojure code is guaranteed to have no side effects? |
| 13:31 | lodin_ | freeman42: ? |
| 13:32 | oddcully | lodin_: i bet they just literally translated the python/js/... versions |
| 13:32 | freeman42 | lodin_, https://xkcd.com/1312/ |
| 13:33 | lodin_ | freeman42: http://prog21.dadgum.com/23.html |
| 13:34 | freeman42 | lodin_, ? |
| 13:34 | lodin_ | I thought we were exchanging links. |
| 13:41 | lodin_ | freeman42: Seriously though, that's a good read. |
| 13:44 | freeman42 | lodin_, yeah, but not sure what you want me to focus on that article |
| 13:46 | lodin_ | freeman42: One of the insight that the author arrives at is where to put the side effects in a game (the outer game loop), and that the game logic can be functional. |
| 14:29 | underplank | Hi all. is there a way once you have a compojure app running to inspect the routes its registered |
| 14:48 | domokato | what function/macro do I use to take a collection and apply some function to it repeatedly with each value from another list as a parameter? |
| 14:48 | domokato | do I have to resort to loop/recur? |
| 14:49 | justin_smith | domokato: doseq (for side effects) or for or map (for values) |
| 14:49 | underplank | also note that map is lazy. thats tripped me up sometimes. |
| 14:49 | mmeix | ,(map * [1 2 3] [10 20 30]) |
| 14:49 | clojurebot | (10 40 90) |
| 14:49 | justin_smith | underplank: yeah, that's why I specified for values / for side effects |
| 14:50 | mmeix | right? |
| 14:50 | underplank | yeah. as a newb the differences between value/side effects lazy vs non-lazy and which you use is still difficult to grasp. |
| 14:50 | domokato | in the end I want the collection that is the result of applying all those function calls to it repeatedly |
| 14:50 | domokato | single result |
| 14:51 | underplank | I often go for map to start and then try the others when that doesnt do what I want. |
| 14:51 | justin_smith | domokato: oh, so you are updating some value for each input? then you want reduce |
| 14:52 | domokato | hm, but reduce operates on pairs of items in a list; not sure that fits my use case |
| 14:52 | justin_smith | what? |
| 14:52 | clojurebot | what is an outrage! |
| 14:52 | justin_smith | domokato: that's not what reduce does |
| 14:52 | j-pb_ | clojurebot:lol |
| 14:52 | clojurebot | I don't understand. |
| 14:53 | justin_smith | ,(reduce + [12 24 36]) |
| 14:53 | clojurebot | 72 |
| 14:53 | domokato | yeah, so it does (+ 12 24) first, etc. |
| 14:53 | hellofunk | ,(= (reduce + 1 2) (apply + 1 2) (+ 1 2)) |
| 14:53 | clojurebot | #error {\n :cause "Don't know how to create ISeq from: java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: java.lang.Long"\n :at [clojure.lang.RT seqFrom "RT.java" 528]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 528]\n [clojure.lang.RT seq "RT.java" 509]\n [clojure.core$seq__4126 invoke "core.clj" 135]\n [clojure.core.pro... |
| 14:54 | justin_smith | domokato: + calls reduce |
| 14:54 | hellofunk | ,(= (reduce + 1 2) (apply + [1 2]) (+ 1 2)) |
| 14:54 | clojurebot | #error {\n :cause "Don't know how to create ISeq from: java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: java.lang.Long"\n :at [clojure.lang.RT seqFrom "RT.java" 528]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 528]\n [clojure.lang.RT seq "RT.java" 509]\n [clojure.core$seq__4126 invoke "core.clj" 135]\n [clojure.core.pro... |
| 14:54 | hellofunk | sigh |
| 14:54 | justin_smith | hellofunk: reduce needs a collection |
| 14:54 | hellofunk | ,(= (reduce + [1 2]) (apply + [1 2]) (+ 1 2)) |
| 14:54 | clojurebot | true |
| 14:54 | hellofunk | right |
| 14:54 | justin_smith | domokato: the reason + does the same thing is because + uses reduce in its definition |
| 14:55 | justin_smith | domokato: + was just a simple example - reduce accumulates a result as it visits each member of an input collection |
| 14:55 | justin_smith | ,(reduce conj [] [:a :b :c :d :e]) |
| 14:55 | clojurebot | [:a :b :c :d :e] |
| 14:56 | justin_smith | ,(reduce conj () [:a :b :c :d :e]) |
| 14:56 | clojurebot | (:e :d :c :b :a) |
| 14:56 | mmeix | ,(reduce str ["He" "l" "l" "o"]) |
| 14:56 | clojurebot | "Hello" |
| 14:56 | domokato | justin_smith: basically, instead of applying a function to two elements, i want to apply a function to a hash-set and each element in turn |
| 14:57 | justin_smith | domokato: the same hash-set each time? |
| 14:57 | nooga | is it better to reduce with str or apply str ? |
| 14:58 | nooga | ,(apply str ["He" "l" "l" "o"]) |
| 14:58 | clojurebot | "Hello" |
| 14:58 | justin_smith | nooga: apply will be faster in that case |
| 14:58 | nooga | good, because I'm doing this all the time |
| 14:58 | domokato | justin_smith: well, the function will conj something into the hash-set, then i want to use that new hash-set for the next iteration |
| 14:58 | nooga | :D |
| 14:58 | mmeix | (was just another example for reduce, to excuse me ...) |
| 15:00 | justin_smith | domokato: ##(second (reduce (fn [[hash acc] el] (if (contains? acc el) [hash acc] [(conj acc el) (inc acc)])) [#{} 0] [:a :b :c :d :a :a :a :b])) |
| 15:00 | lazybot | java.lang.IllegalArgumentException: contains? not supported on type: java.lang.Long |
| 15:00 | justin_smith | err |
| 15:00 | justin_smith | ,(second (reduce (fn [[hash acc] el] (if (contains? hash el) [hash acc] [(conj hash el) (inc acc)])) [#{} 0] [:a :b :c :d :a :a :a :b])) |
| 15:01 | clojurebot | 4 |
| 15:01 | justin_smith | that's a reduce with effectively two accumulators |
| 15:02 | mmeix | maybe domokato could show an example of what he wants to achieve ...? |
| 15:02 | justin_smith | ,(second (reduce (fn [[hash acc] el] (if (contains? hash el) [hash (inc acc)] [(conj hash el) acc])) [#{} 0] [:a :b :c :d :a :a :a :b])) ; counting dups this time |
| 15:02 | clojurebot | 4 |
| 15:02 | domokato | hm, let me stare at that for a while lol |
| 15:03 | justin_smith | domokato: the only difference there from a normal reduce is each element in the vector is effectively a separate accumulator |
| 15:03 | justin_smith | so it tracks a set of things it has seen, and an accumultated score, side by side |
| 15:04 | domokato | oh okay neat |
| 15:05 | domokato | can i basically stick the hash-set as the first element of the list and then pass reduce a function that takes the hash-set and the next element and returns the hash-set with the next element conjoined? |
| 15:06 | justin_smith | domokato: well that sounds a lot like ##(reduce conj #{} [:a :b :c :d :a :b :c :a :b :a]) |
| 15:06 | lazybot | ⇒ #{:c :b :d :a} |
| 15:06 | justin_smith | unless you are doing something else with the hash-set |
| 15:07 | justin_smith | domokato: like I said before, reduce doesn't go over pairs of the input, it goes over successive accumulated results and the input |
| 15:07 | domokato | oh, reduce takes a val argument! i missed that |
| 15:08 | domokato | thanks :) |
| 15:08 | justin_smith | so you were asking a much simpler question, cool |
| 15:08 | justin_smith | yeah, if you don't provide an accumulator argument, it uses the first element of the collection for that |
| 15:08 | domokato | i knew i was just missing something simple |
| 15:09 | mmeix | as an aside - in this case: wouldn't it be better to do just: |
| 15:09 | mmeix | ,(apply hash-set [:a :b :c :d :a :b :c :a :b :a]) |
| 15:09 | clojurebot | #{:c :b :d :a} |
| 15:10 | justin_smith | or ##(set [:a :b :C :d :a :b :c :a :b :a]) |
| 15:10 | lazybot | ⇒ #{:C :c :b :d :a} |
| 15:10 | justin_smith | haha, typo |
| 15:10 | justin_smith | or ##(into #{} [:a :b :c :d :a :b :c :a :b :a]) |
| 15:10 | lazybot | ⇒ #{:c :b :d :a} |
| 15:10 | mmeix | ah, better still |
| 15:10 | justin_smith | (into is useful if you arleady have part of your set |
| 15:10 | justin_smith | ) |
| 15:11 | mmeix | into is especially useful, I found |
| 15:11 | mmeix | (beginner's mind still) |
| 15:13 | mmeix | ,(inc justin_smith) |
| 15:13 | clojurebot | #error {\n :cause "Unable to resolve symbol: justin_smith in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: justin_smith in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol:... |
| 15:13 | mmeix | lol |
| 15:13 | hellofunk | (inc mmeix) |
| 15:13 | lazybot | ⇒ 2 |
| 15:13 | hellofunk | that's how |
| 15:13 | justin_smith | mmeix: inc is a lazybot command, so no , is needed |
| 15:14 | mmeix | (into brain [more stuff]) |
| 15:14 | mmeix | all the time |
| 15:14 | mmeix | :) |
| 15:42 | lynn | how do I expand a variable that I'm passing to a macro? |
| 15:42 | lynn | here is what I'm trying to do: |
| 15:42 | lynn | https://gist.github.com/lynndylanhurley/695495f7584c1295a75f |
| 15:43 | lynn | where `defroutes` is a macro defined by Pedestal |
| 15:44 | justin_smith | lynn: the only way to do it is to write another macro |
| 15:44 | justin_smith | or directly use whatever function the defroutes macro is calling |
| 15:45 | lynn | justin_smith: thanks I have tried that actually. I'll show you what I tried, maybe you can help me figure out what I'm doing wrong |
| 15:45 | justin_smith | sure |
| 15:45 | justin_smith | macros are a bit tricky |
| 15:46 | lynn | yeah I'm finding that out for myself :) |
| 15:46 | lynn | here was my best attempt: |
| 15:46 | lynn | https://gist.github.com/695495f7584c1295a75f |
| 15:47 | lynn | when I try running (foo-routes) outside of the defroutes macro, it seems to output what I want |
| 15:48 | lynn | but it doesn't seem to expand when used within the defroutes macro |
| 15:48 | lynn | I also tried (macroexpand (foo-route)) |
| 15:48 | lynn | but that didn't work either |
| 15:51 | justin_smith | lynn: for your macro to work the defroutes call has to be inside your macro |
| 15:51 | lynn | oh I see - so I need to write a macro that contains the call to the defroutes macro |
| 15:51 | justin_smith | lynn: the problem is that the defroutes macro uses some of its input unevaluated, which means you need another macro around it that evaluates the things you want evaluated before calling the macro |
| 15:51 | justin_smith | right |
| 15:52 | justin_smith | sometimes we call this "macro-contagion" - you want to extend something, it's a macro, now you need another macro surrounding it |
| 15:52 | mmeix | is this a case of macros being "contagiuous"? |
| 15:52 | mmeix | ah, ok |
| 15:52 | lynn | lol |
| 15:54 | justin_smith | in terms of extensibility, it's good to remember data > functions > macros - the further to the left you are on that list, the more flexibly others can use it |
| 15:55 | mmeix | that's a good sentence to remember |
| 15:55 | mmeix | (inc justin_smith) |
| 15:55 | lazybot | ⇒ 275 |
| 15:57 | mmeix | aha, that's why libs sometimes have two versions of some functionality: as a function and as a macro - right? |
| 15:57 | lynn | yeah that's really good advice! I was trying to write a module that could be mounted to an existing pedestal app. I wonder if there's another way |
| 16:55 | rlb | Perhaps I'm misreading, but I just noticed that it seems like the current jvm atom implementation might allow you to have an atom with a state that doesn't agree with the current validator... |
| 16:55 | justin_smith | rlb: do you have code that shows that happening? |
| 16:55 | rlb | i.e. there's no synchronization in ARef setValidator. Perhaps that's intentional. |
| 16:55 | justin_smith | rlb: oh, iirc setValidator does not validate the existing state |
| 16:55 | rlb | justin_smith: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ARef.java#L49 |
| 16:56 | rlb | it says it does in the docs |
| 16:56 | justin_smith | oh, well that would validate it yeah |
| 16:56 | rlb | yes, but I'm wondering if there's a race between the validation and the assignment. |
| 16:57 | justin_smith | ahh, now I get it |
| 16:57 | rlb | i.e. you check the value you just derefed, then someone else changes the value, then you set the validator. |
| 16:57 | rlb | If that's right, then perhaps the docs or the behavior needs adjustment... |
| 17:27 | bcham | hey I |
| 17:27 | bcham | I'm having an issue with enlive snippets that I can't figure out. when a snippet returns a value it's wrapped in parens as in ({:tag :div}) |
| 17:28 | justin_smith | AKA it's a list? |
| 17:28 | bcham | yes |
| 17:28 | bcham | how do I transform it into the tag tree? |
| 17:29 | bcham | ((html/wrap {:tag :div}) {:tag :div :content ["hello"]}) |
| 17:29 | bcham | is basically what I |
| 17:29 | bcham | am going for. |
| 17:29 | justin_smith | you could do (apply html/wrap v) or (html/wrap (first v)) |
| 17:29 | justin_smith | depending on whether there would be other things you want in that list |
| 17:32 | bcham | Thanks justin, I think I've got it. Was confused about this list wrap. |
| 17:35 | bcham | But now I'm suffering from a different issue. I want to pass this into a template and i'm getting an error doing so. I cannot cast a persistent hash map to clojure.lang.named |
| 17:38 | bcham | html/wrap seems to return an array-map instead of the correct structure |
| 17:38 | bcham | Man this language makes me feel like an idiot. |
| 17:40 | bcham | I'm trying to convert it back to nodes and a list but that doesn't seem to work. Relevant wrap function is here: https://github.com/cgrand/enlive/blob/master/src/net/cgrand/enlive_html.clj |
| 17:42 | bcham | any ideas justin_smith ? |
| 17:47 | bcham | nevermind, just tried to avoid the problem entirely. |
| 17:47 | bcham | or found a way to |
| 18:33 | bucketh3ad | Is there a way to get a lein project to load the :provided profile dependencies first? I'm working with a library that only works if it's loaded before any other libraries. |
| 22:56 | mrcheeks | bucketh3ad:Have you considered the Xbootclasspath JVM parameter? |
| 23:13 | Sublixt | Im trying to assoc an infinite list as a value for a map. but it times out. |
| 23:14 | Sublixt | Is this just impossible to do, or am I going about it wrong? |
| 23:14 | justin_smith | ,(assoc {} :a (range)) |
| 23:14 | clojurebot | {:a (0 1 2 3 4 ...)} |
| 23:14 | justin_smith | Sublixt: the assoc should just work, the printing might time out |
| 23:15 | Sublixt | Odd, when I did it in my game it never left the frame I called it in |
| 23:15 | justin_smith | are you sure you aren't using the value? |
| 23:16 | Sublixt | Ummm I'm not quite sure what you mean |
| 23:16 | justin_smith | well, anything that tries to consume that infinite list is going to time out |
| 23:17 | Sublixt | Oh I understand what youre saying |
| 23:17 | Sublixt | Yeah Im dumb |
| 23:18 | Sublixt | the api is probably trying to render it |