#clojure logs

2012-03-25

00:00alandipertmk: (doseq [x xs] (println x)) would do it
00:01mkalandipert: why wasn't my (map println [1 2 3]) working as expected?
00:02alandipertit returns the seq of println mapped over 1 2 3, and println always returns nil
00:02alandipertdoseq always returns just nil
00:03alandipert(it's for side effects like printing, vs. map, which is for working with values)
00:04mkah, which means map is lazy
00:04mkalandipert: thanks
00:05yoklovyou could (dorun (map println '(1 2 3)))
00:05alandipertmk: right, and np.
00:05yoklov(which returns nil instead of a seq of nils)
00:07mkinteresting. It seems like those are effectively equivalent?
00:08yoklovoh
00:08mk(I don't actually know if they are, but it seems they do the same thing, since dorun is for producing effects)
00:09yoklovthey are no
00:09yoklovt
00:09yoklov,(doseq [a '(1 2 3)] (prn a))
00:09clojurebot1
00:09clojurebot2
00:09clojurebot3
00:09yoklov,(dorun (map prn '(1 2 3)))
00:09clojurebot1
00:09clojurebot2
00:09clojurebot3
00:10mk...are you sure?
00:10yoklovi mean
00:10yoklov(map prn '(1 2 3))
00:11yoklovretuns a seq
00:11yoklovwhich when e forced prints some stuff
00:11yoklovdorun takes that and forces everything
00:11yoklovwheras doseq takes a seq, and does some stuff to it, forcing it in the process
00:12yoklovwith dorun your seq could be produced elsewhere
00:13mk,(time (dorun (map prn '())))
00:13clojurebot"Elapsed time: 0.145 msecs"
00:13mk,(time (doseq [a '()] (prn a)))
00:13clojurebot"Elapsed time: 0.964 msecs"
00:13yoklovalso doseq is a macro, and dorun is a function
00:13yoklovi'd assume their performance is the same and clojurebot is being weird
00:14yoklovmaybe not.
00:14mkfactor of 10:1 on my repl. Interesting
00:16mkyoklov: by the way, how was your port of the game turning out?
00:17yoklovhaha, i haven't gotten too far, gonna work on it more tomorrow. friends of mine who were worrying for my sanity convinced me i should go out tonight instead of just staying inside and writing code :p
00:18Frozenlo`And he calls himself a friend? tsss
00:18mkpfft, some friends you have ;)
00:18yoklovseriously, what jerks
00:23mkhmm, there's no set of all namespaces?
00:24mk,*ns*; only shows the current, while (all-ns) returns a seq...
00:24clojurebot#<Namespace sandbox>
00:27yoklovjust do (set (all-ns))?
00:30mkyoklov: I was thinking of trying to break things by messing with the real *all-ns-set* - looks like it's hidden behind clojure.lang.Namespace/all, though
00:35yoklovhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Namespace.java yeah i don't think you can get at that
00:36cgaghow do I set a property in clojurescript?
00:38yoklovoh
00:38qbgHmm... Calling a function with ints boxed in a mutable wrapper is only 50% slower than calling a function that takes primitive ints it looks like
00:38yoklov(set! (.-prop obj) val)
00:38yoklovi think
00:38yoklovshould work.
00:41cgagthat worked, thanks
00:41yoklovawesome
00:41cgagare there any resources on clojurescript? i didn't seem much on the documentation on the repo
00:42yoklovi don't really know, to be honest. i've been going mostly by code in libraries and knowledge of clojure
00:44cgagyeah that's what i've been doing so far
00:50yoklovalso the compiler is in clojure so its fairly readable
00:51yoklovdunno how helpful it is, but its certainly interesting
01:35mk(doc +')
01:35clojurebot"([] [x] [x y] [x y & more]); Returns the sum of nums. (+) returns 0. Supports arbitrary precision. See also: +"
01:37mk,'+'
01:37clojurebot+'
01:38mkstrange, the ccw repl seems broken. I get +\n#<Exception java.lang.Exception: EOF while reading> when trying '+'
01:39amalloythat was not valid syntax in 1.2, so the ccw repl is probably running on 1.2
01:40mkhmm, yes: "1.2.0"
01:40mkthat's rather annoying - how can I update?
01:41amalloy*shrug* ask someone who knows anything about ccw. maybe cemerick or lpetit?
01:44mkamalloy: I might try switching to something else. Thanks for catching that
03:25muhooi've got some functions i tend to use a lot in the repl, what's the best way to have them around? create a project, make a jar of it, and add it to project.clj? or is there some other way?
03:29muhooor just ln -s the file in, and then require it?
03:33Raynesmuhoo: Lein 2?
03:33Raynesmuhoo: If you're using lein 2 you can edit ~/.lein/profiles and add it to your :user profile.
03:34RaynesNow go upgrade if you haven't already.
03:49amalloymuhoo: i recommend making a utility project for them
03:49amalloythen you can use them in actual programs you write, not just repl experimentation
03:50muhooamalloy: that's what i kind of thought, thanks.
03:51amalloyif you want, you can start by forking mine from http://github.com/flatland/useful - it probably includes some of the things you want already, and should provide a reasonable base for adding more
03:53muhooi saw that, it was very, er, useful. i'm pretty sure the stuff i'm doing is a lot more pedestrian
03:54muhoolike, my stuff is baby steps still, and i'm sure i'll end up using useful at some point.
03:55muhooe.g., this is the kind of stuff i ended up typing over and over again and decided, finally, to make a library of it: https://refheap.com/paste/1358
03:56muhoolike a blind man feeling his way around a dark room with a single candle, still.
03:57muhoooh, so that's where assoc-in! is!
03:58muhooi saw clutch examples used assoc-in! and i couldn't find it anywhere. i guess it was in useful all along.
03:58amalloyi doubt if cemerick is using useful; it's probably someone else's
04:01muhooRaynes: yes, i'll try lein2 at some point. as of now, i'm still trying not to change anything that'll confuse or disorient me any more than i already am :-)
04:14RaynesMan.
04:14RaynesUtility libraries make me want to stab myself in the face.
04:15mkRaynes: why's that?
04:17RaynesBecause they do nothing but grow. They start out as "Here is a few of my favorite things!" and turn into giant libraries of unrelated things. The best you can hope for is some semblance of structure and organization, but in the end it is still a giant mess of things someone has thought up over the past two years.
04:18Raynes"Ah, this is a nice function. But there are a thousand other nice functions. My options are to depend on this giant utility library or copy this code and thus duplicate functionality. My head. IT BURNS!"
04:21mkI think that's a problem of organization. I'm not a fan of huge files. If there's something that can be used independently, it should have its own file
04:24mkI'd just copy the code if I were you
04:30ZnudzonHi i have installed clojure 1.3 but now i would like to install contrib libs. I 've made everything from the install instructions but i still dont have the .jar file but a lots of directories with lisb . What now ?
05:18gtuckerkelloggcan one run tests on a leiningen project from swank?
05:19amalloygtuckerkellogg: you probably want clojure-test-mode
05:20gtuckerkelloggamalloy, that does sound like somethnig i would want, doesn't it!
05:20gtuckerkelloggthanks
05:20gtuckerkelloggand btw, amalloy, i like your clojopts rep
05:21amalloythat makes one of us!
05:21gtuckerkellogg:)
05:25gtuckerkelloggamalloy, that is one fantastic mode. wow
05:29amalloythen i should learn to use it :P. i'm still in the stone age of testing
05:36gtuckerkelloggi create a lot of bugs, so i like testing
05:54khaliGanyone alive?
05:55khaliGI need to recur twice in a function but the compiler says can only recur from tail position
05:55AimHereWell both places you're recurring from ought to be the tail position
05:55khaliGhttp://pastebin.com/fdjMBhMG
05:55clojurebotHuh?
05:56AimHereWhat 'tail position' means is that no operations are happening to the results of the recur before the result is returned
05:56khaliGimpossible, gotcha :)
05:56khaliGnow to figure out how to write inline java *grin*
05:57AimHereWell often you can rewrite functions to be tail recursive, or make slightly-different functions that do the same job (the 'loop' function helps with this)
05:57AimHerethe latter being functions that take a bunch of parameters
05:58AimHereNot sure how you'd do it for your function though
05:58AimHere*different bunch of parameters
05:58khaliGyeah dunno im probably using the wrong language
06:00khaliGhm wait there isn't any issue if I don't use the recur keyword
06:00khaliGwhich i suppose is where I went wrong
06:00khaliGthanks AimHere
06:02AimHereWell that code, if it works at all, seems to be out of the functional-idiom; I can't tell because I don't know what merge* does, though
06:03khaliGright, it's basically mutating the array A recursively. I got it out of a textbook
06:04AimHereFair enough; Clojure tends to default to functional style, and would just return a new merged array from the old rather than mutating things
06:04AimHereAt least it's users would ;)
06:04khaliGhmmm understood :)
06:38deobaldAnyone around? swank-clojure is barfing on `Unable to resolve classname: BufferedReader` on a friend's Mac (1.6.8). I can run JRuby's irb and `lein repl`, so Java's not completely broken. Is swank-clojure looking for the Java classes in the wrong place somehow?
08:22hyperboreeanhow do you sort a list of maps by a key's map in clojure? (I am looking for something like python's sorted(lst, key = lambda t: t['price']). Should I use a sorted map instead ?
08:23hyperboreeanmap's key that is
08:48kij Hey, The reductions example here, http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci#Recursive_Version seems be self-referencing, was that valid as some point? and what would the syntax be now ?
09:15gfrederickskij: that doesn't work?
09:16AimHereI just tried it, it works
09:17gfredericksanother mystery solved
09:17AimHerekij > The trick with that is that you don't need the self-reference for the first two members of the sequence, and the laziness stops the sequence from being an infinite regression at any one point in time
09:20AimHereWell okay, the second variant, with the reductions doesn't work
09:22AimHerekij > (lazy-cat [1] (reductions + ....) works
10:10wmealingi have a class with a dash, but the file name that midje tests/looks for has an underscore. Is this expected ?
10:10wmealingshould there be no dashes in clojure filenames ?
10:10gfrederickswmealing: correct; from the java side all dashes are underscores
10:11gfredericksthat's filenames and class/package names mostly
10:11wmealingok
10:11wmealingnot what i expected, but as long as its across the board.
10:11wmealingthanks gfrederi`
10:11wmealingoops, gfredericks
10:11gfredericksyessir
10:12gfrederickshuh I must be logged on somewhere else o_O
10:50ScorchinIs it possible to use regex with (case ..) ?
10:52gfredericksyour question is ambiguous but I expect no either way
11:16mmajchrzakIs there any gui lib for clojure ? I know that i can still use libs from java but for my its too complicated with bigger aps.
11:17AimHereSeesaw is a clojureish wrapper around swing, which might make some things neater for you
11:18mmajchrzakthak you I will check this on google :)
11:18RickInGAhere's a cool seesaw tutorial http://blog.darevay.com/2011/12/a-seesaw-tutorial/
11:26FrozenlockHow does one get the value of a class? By that I mean the value written when doing 'C-c I' in slime.
11:26FrozenlockOr rather let met explain my master plan. Perhaps I have the wrong approach.
11:26FrozenlockI have multiple 'properties' all stored with different java classes. Here is an example on how I need to access the data with the current library: (-> data-storage (.get object-ID Property-ID)). I would like to transfer all this info into a map of this form: {:object1 {:Property1 value :Property2 value} :object2...
11:26Frozenlock
11:27FrozenlockIn addition, I would like to drop all the special classes in the process. For example, for the CharacterString class, I would like to simply store the string such as "this is my string" instead of #<CharacterString this is my string>.
12:08mkFrozenlock: did you solve your problem?
12:08Frozenlockyes and no... I'm making a function that retrieves every properties. It might take a while. :)
12:09FrozenlockAnd usually when it takes a while, I'm doing something wrong.
12:09dnolencore.logic occurs-check is way more expensive in JS than on the JVM
12:11mkFrozenlock: what did you mean by the value of a class? getClass?
12:19FrozenlockI wasn't clear, I apologize. Say I have this object PropertyIdentifier/presentValue (of the class PropertyIdentifier). I would like to get the value shown when I inspect it with 'C-c I'. In this case, its value is "Present Value".
12:20andre27ciao
12:20FrozenlockI'm still new to all this object/class/method thing, I really might confuse them...
12:22mkFrozenlock: you want to get the return value of a method?
12:22mkor is that an attribute?
12:22FrozenlockNot a method, so I would say attribute.
12:23FrozenlockOk wait, I have an example
12:23mk(also called a property, I guess)
12:23FrozenlockSay (def test1 "hello")
12:24FrozenlockIts value is "hello" when inspected with 'C-c I' (obiously).
12:24FrozenlockI could just type test1 in the REPL and get the answer.
12:24mkFrozenlock: I don't use emacs, but I follow you so far
12:25FrozenlockHowever with my PropertyIdentifier/presentValue, I get a java object returned in the REPL
12:25Frozenlock--> #<PropertyIdentifier Present value>
12:25FrozenlockHow can I get the 'Present value' part?
12:27FrozenlockIn other words, I want to get rid of the java part and only keep a string or symbol 'Present value'.
12:29mkFrozenlock: is PropertyIdentifier/presentValue simply a static field, like Math/PI ?
12:30FrozenlockI suppose so.
12:30mkwhat's (type Prope...) ?
12:30Frozenlock..type.enumerated.PropertyIdentifier
12:31FrozenlockBut when you type Math/PI, you get the value, not simply --> #<Math PI>
12:31mkFrozenlock: right, because:
12:32mk,(type Math/PI)
12:32clojurebotjava.lang.Double
12:32raekFrozenlock: do you have a link to the javadoc?
12:33FrozenlockYes, brb.
12:33mkso your class Prop..Id.. has a static field of type PropId. Presumably the toString method returns a string, which you see in your repl
12:33raekjava only has fields and methods. I supspect these properties are objects defined by the library
12:34Frozenlockhttp://sourceforge.net/projects/bacnet4j/files/bacnet4j/1.2/
12:34raekyeah, when you see #<Foo bar> in the repl, it means that you have an object of class Foo whose toString method returns "bar"
12:35FrozenlockSo I could use toString? Let met try that...
12:35FrozenlockOh wow.
12:35FrozenlockSo simple.
12:35FrozenlockYet I was so far away.
12:35raekFrozenlock: if the javadoc of PropertyIdentifier says you should use toString do it
12:35mkFrozenlock: it might be easier to get the field that toString uses
12:36Frozenlockmk: how can I get this field? .getfield or something like that?
12:37raekFrozenlock: do you have any java code example for what you are trying to do?
12:37raekit's much simpler if we can see some sort of documentation of how these classes are supposed to be used
12:37mkFrozenlock: I'm looking at the class docs, and it's a class with many static members
12:37Frozenlockraek: Indeed... I see now that .toString is the only method for this class in the doc.
12:38raekyour questions are not anymore about java in general, but specifically about this library
12:38Frozenlockraek: I'm sorry, I still don't see where the line is between java/libraries.
12:39raekFrozenlock: are you sure the PropertyIdentifier actually holds the value?
12:39FrozenlockI do have examples on how the java code works. No problem there, I've translated most of what I needed.
12:40mkFrozenlock: are you writing out every single property in the PropertyIdentifier class? you don't need to
12:40raekand that it isn't some key of some sort that is used to extract a value from another object
12:40Frozenlockraek: it's exactly that.
12:41raekthen you can't get the value using only the property identifier, I gess?
12:41FrozenlockBut I want to put everything in a map with my own keys. {:present-value data}
12:42Frozenlockraek: No. I have the key associated value. What I wanted was the PropertyIdentifier name, so I could use it in making my own map.
12:42mkFrozenlock: ok, so the PI object has a bunch of static fields - acceptedModes, ackedTransitions, etc., about 50 of them. You want to use those as your keys
12:42raekwell, if I understand you correctly, then :present-value corresponds to PropertyIdentifier/presentValue
12:42Frozenlockmk: yes
12:42FrozenlockYes it does.
12:42raekand you're asking how to perform something like (get m :present-value)?
12:43raekbut we don't know what m corresponds to in the java lib
12:43mkhowever, whoever made this library ... ok, wow, yeah.
12:44raekyou're probably looking for something like (.getProperty some-object PropertyIdentifier/presentValue)
12:44Frozenlockraek: No, I was asking at the very beginning if there was a way to easily transfer the info to a map. Then I asked a more precise question with the goal of obtaining the present-value key, which I did, thanks to you :)
12:44raekok, I didn't see the whole backlog
12:44Frozenlockmk: wow in which direction? Wow ugly, wow great?
12:45mkwhat's a decent pastebin for clojure?
12:45raekmk: refheap
12:45raekFrozenlock: so which class does the map-like object have?
12:45mkFrozenlock: "wow this could be done totally differently in clojure"
12:46raekyou can probably transform that object into a map pretty easily
12:46mkhttps://refheap.com/paste/1359
12:46raekbut the solution will be spicific to this library
12:46mkthat's the source of the object
12:46Frozenlockraek: Class PropertyValues
12:46Bronsawow.
12:47raekyikes.
12:47raekI'm glad we have macros in clojure-land
12:48Frozenlockraek: At least I can! :D
12:48FrozenlockI wouldn't want to stay in those java calls...
12:49scriptoris any of that code generated?
12:49scriptorI don't use java at all, but I've heard ide's like eclipse now do a good bit of code generation and manipulation for you
12:49mk...this class extends 4 further classes
12:50mkscriptor: I'll hazard a guess and say "no"
12:50scriptordamn
12:50raekFrozenlock: I think I misunderstood your original question. were you asking how to go from an instance of PropertyIdentifier for present value to something like :present-value?
12:51raekand back again?
12:51Frozenlockraek: only the first part. But both ways could be handy too :P
12:51mkraek: I think Frozenlock wants the tostring values of each PI that the PI lists as a static field
12:52raekright.
12:52raekI was confused by "the value of a PropertyIdentifier"
12:52raekthe toString method seems to solve the problem
12:52FrozenlockI apologize, like I said, I do not master the vocabulary yet.
12:53FrozenlockIndeed.
12:53raekbut you could also use reflection to get the name of the class as a string
12:53FrozenlockPropertyIdentifier
12:53FrozenlockIs there a way to list all static fields?
12:53raekFrozenlock: no worries, everytihng is clear now... :-)
12:53mkraek: rightly so - its value is, for some strange reason, implemented strictly as its toString value
12:53raekyes
12:53raekreflection
12:54mkFrozenlock: yes, I'm looking up the reflection code you need
12:54raekthe java reflection api is a bit verbose
12:54FrozenlockThanks to you both, I really appreciate your help :D
12:58raekthere are some convenient methods in clojure.lang.Reflector to go from class + name of field to value of field
12:58mkhow does one get the Class of a class?
12:59raekit will always be java.lang.Class
13:00mkright, but how do I get the instance?
13:00raek(the generic parameter does not exist after compilation in java)
13:00raekmk: just write java.lang.Class
13:00raekor (class (class some-object))
13:00raekFrozenlock: http://www.jarvana.com/jarvana/view/org/clojure/clojure/1.3.0/clojure-1.3.0-javadoc.jar!/clojure/lang/Reflector.html#getStaticField(java.lang.String, java.lang.String)
13:01raek,(class (class 123))
13:01clojurebotjava.lang.Class
13:01mkI want the class of ScaryPropertyThing without having to do SPT.field.getClass
13:01raekor did you mean the Class object given its name?
13:01mkroughly, yes
13:02raekin clojure you just write the class name directly in the code (if you know it when you write)
13:02raekif you need to do the translation programatically, you need to use reflection
13:03raek,(class 123)
13:03clojurebotjava.lang.Long
13:03raek,java.lang.Long
13:03clojurebotjava.lang.Long
13:03raek,(class java.lang.Long)
13:03clojurebotjava.lang.Class
13:03mkoh, well then :)
13:03raekthe repl prints classes like symbols...
13:04Frozenlockraek: with this I can use getStaticField to get the fields, is that right?
13:04raekbut the reflection way is pretty simple too: (Class/forName "java.lang.Long")
13:04raekFrozenlock: if the property is a field, then yes
13:05raekoh sorry
13:05raekyeah
13:06raekPropertyIdentifier/foo = (Reflector/getStaticField "com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier" "foo")
13:06raekFrozenlock: ^
13:07raekor simply (Reflector/getStaticField PropertyIdentifier "foo")
13:07FrozenlockWait wait, I'm still trying to require the Reflector library...
13:08mk,(map #(.getName %) (.getFields (Class/forName "java.lang.Math")))
13:08clojurebot("E" "PI")
13:08raek(ns ... (:import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier clojure.lang.Reflector))
13:08raekor (import 'com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier) (import 'clojure.lang.Reflector)
13:09FrozenlockIt's not in clojure core?
13:09Frozenlock(I need to dowload it?)
13:09mkyou probably don't need the reflector. Just use the toString method
13:09raekno, it's in the implementation of clojure
13:10mkyou actually can't get the value of the object any other way, since toString generates the value based on an int
13:10FrozenlockOh I need to 'import'!
13:10raekmk: yes, but I still think reflection is needed for the reverse case (string to PropertyIdentifier instance)
13:11mkraek: I don't think it's possible to do that in that way, the string values are inside toString
13:12raekyes, but using getStaticField you can go from "foo" to the value PropertyIdentifier/foo would return
13:13raekso the internal string is not used
13:13raekonly the name of the field
13:13mkso you're talking about a mapping from the key to the PropIdent object - gotcha
13:14raekyikes. that author has really missed the whole enum thing
13:14FrozenlockHow can I list every static fields?
13:15mkFrozenlock: I pasted the code above
13:15Frozenlock,(map #(.getName %) (.getFields (Class/forName "java.lang.Math")))
13:15raekthis is essentially what the java compiler generates when you type public enum {foo, bar}
13:15clojurebot("E" "PI")
13:16raekexcept that you ca[1~ w[1~ except that with enums you can go from string to instance too :-)
13:16Frozenlockmk: works flawlessly, thanks!
13:17raekautomatation FTW
13:18FrozenlockYeah, I was worried I would have to hardcode every single field.
13:18raekif you want to be really pedantic you can filter the fields to only see the static and public ones
13:22raek(for [field (.getFields java.lang.Math), :let [mod (.getModifiers field)], :when (and (Modifier/isPublic mod) (Modifier/isStatic mod))] (.getName field))
13:22mkwhat's the code for doing a map, but keeping the map? (??? identity '(1 2)) -> {1 1 2 2}
13:23raekzipmap maybe?
13:23raek&(let [coll (range 5)] (zipmap coll (map str coll)))
13:23lazybot⇒ {4 "4", 3 "3", 2 "2", 1 "1", 0 "0"}
13:24Frozenlockraek: modifier?
13:24mkzipmap zips two collections - I want a version of map that keeps the mapping
13:24raekFrozenlock: java.lang.reflect.Modifier
13:24raeksorry :-)
13:24raekmk: and also produces a map instead of a lazy sequence?
13:24mk(map inc (1)) gives (2), I want {1 2}
13:25raek&(into {} (map (juxt identity inc) (range 5)))
13:25lazybot⇒ {0 1, 1 2, 2 3, 3 4, 4 5}
13:26raekyou need (apply hash-map ...) (zipmap ...) (into {} ..) or something similar to get a map
13:27raekI would use zipmap if I had a sequence, a function and wanted to contruct a map from x to f(x)
13:29raekFrozenlock: another pedantic thing to do would be to limit the results to the fields that have the correct type: (= (.getType field) Property.Identifier)
13:30raekbut that's probably overkill in this case
13:30FrozenlockBetter safe than sorry, thanks!
13:32raekmk: afaik, there is no function f in clojure.core that does (f str [1 2 3]) => {1 2, 2 3, 3 4} I'm afraid
13:33raeks/str/inc/
13:34AimHereraek > It's very easy to roll your own
13:35AimHere,((fn [f a] (zipmap a (map f a)) inc [1 2 3])
13:35clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
13:36AimHere,((fn [f a] (zipmap a (map f a))) inc [1 2 3])
13:36clojurebot{3 4, 2 3, 1 2}
13:36raekI can agree that it would be a useful function to have in the standard library though
13:37mkok, here we go:
13:37mk,((fn [classname] (into {} (map (juxt #(.getName %) #(.toString (.get % nil))) (.getFields (Class/forName classname)))) )"java.lang.Math")
13:37clojurebot{"E" "2.718281828459045", "PI" "3.141592653589793"}
13:37raekah cool :-)
13:37FrozenlockOhhhh that's sexy!
13:49mk,(flatten '("one" "two"))
13:49clojurebot("one" "two")
13:50mk,(into {} (flatten (map #(list (.getName %) (.toString (.get % nil))) (.getFields java.lang.Math))))
13:50clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.Character cannot be cast to java.util.Map$Entry>
13:50mkwhats going on there?
13:51mkoh, I see
13:52gfredericks,(->> "java.lang.Math" Class/forName .getFields (map (juxt #(.getName %) #(.toString (.get % nil)))) (into {}))
13:52clojurebot{"E" "2.718281828459045", "PI" "3.141592653589793"}
13:54mk,(into {} (map #(vector (.getName %) (.toString (.get % nil))) (.getFields java.lang.Math)))
13:54clojurebot{"E" "2.718281828459045", "PI" "3.141592653589793"}
13:56mkwhat would it do?
13:57gfredericksmaybe it could be the map-from-fn function we've all been wanting
13:58mkit has a bit of a priorityqueue or sorted feel to it
13:59the-kennyLike (victor identity inc [1 2 3]) -> {1 2, 2 3, 3 4} ?
14:00gfredericksthe-kenny: that suggests interesting vararg possibilities
14:00gfredericksthe-kenny: but no, I was thinking the identity was implicit
14:00gfredericksso just (victor inc [1 2 3])
14:00mkgfredericks: what sort of possibilities?
14:00gfrederickseither multiple functions or multiple collections
14:01the-kennygfredericks: Yeah, just added this for more possibility
14:01mkthe multiple collections would serve as params?
14:01gfredericksmaybe?
14:01gfredericksthe-kenny: I like the idea of having 2-arg and 3-arg versions
14:02mkthat's what map does
14:02the-kennygfredericks: Yeah
14:03gfredericks(defn victor ([f coll] (victor identity f coll)) ([f1 f2 coll] (zipmap (map f1 coll) (map f2 coll))))
14:09yoklovhm, is there a list of the functions in the clojure api which aren't in clojurescript?
14:09gfredericksI doubt it; could be interesting to see how easily that could be generated though
14:11the-kennyThere's a wiki page "Differences between Clojure & Clojurescript"
14:12the-kennyHowever, it's missing some things. Clojurescript sadly doesn't have `sorted-map' :(
14:12yoklov`shuffle` is also unimplemented
14:12yoklovwhich isn't documented anywhere i think
14:12yoklovwhich is why i asked haha
14:12gfredericksshuffle would be easy to add
14:13yoklovyeah, thats why i was surprised it hadn't been done
14:14lynaghkyoklov: Fisher-Yates in-place shuffle is implemented by Closure in goog.array.shuffle
14:14lynaghkyoklov: if you are okay with dropping down to JS
14:15dnolenemezeske: is there an easy way to get lein-cljsbuild to use a custom version of the clojurescript compiler?
14:15yoklovi am, how can you convert a collection to a js array (sorry, new to clojurescript)?
14:16lynaghkdnolen: thanks for that pointer to the LEARN PROLOG NOW! book, I've been reading that plus finally getting into the Reasoned Schemer copy that I got at the Conj.
14:16donkeykonghello, emacs newbie here... im trying to play with labrepl to get the hang of clojure. using emacs and clojure-jack-in. the repl starts fine and i can navigate to the labrepl webpage. however, when i evaluate (doc println) in the repl i get a "Unable to resolve symbol: doc in this context [Thrown class java.lang.RuntimeException]"
14:16gfredericksdonkeykong: try (use 'clojure.repl) first
14:17dnolenlynaghk: np, Prolog lit really clarifies a lot of things, I'm thinking about putting together a core.logic basic that illustrates how to do basic conversions.
14:17Frozenlockdonkeykong: with emacs, you should do 'C-c C-d d' on what you want more details.
14:17lynaghkyoklov: (array 1 2 3) will make a js array [1, 2, 3]. If you have something in CLJS, you can (apply array my-seq)
14:17dnolencore.logic basic wiki page I mean.
14:17yoklovlynaghk, thanks
14:17Frozenlockdonkeykong: Or even M-. if you want to see the source
14:17donkeykonggfredericks: that works! thanks much.
14:17lynaghkdnolen: that would be pretty rad. Especially now that you have it working in CLJS---props on that, by the way.
14:18donkeykongFrozenlock: ok il keep that in mind. lots of keybindings to pick up, one step at a time!
14:18FrozenlockThe joy of emacs :P
14:19dnolenlynaghk: thanks! Yeah I'm excited, interestingly core.logic seems to run equally fast under all the browser nightlies. I think people could actually design some really interesting logic libs that normal JS libs can consume.
14:20qbgIt would be cool if the CLJS compiler could be compiled to JavaScript
14:20Frozenlockdonkeykong: I also hope your on IRC with Emacs :P
14:20lynaghkdnolen: yeah, I haven't done much in the way of making CLJS libs accessible from plain JS, but I'll be figuring that out soon on a client project.
14:20Frozenlock*you're
14:20lynaghkI expect it's just a lot of ^:export
14:20gfrederickslynaghk: depends on if you want data structure translation too
14:21donkeykongFrozenlock: yes and it greets me with "Be happy for Emacs. Emacs is your life." -- Omar Khayyam
14:22dnolenqbg: probably possible and not that much work. I think once we have performant data structures, it will be more interesting to pursue.
14:22lynaghkgfredericks: yeah, that was the incredibly annoying lesson learned from cljs-d3 and one of the main reasons I rewrote it in plain Clojure
14:22qbgdnolen: Imagine ClojureScript as a browser plugin
14:22qbgNo external deps!
14:22gfrederickslynaghk: I messed with that once. My solution was to generate an API namespace that had a wrapper for each public function and also did the data translation
14:23gfredericksI was talking to emezeske about whether or not that would be useful in cljs-build
14:23gfrederickspart of the issue is there's no easy way to generate a separate namespace using cljs code or macros
14:24lynaghkgfredericks: some kind of macro that would automatically throw together a namespace with certain functions in it and wrap their args in translations?
14:24gfrederickslynaghk: yeah that's what I was thinking, but you can't really emit a namespace
14:24gfredericksat least not with the current compiler
14:24gfredericksso hooking into cljs-build would probably be the most straightforward option, whether that's by adding it to the cljs-build project proper or cljs-build providing hooks
14:26lynaghkgfredericks: I've been thinking about that problem in the context of clj/cljs code sharing; I'm working on something that would just emit generated sources, so you'd be free to make up as many new namespaces as you want
14:26gfredericksyeah I think that's how I did it initially; I can't remember if lein-cljsbuild existed at that point or not
14:27gfrederickslynaghk: what're you trying to achieve there that the cljsbuild crossovers don't?
14:27dnolenqbg: would be cool, probably inevitable really :)
14:28qbgAlmost zero barrier to entry :)
14:28lynaghkgfredericks: there are some transformations that need to happen beyond just copying the files. For instance, in Clojure you extend clojure.lang.IFn with invoke. In ClojureScript it's IFn and -invoke
14:29gfredericksah right
14:30lynaghkgfredericks: I've been looking into using Kibit to do those kind of rearrangements, and also filtering based on metadata so you can remove entire toplevel forms if necessary. E.g., in the source you'd define two sqrt functions; one annotated with ^:clj that uses (Math/sqrt x) and one annotated with ^:cljs that uses (.sqrt js/Math x).
14:30gfrederickslynaghk: I wonder if symbol macros together with a cljs? function would suffice for most cases?
14:31lynaghkbut, uh, kind of taking a detour to learn logic programming so it might be a few weeks before I can get something working out the door.
14:31lynaghkgfredericks: that is Evan's approach right now. We talked about this problem at Clojure/West a fair bit, and we're going to just try both and see what feels better.
14:32lynaghkgfredericks: one of the reasons I want to use metadata over macros is so that I can use the JVM Clojure REPL as much as possible.
14:32gfrederickshmmm
14:33gfrederickswhat about metadata on arbitrary forms?
14:33gfrederickswhere the form itself gives the clojure version and in the metadata you give a cljs replacement
14:34gfredericks(defn sqrt [x] #^{:cljs (.sqrt js/Math x)} (Math/sqrt x))
14:34lynaghkgfredericks: that's an interesting idea. I feel like that would make my editor super angry.
14:34gfrederickshaha why?
14:34qbggfredericks: A compiler-cond macro?
14:35gfredericksqbg: eh? not sure what that means
14:35lynaghkgfredericks: dunno, just shoving a lot of forms around I guess. That might be a cool addition, but I definitely want to have the basics (like this clojure.lang.IFn -> IFn) work out of the box automatically.
14:35qbgcond, but evaluates at macroexpansion time
14:35gfredericksqbg: are you suggesting that's what I'm doing, or suggesting an alternative?
14:36qbgIt would be a bit more general of an alternative\
14:36mkis there a categorized list of all of clojure core?
14:36gfredericks$google clojure cheatsheet
14:36lazybot[Clojure - cheatsheet] http://clojure.org/cheatsheet
14:36qbgBut it is basically a (poor) reimplementation of reader conditionals from CL
14:36gfredericksmk: ^ seen that?
14:37lynaghkgfredericks: I just added you to the collaborators list for this repo, if you want to watch how it develops. I'll writeup the README a bit more and open source it when it's barely usablable.
14:37gfredericksqbg: also there's always #=(if cljs? 'js/Math 'Math/sqrt)
14:37mkyep, it's open in a tab, but I think it's missing things, and was hoping for something a bit more parsable
14:38qbgCan we do better than #+ and #- from CL?
14:38gfredericksqbg: what do those do?
14:38gfredericksmk: there's also using the ns functions to get all the vars
14:38gfredericksthat's not too categorized though
14:39qbgDepending on *features*, conditionally ignore the next form
14:39mkgfredericks: yeah, I actually just did (sort (keys (ns-publics (the-ns 'clojure.core)))) :)
14:40qbghttp://www.lispworks.com/documentation/lw50/CLHS/Body/24_aba.htm
14:41dnolenhmm I thought I could just run 'lein install' from a project, did this chagne?
14:42fprefect,(class (char-array [\x \y \z]))
14:42clojurebot[C
14:44dnolenooops, 'lein install' works just fine
14:48gfrederickslynaghk: how does cljx relate to cljsbuild?
14:49lynaghkgfredericks: it doesn't; assuming I can get it to something useful, it'd be a lein plugin that generates clj and cljs from "cljx" source files. You'd still use cljsbuild, but you wouldn't need to do anything with crossovers.
14:50gfrederickslynaghk: ah hah;
14:50gfredericksvery nice
14:50lynaghkgfredericks: if by "very nice" you mean "terrible terrible hack" = )
14:51mkhow can I use booleans?
14:51gfredericksmk: um
14:51gfrederickshow do you want to use them?
14:51mk(booleans ???) -> something that isn't an error
14:52gfredericks,(type true)
14:52clojurebotjava.lang.Boolean
14:52gfredericks,((juxt type identity) (boolean 15))
14:52clojurebot[java.lang.Boolean true]
14:52mkI want to use the booleans function in particular
14:52gfredericksoh wait there is a 'booleans function
14:52gfredericksI see
14:52gfredericks,(doc booleans)
14:52clojurebot"([xs]); Casts to boolean[]"
14:52gfredericksah right; arrays; what fun
14:52gfredericks,(booleans [true false true])
14:53clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to [Z>
14:53gfredericks&(-> [true false true] (make-array) (booleans))
14:53lazybotclojure.lang.ArityException: Wrong number of args (1) passed to: core$make-array
14:53mknice try! ;)
14:53gfredericks&(->> [true false true] (apply make-array) (booleans))
14:53lazybotjava.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Character
14:53gfredericksconsarnit
14:53gfredericks&(doc make-array)
14:53lazybot⇒ "([type len] [type dim & more-dims]); Creates and returns an array of instances of the specified class of the specified dimension(s). Note that a class object is required. Class objects can be obtained by using their imported or fully-qualified name. Class objects f... https://refheap.com/paste/1362
14:53gfredericks&(doc to-array)
14:53lazybot⇒ "([coll]); Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to java.util.Collection.toArray()."
14:54gfredericks(->> [true false true] to-array booleans)
14:54gfredericks&(->> [true false true] to-array booleans)
14:54lazybotjava.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Z
14:54qbg&(->> [true false true] (into-array Boolean/TYPE) (booleans))
14:54lazybot⇒ #<boolean[] [Z@d94042>
14:55gfredericksevery time I need to work with arrays there's always five functions that do mostly the same thing and I always try the right one last
14:55mk,(into-array Boolean/TYPE [true false true]) ; I get the impression that the use of booleans was superfluous there, qbg...
14:55clojurebot#<boolean[] [Z@1ad13ee>
14:55qbgmk: It is
14:56qbgtype hinting is the only reason to use booleans
14:56qbg(basically)
14:57qbgBut Clojue's philosophy is to be close to the host...
14:58gfredericksyeah :)
14:58gfredericksI didn't mean that it'd be compatible with clojure's goals or anything
14:58qbgIgnoring the host isn't good enough?
14:58mkso... ok... core has some really silly-looking infrequently-used functions
14:59dnolenemezeske: hmm, how can I install lein-cljsbuild from the repo locally?
14:59gfredericksqbg: well an ideal dialect could be guaranteed to execute the same on all hosts
14:59mkqbg: thanks for solving the mystery of booleans
14:59gfredericksmk: yeah it does have a lot of those
14:59qbgbooleans in the end is just return (boolean[])o;
14:59mkgfredericks: like the intersection of what you can expect all the hosts to implement
15:00gfredericksmk: and maybe some other non-performant modifications like always promoting to bigints (or rather semantically bigints everywhere -- not exposing a distinction)
15:00qbgmk: Examples that you think are silly?
15:02gfredericksqbg: could go even further and make it pure-functional, I think
15:02mkqbg: ffirst and its ilk, apparently most of these array casts... *1 *2 should be in the repl, that sort of thing
15:03devnwhat am i doing wrong with seesaw here? It seems like my keystroke listener works in the nth instance (-> f show!), but then fails in new instances
15:03qbgmk: Wait until you see CL...
15:03mkqbg: CL?
15:04devncommon lisp
15:04gfrederickscommon lisp
15:04qbgWith the ca*d*r functions
15:04mkright. Yeah, there might be quite a wait on that ;)
15:04qbged is my favorite
15:05qbgBasically not implemented in the impls I used
15:05mked?
15:05clojureboted is the standard editor!
15:05Iceland_jacked.
15:06qbghttp://clhs.lisp.se/Body/f_ed.htm
15:06irc2samushi guys, in order to test if a given instance implements some interface is it rigth to use "instance?"?
15:07gfredericks,satisfies?
15:07clojurebot#<core$satisfies_QMARK_ clojure.core$satisfies_QMARK_@14dd46d>
15:07mkif that's the scheme editor, it's the reason I stopped messing about with learning scheme
15:07gfredericksirc2samus: I think that does it ^
15:07qbgirc2samus: Yes
15:07gfredericksoh wait
15:07gfredericksI read 'protocol' instead of 'interface'
15:08irc2samusoks thanks!
15:11gfredericksso do CL/scheme have a single stringy-thing while clojure has three?
15:11qbgstringy-thing?
15:11gfredericksstring/symbol/keyword
15:12qbgCL has all of those
15:12AimHereScheme has strings and symbols, at least
15:12gfrederickshell also char-seqs
15:12qbgCL strings are mutable
15:13gfredericksthen there are also vectors of futures of atoms of length-1 strings
15:13gfrederickswhich are what I use most of the time
15:14qbgCL has zero dimensional arrays
15:14qbgAnd arrays which point to the contents of other arrays
15:14gfredericksit has more than one of them?
15:15qbgIt has real multidimensional arrays
15:15qbgNot just arrays of arrays
15:15qbgA 1 dim array which shares the contents of a 2d array is fun
15:16gfredericksthat's funny I have the opposite opinion
15:16qbgThere was a C implementation for the lisp machines
15:17qbgThat would really show how "portable" your C code is!
15:25gfredericksdoes erc have a built in thing for keeping track of mentions and such?
15:40mkwhat's the difference between = and ==?
15:41muhoo&(doc =)
15:41lazybot⇒ "([x] [x y] [x y & more]); Equality. Returns true if x equals y, false if not. Same as Java x.equals(y) except it also works for nil, and compares numbers and collections in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) ... https://refheap.com/paste/1363
15:41gfredericks,(doc ==)
15:41muhoo&(doc ==)
15:41lazybot⇒ "([x] [x y] [x y & more]); Returns non-nil if nums all have the equivalent value (type-independent), otherwise false"
15:41clojurebot"([x] [x y] [x y & more]); Returns non-nil if nums all have the equivalent value (type-independent), otherwise false"
15:41gfredericksman I don't know what that means
15:41muhoome neither *shrugs*
15:42mk,(== 1 1)
15:42clojurebottrue
15:42mk"returns non-nil"
15:42gfredericks,(== 1 1.0)
15:42clojurebottrue
15:42muhoo,(= 1 1.0)
15:42gfredericks,(= 1/3 0.3333333333333333)
15:42clojurebotfalse
15:42clojurebotfalse
15:42muhooAHA!
15:42gfredericksoh wow
15:42muhoo== is type independent
15:42gfredericksdidn't expect (not= 1 1.0)
15:42muhoolike it says
15:43gfredericksyet ##(= [3] '(3))
15:43lazybot⇒ true
15:43gfredericks&(= [3] '(3.0))
15:43lazybot⇒ false
15:43muhoo&(== [3] '(3.0))
15:43lazybotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number
15:43muhoorealy?
15:44gfredericks&(== [3] [3.0])
15:44lazybotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number
15:44gfredericks???
15:44lazybotgfredericks: How could that be wrong?
15:44muhoo" if nums"
15:44muhooso == can only handle numbers
15:44gfredericksooh
15:44Bronsa== is just for numeric comparison
15:44gfredericksyou learn something new every minute
15:44gfredericks((juxt = ==) 0.75 3/4)
15:44gfredericks&((juxt = ==) 0.75 3/4)
15:44lazybot⇒ [false true]
15:45muhoowhat i like about clj si that the new things i learn make me go "ooh" not "wtf".
15:46gfredericksmuhoo: like ##(#'and true false true)?
15:46lazybot⇒ true
15:46muhoo&(and true false true)
15:46lazybot⇒ false
15:46mkthis is new in 1.3 it seems, since 1.2 gives true on (= 3 3.0)
15:47muhoowhat's the #' do?
15:47Bronsayou call and as a function, not as a macro
15:47gfredericks,(= #'and (var and))
15:47clojurebottrue
15:48muhoowhy would you do that?
15:48gfredericksyou wouldn't so it's not a very good example :)
15:48Iceland_jackwhy indeed
15:48Bronsawhen a macro is called &form and &env are implicitly passed
15:48gfredericksclj does indeed have less WAT than js
15:48Iceland_jackWATs per minute
15:48Bronsaif you call it as a function, you need to pass them manually
15:48muhoospm
15:48muhoowpm
15:49Iceland_jackalso WTF's per minute, that's how I measure my software
15:49Bronsaso (#'and true false true) is really (and true)
15:49muhoointeresting
15:50gfredericksjs is like a practical joke that got out of hand
15:50muhoocould be worse.
15:50muhooyou could be coding in php and java for a living
15:51muhoowhich have more "oh christ i want to stab my eyeballs with a fucking pencil!" per minute, IME
15:51gfredericksOCIWTSMEWAFP
15:51gfredericks//m
15:52gfrederickshard to start a message with a slash
15:52muhoo /like this
15:52gfredericksyes like that
15:52mk,[(compare "a" "z") (compare 1 26)]
15:52devnweee, i now have a fancy capslock keyboard for overtone
15:52clojurebot[-25 -1]
15:53gfredericks&(doc compare)
15:53lazybot⇒ "([x y]); Comparator. Returns a negative number, zero, or a positive number when x is logically 'less than', 'equal to', or 'greater than' y. Same as Java x.compareTo(y) except it also works for nil, and compares numbers and collections in a type-independent manner. x must implement Comparable"
15:53muhoohah, a comparator. what's next, an op-amp?
15:53muhoomaybe a schmitt trigger
15:54mkit's strange that it returns the alphabetic diff of the first char
15:54gfredericks&(compare "aa" "az")
15:54lazybot⇒ -25
15:54gfredericks&(compare "aa" "ba")
15:54lazybot⇒ -1
15:55muhooi guess it's just supposed to be negative, zero, positive, and the actual value isn't meaningful?
15:55mkuhm.
15:55gfredericksyeah
15:55mkwhy?
15:55clojurebotWhy is why
15:55gfredericksso it's quicker to return the diff than check it first
15:55gtrakhow do I override + within a macro?
15:55muhoo,why
15:55clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: why in this context, compiling:(NO_SOURCE_PATH:0)>
15:55gfrederickswith-redefs?
15:55muhoo`why
15:55gtrakI get, 'can't let qualified name'
15:56gfredericksgtrak: oh you're trying to (let [+ foo] ...)?
15:56gtrakyea
15:57gfredericksokay use ~'+ then
15:57gfredericks+ will expand to clojure.core/+ otherwise
15:57gtrakah, I see
15:57muhoogtrak: ##(letfn [(+ [x y] (- x y))] (+ 3 4))
15:57lazybot⇒ -1
15:57gtrakmakes sense :-)
15:57gfredericksmuhoo: he's already inside a macro
15:58gfredericksor backquote rather
15:58muhoooh
15:58gfredericks,`(let [+ -] (+ 3 4))
15:58clojurebot(clojure.core/let [clojure.core/+ clojure.core/-] (clojure.core/+ 3 4))
15:58muhoocool
15:58gtrakjust reinventing vector math :-)
15:59beffbernardif you have a java-source-path defined, can you reference your clojure code from java?
15:59gtrakthere's no plusable unfortunately
15:59beffbernardin leiningen
16:01yoklovhaha, persistent data structure heavy clojure code makes for very sloooow clojurescript code
16:02devnwee... time to figure out how to draw a keyboard with seesaw, heh
16:02dnolenyoklov: very :)
16:04yoklovyup, it does work though, which is a huge plus. shouldn't be too hard to make this quicker.
16:04yoklovare clojurescript lists copy-on-write too?
16:05qbgyoklov: I think everything in CLJS is copy on write
16:05gfrederickswhat do people mean by "clojure doesn't have a cons cell"? Is it just that Cons requires a seq for the second part?
16:05gfredericksqbg: lists are easy to do persistent though; I'd be surprised if they were copy on right
16:05qbggfredricks: I believe so
16:05yoklovyeah, thats why i asked
16:06gfredericksit'd almost be harder to do COR for lists
16:06qbgYeah, I think I'm thinking of vectors
16:06yoklovgfredericks, yeah the cons cell from most lisps is just two objects, and it's only a list if the second one is a list
16:07dnolenyoklov: lists don't need to be copy-on-write
16:07yoklovright, but if they were i wouldn't want to use them
16:07AimHereyoklov > Don't you mean if the second one is a cons cell?
16:07yoklovno
16:08yoklov(1 . (2 . (3 . 4))) is not a list
16:08gfredericksyoklov: so you meant it recursively
16:08yoklovyeah
16:08gfredericksa list is a cons cell whose second element is nil or a list
16:08yoklov(1 . (2 . (3 . (4 . ())))) is a list
16:08yoklovright.
16:09yoklovsince nil is the empty list, it counts as a list
16:09yoklovin those lisps
16:09Iceland_jackyoklov: (1 . (2 . (3 . 4))) is an improper list
16:09yoklove.g. scheme is the one i can actually talk about because i haven't really ever written anything non-trivial in common lisp
16:10yoklovIceland_jack, i guess it depends on if you consider an improper list to be a type of list
16:10gfredericksI believe erlang also has cons cells in the same sense
16:10Iceland_jackWell in Common Lisp (1 2 3) and (1 2 . 3) are both considered lists; proper and improper lists respectively
16:10Iceland_jackLanguages like Clojure/Haskel/ML et al don't allow improper lists
16:12yoklovyup, which is sorta nice. clojure has better data structures to fill that void
16:13qbgWhat is read-string in CLJS?
16:13gfredericksI'd expect the same as in clj
16:13gfredericksoh unless it doesn't exist
16:13gfredericksI'm always misinterpreting questions
16:16ihodeshmmm so there's got to be a better way of doing this... i've got a cond tree, and one of the test statements is something kinda complicated, and what returns (if it's logically true) is what i want cond to return... but i need to use cond. any ideas of what to do?
16:16gfredericksihodes: that's only the case for one of your clauses?
16:16ihodescurrently i'm just computing it twice; once to evaluate to true, and then once for the return value: e.g. (cond (something complicated returning true maybe) (same thing))
16:16ihodesgfredericks: for a few of the clauses, but not all of them
16:17gfredericksihodes: first thought is to set each of those up in a let wrapped around the cond, but with a delay
16:17gfredericks(let [x (delay ...), y (delay ...), z (delay ...)] (cond @x @x (foo) bar @y @y @z @z))
16:17ihodesyeah, i wanted to avoid that for aesthetic purposes, but maybe so
16:18gfredericksmaybe the only way to clean it up is to write a macro
16:18qbgUse (some identity <lazy-seq>)?
16:18ihodesqbg: that's what i'm actually doing, but it's ugly
16:19ihodesgfredericks: grrrr. it seems common enough that there'd be a way of handling it. but i guess i don't actually run into it that often
16:19gfredericksyeah I don't think I ever have
16:19ihodeshaha something like (cond (my expression) :ibid)
16:20qbgCould use the ternary form of condp
16:20qbgBut that would be a ugly
16:20gfredericksthen there's an (or) with your other cases wrapped in ifs
16:21qbgYeah, you could use or
16:21Frozenlo`Is there a function to make a key from a name? (the inverse of `name')
16:21qbg&(keyword "foobar")
16:21lazybot⇒ :foobar
16:21Frozenlo`Thanks!
16:21qbggfredericks: Probably no need for if
16:22gfredericksqbg: when he wants separate parts there would be...
16:22qbgor is short circuiting
16:22gfredericks(cond (x) (x) y z (w) (w)) becomes (or (x) (if y z) (w))
16:22ihodesexactly
16:23ihodeshmmmmmmm
16:23gfredericksqbg: his main problem is he's mixing two kinds of clauses
16:23gfredericksunless he's a woman and then it's her main problem
16:24ihodesi'm a him. freenode should allow you to enter preferred pronoun. would solve all sorts of problems.
16:24qbgIf (some identity ...) currently works, then or should work also
16:25gfredericksihodes: man that'd make things even easier than face-to-face
16:25ihodesi could just use (or (x) (if y z) (w)). that might be the best way to do it without writing a macro.
16:26gfrederickswith each clause on its own line it should be pretty readable
16:27ihodesi just hate having about 14 (if x y)s in there. so much repetition.
16:28qbgMaybe you can refactor that?
16:28ihodesmeh i guess i can use a cond for all the ifs, within the or
16:28gfredericksyeah it totally depends on how mixed the types of clauses are
16:29ihodesyeah. at this point, i'm just trying to make it look nice. i think (or (x) (y) (z) (cond a b, c d, e f)) is the best way of handling it
16:31ihodesthanks for the brainstorming gfredericks & qdb
16:34muhooone of the nice things about reading the source of the cljwest slides is that i discoverd there's a slideshow mode for emacs
16:35muhoodidn't know org-mode could do slides.
16:35devnorg-mode can do...everything
16:36mkhow can I check if something is a boolean, and also, do exception-throwing boolean casting?
16:36gfredericksmk: ##(assert (boolean? :foo))
16:36lazybotjava.lang.RuntimeException: Unable to resolve symbol: boolean? in this context
16:36gfrederickswtf
16:37qbgmk: booleaning casting how?
16:37mk,(int "a")
16:37gfredericks&(assert (instance? Boolean :foo))
16:37lazybotjava.lang.AssertionError: Assert failed: (instance? Boolean :foo)
16:37clojurebotExecution Timed Out
16:38gfredericks&(assert :foo)
16:38lazybot⇒ nil
16:38devn&(let [x false] (or (true? x) (false? x)))
16:38lazybot⇒ true
16:38mk&(int "a")
16:38lazybotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character
16:38devngfredericks' is way better
16:38mkwhy did clojurebot time out?
16:38devn&(map char "a")
16:38lazybot⇒ (\a)
16:39devn&(map (comp int char) "a")
16:39lazybot⇒ (97)
16:39mkhow do I pretty-print a 2d list as a table?
16:40devncl-format
16:40gfrederickswill pprint/print-table take integer keys?
16:41devn&(use 'clojure.pprint)
16:41lazybot⇒ nil
16:42gfrederickshow often does lazybot reset those ns ops?
16:42devn&(pp/print-table [:a :b] {:a [1 2 3], :b [4]})
16:42lazybotjava.lang.RuntimeException: No such namespace: pp
16:42devn&(print-table [:a :b] {:a [1 2 3], :b [4]})
16:42lazybot⇒ ======= :a | :b ======= | | ======= nil
16:43devnerr
16:43mk,`print-table
16:43clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class clojure.lang.RT>
16:43devn&(print-table [:a :b] {:a 1, :a 2, :a 3, :b 4})
16:43lazybotjava.lang.IllegalArgumentException: Duplicate key: :a
16:43mk&`print-table
16:43lazybot⇒ clojure.core/print-table
16:43devn&(print-table [:a :b] [:a 1, :a 2, :a 3, :b 4])
16:43lazybot⇒ ======= :a | :b ======= | | | | | | | | ======= nil
16:43gfredericks&(print-table [2 1] [101 102 103] [[201 202 203] [301 302 303]])
16:43lazybotclojure.lang.ArityException: Wrong number of args (3) passed to: pprint$print-table
16:43gfredericks&(print-table [2 1] [[101 102 103] [201 202 203] [301 302 303]])
16:43lazybot⇒ ========= 2 | 1 ========= 103 | 102 203 | 202 303 | 302 ========= nil
16:43mephist0an easy way to convert this [a b] [1 2] into this {a 1 b 2} please
16:44gfredericksmephist0: (into {} ...)
16:44gfredericksno
16:44devnmephist0: zipmap
16:44gfredericksmephist0: zipmap
16:44devn&(zipmap [:a :b] [1 2])
16:44lazybot⇒ {:b 2, :a 1}
16:44mkso how do I do the table thing, then?
16:44dnolenhmm is there any way to specify multiple source paths to leiningen?
16:45gfredericksmk: make sure you have vectors as the inner lists
16:45mephist0very good. Thank you devn gfredericks
16:45mkI can't resolve symbol print-table
16:45devnmk: you need to use or require clojure.pprint
16:45gfredericksand then (print-table (range (count (first vectors))) vectors)
16:45muhooi kind of like incanter's way of printing tables
16:46devni kind of dislike the print-table fn. i got a mild headache molding all of my data into what it expected
16:46gfredericks(-> seqs first count range (print-table (map vec seqs)))
16:46mkthis is in clojure 1.3?
16:46muhooif you tell it (view (to-datasource some-data-structure)) it does a pretty good job
16:46gfredericksmk: yeah
16:46devnmk: nod
16:46devnmk: it would be helpful to show us the data you have as input
16:47devna sample of it, anyway
16:47muhoosorry to-dataset
16:47gfredericksdevn: how would you have done print-table?
16:48mkdevn: [[12][213123 23][213123 234][9 9 9 9 9 9 9]]
16:48mk(or some random similar arrangement)
16:49devngfredericks: im not sure, it just seems like there should maybe be some general fns to make your data fit what print-table expects
16:49devngfredericks: for instance, if i want to just print-table of {:a 1, :b 2}, it seems like i should able to just do that
16:49qbg&(cl-format true "~{~s~%~}" [[1 2 3] [4 5 6] [7 8 9]])
16:49lazybot⇒ [1 2 3] [4 5 6] [7 8 9] nil
16:50gfredericksqbg: what is this witchcraft?
16:50devngfredericks: or if i have [:a [1 2 3], :b [4 5 6]], it feels like it should just "get it"
16:50devngfredericks: you havent joined the cult of the cl formatter?
16:50devn&(cl-format nil "~R" 111)
16:50lazybot⇒ "one hundred eleven"
16:50devn&(cl-format nil "~r" 111)
16:50lazybot⇒ "one hundred eleven"
16:50devn&(cl-format nil "~@R" 111)
16:50muhoothat's pretty bad ass
16:50lazybot⇒ "CXI"
16:51devnit's like learning a new mini language, though
16:51qbg&(cl-format nil "~:@R" 4)
16:51lazybot⇒ "IIII"
16:51simardI call a static clojure function from java code. On my PC (Linux), it works fine, on another (Windows7), I get this error https://gist.github.com/2199626
16:51devnqbg: :)
16:51muhoo&(cl-format nil "~R" 1976)
16:51lazybot⇒ "one thousand, nine hundred seventy-six"
16:52devn&(cl-format nil "~@R" 1976)
16:52lazybot⇒ "MCMLXXVI"
16:52qbg&(cl-format nil ~:R" 1976)
16:52lazybotjava.lang.RuntimeException: EOF while reading string
16:52qbg&(cl-format nil "~:R" 1976)
16:52lazybot⇒ "one thousand, nine hundred seventy-sixth"
16:52gfredericksomg
16:52simardI tried to add some (println ..) from the top level of the clojure file and it's not working either, which lets me think an error happens at load time, not call time
16:52qbgNever NEVER use format to produce format control strings
16:52gfredericksthat is obscene
16:52qbgYou head will just die
16:52devnyeah. it might make people /angry/ at you
16:53gfredericksI wrote a whole library to convert numbers to words
16:53devnbut if you're ever asked to do the roman numeral kata
16:53devnjust use cl-format ;)
16:53gfrederickshow high does it go though?
16:53devni think roman numerals kick out around 2500
16:53devn&(cl-format nil "~@R" 2500)
16:53lazybot⇒ "MMD"
16:53muhooif someone asks you do do roman numerals,
16:53gfredericksno for the words one
16:53devn&(cl-format nil "~@R" 900)
16:53lazybot⇒ "CM"
16:53qbghttp://www.foldr.org/~michaelw/log/static/programming/lisp/format-automotivator.jpg
16:53devn&(cl-format nil "~@R" 9000)
16:53lazybot⇒ "9,000"
16:53muhoojust tell them to quit screwing around and just give you the damn job
16:54devn&(cl-format nil "~@R" 3400)
16:54lazybot⇒ "MMMCD"
16:54devn&(cl-format nil "~@R" 6500)
16:54lazybot⇒ "6,500"
16:54devnbinary search continues as an exercise for the reader
16:54mk...I still have no idea how to make it draw a table from an arbitrary 2d seq
16:54gfredericks(cl-format nil "~:R" 100000000000000000000000000N)
16:54gfredericks,(cl-format nil "~:R" 100000000000000000000000000N)
16:54clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: cl-format in this context, compiling:(NO_SOURCE_PATH:0)>
16:54gfredericks&(cl-format nil "~:R" 100000000000000000000000000N)
16:54lazybot⇒ "one hundred septillionth"
16:54devn,(use 'clojure.pprint)
16:54clojurebotnil
16:54qbgmk: try (cl-format true "~{~s~%~}" [[1 2 3] [4 5 6] [7 8 9]]) at the repl
16:54muhoo&(class cl-format)
16:54lazybot⇒ clojure.pprint$cl_format
16:54qbgGood enough?
16:55gfredericks&(cl-format nil "~:R" (apply * (repeat 100 10N)))
16:55lazybot⇒ "10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000th"
16:55muhoooh, it's in pprint
16:55gfredericksah ha
16:55gfredericks&(cl-format nil "~:R" (apply * (repeat 50 10N)))
16:55lazybot⇒ "one hundred quindecillionth"
16:56mkqbg: the rows aren't aligned
16:56gfredericksgoes up to but not including 10^66
16:56devn&(print-table [:a :b :c] [{:a 1} {:b 2} {:c 3}])
16:56lazybot⇒ ============ :a | :b | :c ============ 1 | | | 2 | | | 3 ============ nil
16:56devnmk: try that at the repl. is that better?
16:57devnyou may need to turn your data structure into something that print-table wants
16:57muhoo&(cl-format nil "~@R" 420)
16:57lazybot⇒ "CDXX"
16:57tomoj&(cl-format nil "~:R" (apply * (repeat 70 10N)))
16:57lazybot⇒ "10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000th"
16:58gfrederickstomoj: goes up to 65
16:58tomojis the rest, uh.. nameless?
16:58qbg(cl-format true "~{~{~0,5t~s~}~%~}" [[1 2 3] [4 5 6] [7 8 9]])
16:58tomojor is the implementation just incomplete?
16:58qbgHow does that look?
16:58muhoothe yak, it is shaved.
16:58qbg(you'll probably need to modify the 5 to make sense for you
16:58gfrederickstomoj: I think that's as much as most dictionaries traditionally cover exhaustively
16:58Frozenlo`Another newbie question... The result of using `map' is of the form (item1 item2...). Is there a way to make it a map instead?
16:59gfredericksI think up to 10^303 is derivable? sorta...
16:59devntomoj: how many numbers in your dataset are above 65 places?
16:59devn(that you need to print readably)
16:59qbgA bit better: (cl-format true "~{~{~s~0,5t~}~%~}" [[1 2 3] [4 5 6] [7 8 19]])
16:59mkI just want the numbers. Without weird headers, and I don't actually know how many will be in there
16:59gfredericksFrozenlo`: it's not clear what that map would be of -- i.e. what are the keys and the values?
17:00Frozenlo`gfredericks: both are other maps :)
17:00gfredericksdevn: he's just trying to make sure his code is scalable
17:00gfredericksFrozenlo`: maybe zipmap will do what you want? it's still not clear
17:00gfrederickse.g., if you're doing ##(map inc [3 5 183])
17:00lazybot⇒ (4 6 184)
17:01gfrederickshow would we make a map out of that?
17:01mkI suppose I need something to display matricies, rather than tabular data
17:01tmciverI just noticed this cl-format. What ns? I don't have it on my repl.
17:01devn&(partition 2 '(1 2 3 4 5 6 7 8))
17:01lazybot⇒ ((1 2) (3 4) (5 6) (7 8))
17:01devn&(map zipmap (partition 2 '(1 2 3 4 5 6 7 8)))
17:01lazybotclojure.lang.ArityException: Wrong number of args (1) passed to: core$zipmap
17:01qbgDocumentation: http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
17:01qbgtmciver: clojure.pprint
17:01raekFrozenlo`: if you have a sequence of map entries, use (into {} ...), if you have a seq of keys and a seq of values, use (zipmap ...), if you have a seq of alternating keys and vals, use (apply hash-map ...)
17:01tmciverqbg: thanks.
17:02Frozenlo`raek: thanks, trying now.
17:02raek...and a map entry is a vector of two elements
17:03devn&(let [sequence '((1 2) (3 4) (5 6) (7 8)), keys (map first sequence), vals (map second sequence)] (zipmap keys vals))
17:03lazybot⇒ {7 8, 5 6, 3 4, 1 2}
17:03tomojdevn: I don't need cl-format at all, just curious about the names
17:04devntomoj: yeah, if you check out the source it goes to....
17:04devnvigintillion
17:04devnhttp://en.wikipedia.org/wiki/Names_of_large_numbers
17:04devn10^63
17:05tomojlol @ centillion
17:05gfredericksthere's an interesting one mentioned in that article that grows double exponentially I think
17:05gfredericksi.e., gets qualitatively higher on fewer names
17:05devn"some scientists say there may even be larger numbers!"
17:05devn10^303 + 1 ?
17:06gfrederickslol
17:06gfredericks$google 24 is the highest number
17:06lazybot[Mr. Show - 24 is the Highest Number - YouTube] http://www.youtube.com/watch?v=RkP_OGDCLY0
17:07qbgmk: Try something like (cl-format true "~{~{~8@A~}~%~}" [[1 3424 2] [4 5 6] [7 8 19]])
17:08mkqbg: spaces between small numbers are too huge. I'm working on taking the max string length of each column and using that...
17:09qbgmk: Have you thought about using ClojureScript and generating a table element? :p
17:10mkqbg: yeah that'll look great in the repl ;)
17:10qbgVisual repl is the future!
17:10mkqbg: I agree! I hope you're thinking of writing one
17:10devnas long as we're talking about cl-format, i remember thinking this was interesting when i first picked up clojure
17:10devn&(+ (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*) (*)(*))
17:10lazybot⇒ 42
17:10qbgVisual repl is the past! See CLIM
17:11gfredericksdevn: boobs?
17:11devnim ashamed of you, gfredericks
17:11mkhow do I do a double-map? I have a [] of functions
17:11gfrederickswell otherwise you could've done that more compactly
17:12simardrefresh: https://gist.github.com/2199626
17:12devn,(+(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*)(*))
17:12clojurebot42
17:12qbg&(reduce #(map %2 %1) [1 2 3] [inc #(* 2 %) dec])
17:12lazybot⇒ (3 5 7)
17:13gfredericksdevn: I mean mixing (*) and (+)
17:13emezeskednolen: There's no easy way to use a custom clojurescript compiler with cljsbuild. Someone else was asking about that, I think, but I haven't come up with a decent solution yet.
17:13qbgmk: Something like that?
17:13devngfredericks: sure
17:13gfrederickssomewhere I wrote some code that would take a number and output that sort of expression
17:13emezeskednolen: As far as installing cljsbuild locally, you just need to "lein install" from support/ and then plugin/
17:14devngfredericks: ha, i was going to write that this morning, but then thought better of it
17:15devn&(*(+(*)(*)(*)(*)(*)(*))(+(*)(*)(*)(*)(*)(*)(*)))
17:15lazybot⇒ 42
17:15mkqbg: (dec identity inc) (3 4) -> ((2 3)(3 4)(4 5))
17:15gfredericksdevn: my judgment is worse than yours
17:15gfredericksnow I have to try to find it...I hope it wasn't in ruby
17:15devnback in a bit
17:16qbg&((fn [fns coll] (map #(map % cols) fns)) [dec identity inc] [3 4])
17:16lazybotjava.lang.RuntimeException: Unable to resolve symbol: cols in this context
17:16qbg&((fn [fns coll] (map #(map % coll) fns)) [dec identity inc] [3 4])
17:16lazybot⇒ ((2 3) (3 4) (4 5))
17:16gfredericksqbg: maybe (map (apply juxt fns) colls)?
17:18qbggfredericks: I think you'd need to transpose the result
17:19gfrederickshmm
17:19gfrederickscannot find my silly +/* expression code
17:19gfredericksprobably the world is better off for it
17:20qbggfredericks, devn: Sounds like a job for core.logic :)
17:20qbgMaybe
17:20mkqbg: thanks, that seems to work
17:21gfredericksqbg: oh crap that's a great idea
17:21qbgProbably will need cKanren extensions
17:21qbgFor complicated stuff
17:21gfredericksthough there was some number theory involved with trying to keep it small
17:22dnolenemezeske: thanks, actually got it sorted out.
17:25ibdknoxdnolen: nice work on the cljs core.logic stuff! :)
17:30dnolenibdknox: thx! just in time for NYC.js and JSConf :)
17:33emezeskednolen: Oh, wasn't there some bug or something in cljsbuild that you were worried about fixing before JSConf?
17:34emezeskednolen: I remember that coming up, but forgot what it was
17:35dnolenemezeske: nope, I think you're thinking of the :source-path issue :)
17:37emezeskednolen: You were asking about lein2 support, under which the REPLs are broken
17:39emezeskednolen: Are you just going with lein1 for now?
17:41dnolenemezeske: oh yeah, lein2 repl would cool, but it's not critical for me now.
17:46emezeskednolen: Okay, good deal
17:56mkhow can I get the name of a function?
17:56qbg&map
17:56lazybot⇒ #<core$map clojure.core$map@151f412>
17:57mkcan I get just map?
17:57qbg&(.getSimpleName (class map))
17:57lazybot⇒ "core$map"
17:58qbgWould have to do regex from there
17:58yoklovwow, surprisingly drawing this to the canvas is slower than actually running the game
17:58yoklovbut both are absurdly slow.
17:59mkqbg: thanks
17:59ibdknoxyoklov: drawing on the canvas should be pretty quick, depending on what you're drawing
18:00yoklovtext
18:00yoklovmostly
18:00qbgmk: That is only going to make sense for named functions
18:00ibdknoxusing cljs?
18:00yoklovyup
18:01ibdknoxare you doing a loop with doseq or some other such seq mechanism?
18:01yoklovporting code from clojure to cljs. there are performance issues everywhere as it uses lots of persistant datatypes
18:01yoklovyeah
18:01yoklovdoseq
18:01yoklovshould i be doing a loop/recur?
18:01ibdknoxdoseq is *way* too slow
18:01ibdknoxyou can't use seq
18:01ibdknoxs
18:01ibdknoxthat's why money does weird things with arrays :(
18:01ibdknoxmonet*
18:02qbgmk: If you have a var, you could get the symbol from that
18:02yoklovright okay, hm, so what's the canonical way to loop over some range of numbers without using doseq?
18:02yoklovloop/recur?
18:02mkqbg: gotcha
18:02ibdknoxyeah
18:02qbg,(.sym #'map)
18:03clojurebotmap
18:03qbg^ Hack though
18:03ibdknox,(-> #'map meta :name)
18:03clojurebotmap
18:03ibdknoxqbg: ^
18:04qbgIt would be nice if vars were named
18:10yoklovhrm. still pretty slow
18:10clojurebotexcusez-moi
18:10yoklov20 seconds to draw 100 frames
18:10yoklovfrom 22
18:11ibdknoxyoklov: gist?
18:11yoklovhttps://gist.github.com/2200308
18:12qbgIsn't dotimes available?
18:12yoklovtried reversing the iteration in the foolish hope that it would speed it up
18:13yoklovhm. maybe the (set (map :pos monsters)) is slowing it down...
18:13yokloveh there are only ever 6 or so
18:14ibdknoxcan you add the generated js for that function too?
18:14yoklovabsolutely
18:14ibdknoxnothing obvious is jumping out
18:15ibdknoxalso, how are you calling draw?
18:16dnolenyoklov: did you try running the JS profiler (say in Chrome) to see where the time is spent?
18:16yoklovwhen i'm testing the speed it's in a reduce loop, however its still noticably slow when i call it at the end of an event
18:16yoklovyeah
18:16yoklovits in draw
18:16yoklov:/
18:17qbgYou looping through each pixel to see if something is there?
18:17dnolenyoklov: but it's not clear which thing in draw in slowing you down?
18:17qbgeach block that is I guess
18:18yoklovhttps://gist.github.com/2200308 has the generated js
18:18yoklovand as far as the slowness in draw its a lot of anonymous functions
18:19yokloveventually leading to cljs.core.hashmap, actually
18:19yoklov*contains_key. hm.
18:19ibdknoxall the gets
18:20dnolenyoklov: gets are punishingly slow at the moment
18:20yoklovthat would explain it
18:21yoklovand a lot.
18:21dnolenyoklov: you using regular maps right?
18:21ibdknoxyeah he is
18:21dnolenyoklov: way to get massive speedup is to replace the map with you own record with those keys
18:22dnolenyoklov: then you avoid all the avoid of hashing, array copying etc.
18:22yokloverr, so inline the lookup?
18:22yoklovor… what?
18:23yoklovoh like a record type?
18:23ibdknoxyeah, an actual record
18:24dnolenyoklov: yes then you don't need to change the fns.
18:25yoklovwell, that is certainly a hack in this case but i can deal if it offers massive speedup
18:25dnolenyoklov: even in Java you sometimes want to replace map use with defrecord if perf becomes an issue.
18:27yoklovhm. never really had performance issues in java, probably just because i don't do anything that intense
18:31emezeskeHas anyone happened to make Google Closure externs file for RaphaelJS?
18:32emezeskeOr can anyone point me toward documentation on how to make an externs file?
18:36gfredericksemezeske: is there more to extern besides `Raphael`?
18:38emezeskegfredericks: I thought all the member functions, etc, had to be externed. I would love to be wrong...?
18:39gfredericksnot knowing about any of these things too intimately, that would surprise me.
18:41emezeskeWouldn't references in my code to the public methods of the Raphael object be munged?
18:42gfredericksas in Raphael.foo(bar)?
18:42irc2samusguys how do you get an integer from a numeric string?
18:42gfredericks&(Integer/parseInteger "48929854")
18:42lazybotjava.lang.IllegalArgumentException: No matching method: parseInteger
18:42gfrederickshmm
18:42gfrederickswell there's something there
18:42yoklov&(Integer/parseInt "48929854")
18:42lazybot⇒ 48929854
18:42emezeskegfredericks: Yeah
18:42yoklov:p
18:42gfredericksI was going to type that first but decided it looked too javascripty
18:43gfredericksemezeske: is that (Raphael/foo bar)?
18:43yoklovhaha, i only know because i'm in college so most of the code i have to write is in java
18:43gfredericksoh I guess it's JS before it gets munged
18:43gfredericksso Raphael.foo(bar) then
18:43emezeskegfredericks: No, it would be like (.foo (js/Raphael ...) bar)
18:43gfredericksI would think if Raphael is externed then the compiler would pass over an expression with 'Raphael' at the front of it...
18:44irc2samusgreat! is it weird that it doesn't appear on clojuredocs?
18:44gfredericksbut like I said I don't know much about these matters
18:44gfredericksirc2samus: it's pure java, so...not really
18:44gfredericksmaybe unideally
18:44emezeskegfredericks: Well, Raphael/foo would be like a static member access
18:44emezeskegfredericks: Mostly you just create a Raphael object, and then call members
18:45emezeskegfredericks: Which are just object.whatever()
18:45gfredericksoh you mean on the instance
18:45emezeskegfredericks: Yeah
18:45gfredericksso (.foo my-raphale bar)?
18:45emezeskegfredericks: Exaclty
18:45irc2samusohh I see, thanks
18:47gfrederickshmmm; okay, so I guess it'd be hard (impossible) for the compiler to know if my-raphael is a raphael object, so the way that works is e.g. if you extern 'draw' then calling (.draw my-raphael) will not be munged and neither will calling draw on anything else but you don't lose much that way...
18:47gfredericksemezeske: yeah okay you've convinced me
18:48gfredericksdevn: at compiletime or runtime?
18:48emezeskegfredericks: I just got things to compile with using raphael.js as the externs file, but the compiler produces warnings for like 5 minutes before it's done
18:48devngfredericks: runtime
18:48emezeskegfredericks: I guess I just need to strip it down myself :(
18:48gfredericksemezeske: probably a regex could find all the functions declared eh?
18:49emezeskegfredericks: Maybe...
18:49gfredericksdevn: that sounds complicated
18:49gfredericksemezeske: you have a problem, you think "I know, I'll use a regex", and then you use the regex to solve the problem
18:49devnnow you have two problems
18:51gfredericksdevn: that's an old wives' tail
18:52irc2samusok, apologies for the basic question but why do I have to wrap Integer/parseInt on a fn in order to use it with map?
18:52devngfredericks: i just recently re-read joy of clojure (wow, i missed a lot in my haste the first time around, what an incredible book)
18:52gfrederickshm
18:52gfredericksdevn: does it condemn regexes?
18:52gfredericks,Integer/parseInt
18:52clojurebot#<CompilerException java.lang.RuntimeException: Unable to find static field: parseInt in class java.lang.Integer, compiling:(NO_SOURCE_PATH:0)>
18:53irc2samusgot that same error
18:53gfredericksirc2samus: I guess otherwise the syntax would be ambigious between static fields and static methods?
18:53devn"Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems --Jamie Zawinski (aka jwz)
18:53gfredericksdevn: that's what I was playing off of
18:54devngfredericks: they just remark that they're sympathetic to the statement, but that regular expressions can be useful
18:54devni know people who have built really fragile code out of ornate regexen
18:54devnthen again, i use them quite often
18:54gfredericksirc2samus: I can't think of any particular reason, it's probably mixed up in compilers and reflection and performance and all that. But the Foo/bar syntax can only be used in the front of a list, it can't be evaluated by itself and passed around
18:55irc2samusok, good to know thank you
18:55gfredericksdevn: "Some people, when confronted with a problem, think "I know, I'll use an ornate regex to build fragile code." Now they have two problems."
18:56devn:) I was just about to say "I just said that."
18:56devnuntil I noticed
18:56gfredericksirc2samus: I think there might be a macro to do what you're doing a little easier though
18:56amalloythe particular reason is that Integer/parseInt isn't a function
18:56gfredericksamalloy: well it could be compiled into one
18:56amalloyit's a method, which is not a first-class value in java
18:58AimHereAs far as Integer/parseInt is concerned, 'read-string' does turn strings into numbers for you in a more first-class stylee, though it'll turn non-Integer strings into not-integers as well
19:20yoklovso, if I want to get some performance improvements by turning my maps into records, how should i be accessing the fields of those records? (:field a-record) still seems to be very slow
19:21gfredericksyoklov: I think (.field a-record) is the way to do it?
19:21yoklovhrm.
19:23ibdknox(.-field a-record)
19:23yoklovthat's tough. short of (case :field (.field a-record), :otherfield (.otherfield a-record)), i dunno if that's gonna be possible, because just the symbol `namespace/field` will give an error as it doesnt exist… i think
19:25ibdknoxyoklov: huh?
19:25ibdknoxI didn't understand that
19:25ibdknoxas long as a-record is non-nil, everything will be fine
19:25yokloverr, sorry. i have the keyword :field stored somewhere
19:25yoklovi could change that to a symbol and do (. a-record variable-resolving-to-field)
19:25ibdknox(aget a-record wooohoo)
19:25yoklovor… somethign weird? no that makes no sense.
19:26yoklovoh
19:30Lee__New to this irc gizmo... Anyone here who can help with a classpath problem after upgrade to Clojure 1.3?
19:31gfredericks~anyone
19:31clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
19:32Lee__Thx clojurebot.
19:32yoklovblergh. i guess i can't have destructuring if i want that speedup?
19:34amalloyyoklov: you get a noticeable speedup for free just by using records, i think. you get maybe another factor of four for using hinted .foo lookups instead of :foo, but it's highly unlikely that that's your bottleneck anyway
19:34Lee__With clojure 1.2 I was able to launch runs on linux with "java -cp ./*:./src/ clojure.main -i myfile.clj" and it would find required files in the same directory, but this isn't working with clojure 1.3... Anyone know why and/or a fix?
19:34yoklovamalloy: this is in clojurescript, actually
19:36yoklovand i'm pretty sure it's my bottleneck because chrome's profiler says that it's in hash_key_exists_QMARK_ or something like that
19:36gfredericksLee__: any particular reason you're not using leiningen?
19:36ibdknoxyoklov: correct
19:37ibdknoxamalloy: in CLJS that could easily be the bottleneck :(
19:37gfredericksibdknox: because keywords are strings?
19:38ibdknoxarguments is orders of magnitude slower :(
19:38gfredericksoh
19:38yoklovso hm
19:38Lee__gfredricks: I do use leiningen in other contexts, but for doing remote runs on a cluster I've just been using that java call... I guess one reason is that I actually throw more java options in the call, e.g. for parallel garbage collection on a 48 core node... Maybe I can do that with lein calls too? I just didn't ever bother to figure that out because this worked (before).
19:39yoklovi guess my best bet is to start rewriting this to pass more args separately and use more js arrays?
19:39gfredericksLee__: okay that question is beyond me I think; hopefully someone else knows
20:00Lee__More generally: what changed between 1.2 and 1.3 re: how the classpath is searched? I've been unable to find any docs on this. With 1.2 I can launch java with "-cp ./*:" and it finds any required files in the launching directory, but not so with 1.3...
20:05mkLee__: many people use lein, and things tend to just work
20:05mk...but I see that this was already suggested above
21:08dnolenyoklov: I feel your pain.
21:09yoklovhaha
21:09dnolenyoklov: in core.logic I was well aware of the problems and avoided using anything map or record related.
21:09yoklovi actually just sped it up a bunch by calling name on a bunch of keywords and then using them in agets for the record types
21:10yoklovwhat did you use instead?
21:10dnolenyoklov: in Clojure I used a map - it's ridiculously fast, but for core.logic in CLJS I switched back to lists which is what the original Scheme used.
21:11yoklovoh right
21:12yoklovreally my only really huge slowdowns are in the set-heavy areas of my code and in "draw", which accesses tons and tons of maps
21:12yoklovor keys in maps, rather
21:13devnLee__: What blows up with 1.3??
21:13lazybotdevn: Definitely not.
21:14devnLee__: As in, do you have a specific error? (If it's more than a line long please post it to a pastebin or gist.github.com)
21:17dnolenyoklov: k I looked into, there's something seriously wrong with record
21:17dnolenyoklov: well, a I looked into a little
21:18yoklovoh?
21:18dnolenyoklov: if I make a type and I implement only the single arg -ilookup, 10000 lookups takes 8
21:18dnolenwhich is reasonable
21:18dnolenyoklov: if I use a record, 10000 lookups take 330ms which is not
21:18yoklovoh okay
21:19yoklovthats interesting
21:22dnolenyoklov: arg, I see why
21:23dnolenyoklov: the implementation of -ilookup for defrecord doesn't first check to see if it's one of the field keys with a cond/condp
21:23dnolenyoklov: opening up a ticket, simple fix, I'll try to get to it this week
21:23yoklovso checking it would be faster?
21:23dnolenyoklov: near 40X faster or something.
21:24yoklovwow
21:24yoklovthat is somewhat unintuitive, wouldnt more checks slow it down?
21:24dnolenyoklov: if/else cascades are quite fast in JS
21:25yoklovright, but what is it otherwise? a thrown exception?
21:25dnolenyoklov: no, nil
21:25dnolenjust like maps
21:25yoklovand that's necessarially slower?
21:26dnolenwhat's slower?
21:27yoklovOH, i misread what you said above
21:27yoklovor misunderstood what the alternative to it being a field key is
21:27dnolen(get (merge (hash-map ~@(mapcat (fn [fld] [(keyword fld) fld]) base-fields)) ~'__extmap) k# else#)
21:27dnolenis the current implementation
21:27dnolenyes that is a hash-map merge for every lookup
21:28yoklovalright that makes sense
21:28yoklovyeah i forgot records could also contain arbitrary keys
21:29dnolenyoklov: I'm going to change that to cond/p + ext-map lookup for else clause.
21:29yoklovas i said, i've been working around this by doing (aget record (name field)) when possible, which has been working
21:29yokloveven if it is a ugly hack
21:39Lee__devn: I no longer have the text of the error (it was the standard one about not being able to find a required file on the classpath) BUT I have solved it, by adding "$PWD:" to the start of the classpath in the java call. Whew. Thanks for the attention.
21:40devnLee__: glad you figured it out. I'm so used to using leiningen I feel like I've lost some of the classpath foo that used to be required.
21:41devndnolen: did i see a bunch of protocol additions in clojurescript?
21:42dnolendevn: ?
21:42devndnolen: nevermind, i might be thinking of a different project (probably clojure-scheme)
21:43gtuckerkelloggis lein-bin compatible yet with lein v2?
21:43devnRaynes: see above message
21:43RaynesYikes. I forgot I even wrote that.
21:43RaynesNo, it isn't, but it wouldn't be hard at all to update it.
21:43RaynesI didn't realize people actually used it or I would have already done it.
21:45gtuckerkelloggYep, it gets used
21:46dnolenyoklov: fixed in master
21:47yoklovwow, that was fast
21:47gtuckerkelloggdamn
21:50devnnow entering dnolen country...
21:51devnbest part is, he's also really good at explaining things
21:51devn(or worst part if you're jealous of his drunken master style)
21:52yoklovyup. extremely impressive.
21:53devni'm talking about him while i'm in here so he'll either ignore me humbly, or say "aw, 'twas nothing", but david has kept the clojurescript train moving like a boss
21:53devneveryone should send him gifts
21:54devn(inc dnolen)
21:54lazybot⇒ 5
21:58RaynesDamn it.
21:59Raynesdevn: That sucks. I just updated and released lein-bin 0.2.0 for that guy and he leaves. :(
21:59RaynesI just wasted a whole 4 minutes.
22:00dnolenibdknox: actually I'm not so sure any more, I may have been thrown off by benching defrecord once or something.
22:00dnolenibdknox: arguments performance hit is more like 2X, still that's pretty pervasive
22:04devnRaynes: <3
22:04devnRaynes: he saw you were on the case
22:04devnand since i'm handing out thank yous, thanks Raynes for maintaining the hell out of all of your projects
22:05devnyou're a boss.
22:05RaynesYay! Bossness!
22:06devnim a little scared about speaking -- the last slot and everything, yeesh.
22:07RaynesWish I could be there to see it.
22:14technomancydevn: last slot is a drag =\
22:25Raynestechnomancy: So is the 3rd.
22:29mkwhat is subseq supposed to do? ##(doc subseq)
22:29lazybot⇒ "([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
22:31mkwhat's it supposed to be used for?
22:42devntechnomancy: i think it'll be okay. it's not patently technical, and i have a feeling (given the conf ends on a friday night) that it won't be the "last" "session"
22:49MGThey, does anyone know what's going on here? I import clojure.string as string and do (replace "a" #"a" "\\"), then get an error instead of a string containing a forward-slash character
22:49MGTerr, should be (string/replace "a" #"a" "\\")
22:49devnyou mean require?
22:49MGTyes
22:50xeqi&(string/replace "a" #"a" "\\")
22:50lazybotjava.lang.RuntimeException: No such namespace: string
22:50xeqi&(clojure.string/replace "a" #"a" "\\")
22:50lazybotjava.lang.StringIndexOutOfBoundsException: String index out of range: 1
22:51MGTyep
22:52devn&(clojure.string/replace "a" #"a" "\\\\")
22:52lazybot⇒ "\\"
22:52devnnot what you want, I take it?
22:53MGTI don't think so
22:53devnyou're trying to replace with just "\", yes?
22:53MGTwell, I guess it is, actually
22:53MGTyes
22:53MGTthanks, think I understand now!
22:55devn&(s/replace "foo" #"f" "\\\\")
22:55lazybot⇒ "\\oo"
22:56devn&(seq (s/replace "foo" #"f" "\\\\"))
22:56lazybot⇒ (\\ \o \o)
22:57devnit's a bit long -- sort of like when you're lost and you turn around before you get to your destination
22:57devnthe required additional \\ is kind of like that IMO
22:58holohi
22:58MGTyeah, makes sense
22:58amalloythere is at least one open ticket about that in jira, mgt/devn
23:00alex_baranoskyis there anyway to pretty print (quote foo) as 'foo ?
23:10mkalex_baranosky: what would the function take as an argument? a single form?
23:14dnolen_yoklov: gotta run but that sounds good.
23:14rhcwhat's a good way in clojure to run a function after some period of time?
23:14rhc(future ((sleep ..) (do-function))
23:15Raynes(.start (Thread. (fn [] (Thread/sleep 2000) (somefunction))))
23:15RaynesI wouldn't use future for this.
23:15rhcRaynes: thanks
23:16rhcso its generally better to use regular java threading over future when you don't care about the result?
23:16Raynesfuture contains any exceptions that occur in its body. They don't pop up until you actually try to use the value of the future. Unless you actually want the value, I'd avoid it.
23:16RaynesRight.
23:16mkwhy not use an agent?
23:17RaynesWhy not just sleep 2h && echo "foo"
23:17Raynes;)
23:18rhcmk: hmm, i'll look into that too, thanks
23:18mkit's strange to call java for something as common as "now start doing this in another thread"
23:19mkany suggestions for good talks to watch?
23:57devnrhc: look at at-at
23:57devnrhc: https://github.com/overtone/at-at