2011-04-22
| 04:26 | alekx | (let [v [1 2 3] (get v -2) (nth v -2)) ; get => nth in IndexOutOfBounds |
| 04:26 | alekx | Is that ok? |
| 04:27 | alekx | sorry, question is get using a negative index results in nil, while nth w/ negative index results in IndexOutOfBounds |
| 04:28 | fliebel | alekx: I still see no question, but that is expected. try (get v −2 :blah) |
| 04:28 | alekx | fliebel: I was wondering about the difference in behavior |
| 04:29 | alekx | both nth and get support the "missing value" |
| 04:29 | fliebel | &(doc nth) |
| 04:29 | sexpbot | ⟹ "([coll index] [coll index not-found]); Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences." |
| 04:29 | alekx | (nth [] -2 "missing"_ |
| 04:30 | alekx | Is there a way to get the second to last element from a vector/sequence? |
| 04:30 | fliebel | alekx: vector or sequence? |
| 04:30 | alekx | some langs support negative indexes for doing that; I'm wondering if a similar idiom exists in clojure |
| 04:31 | alekx | let's start with vector |
| 04:31 | alekx | :D |
| 04:31 | fliebel | Not that I know, you could do (- length 2) though, or do (last (drop-last 2)) |
| 04:31 | fliebel | or (nth 2 (rseq)) |
| 04:32 | fliebel | or structure your data so that you don't need to do that, because it is inefficient. |
| 04:32 | fliebel | vectors can do disj though. |
| 04:33 | fliebel | (peek [1 2 3]) |
| 04:33 | alekx | &(doc disj) |
| 04:33 | sexpbot | ⟹ "([set] [set key] [set key & ks]); disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)." |
| 04:33 | fliebel | or what… let mee see. |
| 04:33 | fliebel | no, you want peek and pop. |
| 04:33 | fliebel | for a vector they work a the end, for a persistenqueue they work at the start. |
| 04:34 | alekx | thnks. I'll look into all these one by one :) |
| 04:35 | fliebel | So since nth is actually just (first (rest (rest… you'd do (peek (pop (pop.... |
| 04:36 | fliebel | But vectors are counted and support numerical indexes really fast, so (- (lenth) 2) is probably faster. |
| 04:37 | alekx | it definitely needs to be index based |
| 04:37 | alekx | that's the whole idea |
| 04:38 | alekx | so probably the length approach is the one to use |
| 04:38 | fliebel | &(source nth) |
| 04:38 | sexpbot | java.lang.Exception: Unable to resolve symbol: source in this context |
| 04:38 | alekx | or someone could implement a new nth that behaves this way |
| 05:33 | fliebel | What would be the Clojure way of doing this? Killing threads does not really sound like a good idea. http://stackoverflow.com/questions/5378391/closing-a-blocking-queue |
| 07:54 | raek | fliebel: interrupting a thread is not the same as calling .stop on it |
| 07:56 | raek | an interrupt merely suggests the thread to stop what it's doing, but is not guaranteed to have any effect (it's up to the thread) |
| 07:58 | raek | also, I would recommend reading the chapter "Cancellation and Shutdown" of Java Concurrency in Practice. it explains all this really well |
| 07:59 | fliebel | raek: OKay, thanks. I don't own the book though. |
| 07:59 | raek | you might also find the "Shutdown with poison pill" example useful http://www.javaconcurrencyinpractice.com/listings/IndexingService.java |
| 07:59 | raek | I've borrowed it from the uni library... :) |
| 08:00 | fliebel | I'm not in uni either. |
| 08:02 | fliebel | raek: Do you know anything about pods? I thought they where going to be for this kind of Java stuff in Clojure. |
| 08:02 | raek | nope... :-) |
| 08:02 | raek | fliebel: I did something similar in clojure a while ago: https://github.com/raek/stream-seq |
| 08:03 | raek | https://github.com/raek/stream-seq/blob/master/src/se/raek/stream_seq.clj#L123 |
| 08:04 | fliebel | okay, locking… |
| 08:04 | raek | the project has an implementation of a "closable" blocking queue |
| 08:04 | raek | it uses locks and stuff, so it's not very pretty |
| 08:05 | raek | the locks are mainly there to keep producers from putting stuff in the queue when it has been closed |
| 08:06 | fliebel | raek: Thanks for that code, it seems to contain a lot of stuff I might need. |
| 08:08 | fliebel | The trouble with seque is that it must really support any BlockingQueue. Especially SunchronousQueue is problematic with locking. |
| 08:12 | fliebel | So 1) I can't lock the actual queue, because for SynchronousQueue that means a deadlock. 2) I can't insert a plug, because for PriorityBlockingQueue that means NPE. |
| 08:13 | fliebel | I'm going to do some hamocking outside to cook something up. |
| 08:32 | raek | fliebel: can't you use an (Object.) as the "plug"/"poison pill"? |
| 08:33 | fliebel | raek: What is the priority of an object? |
| 08:34 | raek | oh, missed the Priority- there :) |
| 08:35 | raek | hamocking sounds like a good plan |
| 08:35 | fliebel | :) |
| 09:09 | fliebel | raek: interrupting *was* in fact a working solution :) |
| 09:10 | ambrosebs | is there any way to extract the type hint of an argument? |
| 09:10 | ambrosebs | say I want to know this symbol was hinted to be Integer |
| 09:10 | ambrosebs | (foo ^Integer 'a) |
| 09:10 | fliebel | (:tag (meta x)) I think. |
| 09:11 | fliebel | &(:tag (meta ^Integer [])) |
| 09:11 | sexpbot | ⟹ nil |
| 09:11 | fliebel | uuhm, what? In my repl that works. |
| 09:11 | fliebel | &(meta ^Integer []) |
| 09:11 | sexpbot | ⟹ nil |
| 09:11 | fliebel | (dec sexpbot) |
| 09:11 | sexpbot | ⟹ -1 |
| 09:11 | ambrosebs | doesn't seem to work for me either |
| 09:12 | fliebel | &(meta ^:blah []) |
| 09:12 | sexpbot | ⟹ nil |
| 09:16 | raek | ambrosebs: the type hints are on the data stucture that is sent to the evaluator |
| 09:16 | raek | ambrosebs: so you need to look at those before they get evaluated, i.e. you need to do it in a macro |
| 09:16 | ambrosebs | ah this makes sense |
| 09:18 | ambrosebs | Im not sure if I can use a macro in my situation |
| 09:19 | raek | I recall that the "defstrict" exercise of Labrepl uses the type hints to add runtime type checks |
| 09:19 | ambrosebs | yes i remember that too now |
| 09:20 | ambrosebs | I'm using pallet to generate Bash script .. I'm nested inside the "script" wrapper function, so I'm not exactly in clojureland |
| 09:21 | ambrosebs | I think i'll have to take a different strategy |
| 09:37 | _Vi | How to have a JComboBox that selects keywords from a set? Should I use a map from keyword to combobox's item index? |
| 10:02 | fliebel | What a beautiful error! java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: |
| 10:03 | fliebel | Now, how can I tell clojure.test that I don't care about the type of exception? |
| 10:04 | stuartsierra | fliebel: you mean test for any exception? |
| 10:05 | fliebel | stuartsierra: Well, what I mean is that the type of exception seems to depend on my implementation. So I guess that what I actually want is the original exception. |
| 10:06 | stuartsierra | There's an example in the tests for clojure the language to get the root cause of an exception. |
| 10:06 | stuartsierra | but you may just want `(thrown? Throwable ...)` |
| 10:07 | fliebel | stuartsierra: Well, I put Exception in there, but then it did not work when it was a RuntimeException. Is Trowable any different? |
| 10:07 | stuartsierra | Yes. Throwable is the parent of all exception types. |
| 10:08 | stuartsierra | although Exception is also the parent of RuntimeException. |
| 10:08 | fliebel | stuartsierra: right, that is what I thought, but it seems to work anyway. :) thanks |
| 10:08 | stuartsierra | 'welcome :) |
| 10:10 | fliebel | :( still locks itself up from time to time... |
| 10:11 | stuartsierra | It's possible the exception is happening outside the scope of your `is` assertion or `deftest`, due to timing / concurrency issues. |
| 10:11 | fliebel | stuartsierra: Nah, the test is working now, btu I'm using interrupt to get out of the .take when I'm done, but it seems to miss that sometimes. |
| 10:12 | stuartsierra | Thread.interrupt? |
| 10:12 | fliebel | yea |
| 10:12 | stuartsierra | Well, there's your problem. :) |
| 10:12 | fliebel | why? |
| 10:12 | clojurebot | why not? |
| 10:12 | Kerris | ahahah clojurebot |
| 10:13 | Bronsa | lol |
| 10:13 | stuartsierra | The behavior of Thread.interrupt is complex. |
| 10:14 | stuartsierra | If you need to wait for something to complete, you're probably better off with something like a CountDownLatch. |
| 10:15 | fliebel | stuartsierra: Sounds like it's time based? |
| 10:15 | stuartsierra | CountDownLatch isn't time based. It's like a semaphore. |
| 10:15 | stuartsierra | Clojure's promises use them. |
| 10:16 | fliebel | stuartsierra: Oh! I'll check that out. (it's for this one https://gist.github.com/934781 ) |
| 10:17 | dnolen | interesting, Java 7 book that covers using Scala/Clojure http://www.java7developer.com/ |
| 10:20 | fliebel | stuartsierra: What is complex about interrupting? |
| 10:20 | stuartsierra | I don't understand it. Ergo, it must be complex. |
| 10:20 | thorwil | is there a straightforward approach or library for reversible text transformations? (specify transformation from format A to B, handle he other direction implicitly)? |
| 10:21 | fliebel | thorwil: Boomerang, or Logos, if you try really hard. |
| 10:22 | fliebel | http://www.seas.upenn.edu/~harmony/ |
| 10:23 | thorwil | actually, i recall reading a bit about boomerang. but "straigtforward" in this context would start with available from/in clojure |
| 10:23 | fliebel | stuartsierra: This sounds interesting: http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html |
| 10:23 | stuartsierra | Yeah, Goetz is a smart guy. |
| 10:24 | cemerick | fliebel: it has a lot of the same characteristics of locks that make them hard to use properly as well |
| 10:25 | fliebel | cemerick: Well, while I'm already mutating stuff all the way though, it doesn't really matter, since it's complex anyway. It makes me respect Clojure all the more, though :) |
| 11:15 | sritchie | hey all, I was wondering if anyone had any advice on this function -- https://gist.github.com/936857 |
| 11:15 | sritchie | this is the structure of a cascalog aggregator -- tuples is a sequence of (index, val) pairs |
| 11:16 | sritchie | essentially, I'm filling in a sparse vector by associng values in place -- I sort of feel like this bashing in place isn't idiomatic |
| 11:22 | Chousuke | sritchie: I'm having a hard time figuring out what that function even does :/ |
| 11:24 | sritchie | Chousuke: sorry! should have had an example. I start with a vector of 0s, of some length "width". This is fed into a function composed of a bunch of smaller "assoc" functions -- each of this does one of the replacements required by cascalog |
| 11:25 | Chousuke | are the tuples in index order? |
| 11:25 | Chousuke | then you could build a lazy sequence of items and call vec on that. |
| 11:26 | Chousuke | if not, it's a bit trickier. |
| 11:26 | sritchie | Chousuke: yeah, some of the spots are going to be missing |
| 11:26 | sritchie | they will be ordered, though |
| 11:27 | sritchie | ,((fn [width tuples] [(vector ((apply comp (for [tup tuples] (fn [v] (apply assoc (vec v) tup)))) (repeat width 0)))]) 5 '((0 1) (4 2))) |
| 11:27 | clojurebot | [[[1 0 0 0 2]]] |
| 11:27 | sritchie | (cascalog needs all that extra nesting) |
| 11:27 | sritchie | ,((fn [width tuples] [((apply comp (for [tup tuples] (fn [v] (apply assoc (vec v) tup)))) (repeat width 0))]) 5 '((0 1) (4 2))) |
| 11:27 | clojurebot | [[1 0 0 0 2]] |
| 11:28 | Chousuke | well then you can do something that goes through the tuples one by one, returning the value in it if the index is right, and returning a padding value instead if not (and incrementing an interal index counter) |
| 11:28 | Chousuke | lazily |
| 11:29 | Chousuke | and then just call vec on the result of that, to get a vector of it |
| 11:31 | sritchie | Chousuke: hmm, let me think about that one |
| 11:32 | sritchie | in this example, after looking at (0 1), the function would need to return three padding values -- I wonder if (partition 2 1 tuples) would help, so the function could look at consecutive pairs of tuples? |
| 11:32 | Chousuke | I don't think it has to be like that |
| 11:33 | Chousuke | it can just look at the first tuple, and if its index is not equal to the counter index, then return a padding value and recurse with an increased counter |
| 11:33 | Chousuke | if it is, then recurse with the rest of the tuples and an increased counter |
| 11:33 | Chousuke | until you run out of tuples |
| 11:35 | sritchie | trying that out |
| 11:38 | thorwil | I need to apply a function to the content of a text class. constructed as (def txt (ds/as-text "Foo")) prints as #<Text <Text: Foo>> |
| 11:39 | thorwil | simply converting to a string includes the Text label and the content might e longer than 500 characters |
| 11:44 | thorwil | nm, looks like .getValue is the solution |
| 11:52 | sritchie | Chousuke: https://gist.github.com/936857 |
| 11:52 | sritchie | there's a first try... it's a lot faster |
| 11:55 | ilyak | hi * |
| 11:55 | ilyak | Is is possible to somehow recur into current function and not into loop |
| 11:56 | ilyak | Because otherwise you get three variables: initial-list, current-list and rest-list |
| 11:56 | ilyak | It's easy to make a mistake |
| 11:59 | Chousuke | sritchie: you could make it use a lazy seq too, though it's probably a bit more complicated than that. |
| 11:59 | manutter | ilyak: what is the context of your question? Do you have any example code? |
| 11:59 | Chousuke | sritchie: actually |
| 11:59 | Chousuke | sritchie: never mind. calling vec on that thing is pointless, it's already a vector :D |
| 12:00 | Chousuke | sritchie: if your sparse vectors are going to be large, try using a transient too |
| 12:03 | sritchie | Chousuke: that's smoking fast |
| 12:03 | sritchie | Chousuke: any comments on the way the function's written? |
| 12:15 | ilyak | manutter: Yeah, I'll paste |
| 12:16 | ilyak | manutter: http://pastebin.com/iphLptVW - this is haskell-style stateful iteration |
| 12:16 | ilyak | Maybe I should make cache transient and use for instead of loop? |
| 12:18 | Chousuke | transient? why. |
| 12:18 | Chousuke | and don't forget for is lazy |
| 12:18 | ilyak | How would I write it without repeating downloads three times |
| 12:19 | ilyak | Oh, I'd unlazy it after |
| 12:19 | ilyak | and, preferably, transferring cache implicitly not explicitly (too wordy) |
| 12:19 | dnolen | ilyak: you can recur to the current fn. |
| 12:19 | ilyak | Even if it's defn-ed? |
| 12:20 | ilyak | Maybe I should try memoizing find-best-major |
| 12:20 | dnolen | ilyak: yes, fns also support multiple arity, so you can make a second fn that takes the initial values. |
| 12:21 | ilyak | Does clojure have some sort of memoize in core? |
| 12:22 | dnolen | ,(doc memoize) |
| 12:22 | clojurebot | "([f]); Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use." |
| 12:23 | ilyak | cool |
| 12:24 | TimMc | ilyak: Just be careful what you memoize, of course -- there's no clean way to clear the memoization cache. |
| 12:25 | ilyak | Well, it would be garbage collected won't it |
| 12:25 | ilyak | Is there a reasonable way to make with-open work with a map of something to closeable? |
| 12:26 | ilyak | i.e. close everything it finds there |
| 12:26 | TimMc | ilyak: If you drop all references to the memoized function, yeah. |
| 12:26 | ilyak | TimMc: It won't escape that function |
| 12:27 | dnolen | ilyak: which is the proper way to use memoize. |
| 12:29 | dnolen | http://lambda-the-ultimate.org/node/4260 |
| 12:30 | dnolen | "Clojure (roughly an untyped version of Haskell using LISP notation)" |
| 12:30 | hiredman | heh |
| 12:31 | ilyak | Wow |
| 12:31 | ilyak | It's even faster when I recur to defn |
| 12:46 | thorwil | i have a problem with http://paste.pocoo.org/show/376416/ , where the effect if more isn't specified, it should be as if there was nothing at all @more. otherwise more will be a single function |
| 12:49 | fliebel | thorwil: What is in @more? |
| 12:51 | thorwil | fliebel: as things are, the @ marks my intention. it's meant to be an optional function |
| 12:52 | amalloy | *baffled* |
| 12:52 | fliebel | thorwil: So why do you write & more? then it's at least a seq of an optional function. |
| 12:53 | fliebel | thorwil: Write it as a multi-arg fn then, whre the [] version calls the other one with a default function, or identity. |
| 12:54 | thorwil | retrieve-article* is to be used like: (def retrieve-article (retrieve-article*)) or (def retrieve-article-for-editing (retrieve-article* de-paragraphify)) |
| 12:54 | fliebel | http://paste.pocoo.org/show/376424/ |
| 12:54 | thorwil | if this seems needlessly convulted ... i'm trying to raise my understanding of funcions that return functions as alternative to macros ;) |
| 12:55 | fliebel | thorwil: ^^ |
| 12:55 | ilyak | For some reason replacing loop/cache with memoize made it slower |
| 12:56 | fliebel | ilyak: If the memoized fn is cheap, yes, it'll be slower, as it needs to look up the value every time. |
| 12:57 | ilyak | It seems expensive to me |
| 12:57 | thorwil | fliebel: wow, your version gives me new insight, thanks! |
| 12:57 | ilyak | I'll try it without memoize at all |
| 12:57 | fliebel | ilyak: Note that I have no idea what you're doing. |
| 12:59 | fliebel | thorwil: you're welcome :) I could use some insights as well though :( Still rewriting seque. |
| 13:00 | ilyak | fliebel: Sadly, my code without my data won't make any sense |
| 13:00 | ilyak | And data weight several gigs |
| 13:00 | ilyak | and are confidential |
| 13:01 | fliebel | ilyak: I guess the minimal mockup to make it run is less than that, but as you wish. |
| 13:11 | devn | heya fliebel |
| 13:11 | devn | amalloy: im here! |
| 13:11 | amalloy | devn: haha |
| 13:12 | amalloy | i was actually just demonstrating how $seen works |
| 13:12 | devn | I feel so used :( |
| 13:12 | amalloy | aw, poor devn |
| 13:12 | amalloy | devn: want to join the 4clojure.com team? |
| 13:13 | amalloy | since you're lonely and you hang out in #sexpbot already |
| 13:13 | devn | do i have to do anything? |
| 13:14 | devn | amalloy: just saw the page. hell yes i want to join. |
| 13:15 | amalloy | devn: we're planning to release 0.1.0 today; finishing up the last feature planned for the release. have a look at the issues page and see if there's anything that interests you |
| 13:15 | ilyak | My program in js/rhino runs 3,7 times faster than the same program in clojure |
| 13:16 | ilyak | I wonder if I would get the parity |
| 13:17 | Raynes | drewr: Ping. |
| 13:18 | Raynes | drewr: Nevermind. Found what I was looking for. ;) |
| 13:20 | ilyak | Without memoization it's crippling slow. |
| 13:24 | dnolen | ilyak: is the algorithm significantly different from the js/rhino version? |
| 13:25 | peteriserins | to anyone from 4clojure: am I supposed to star the gists that I want to remember? |
| 13:25 | ilyak | dnolen: I guess not, except that obviously clojure version is more fp |
| 13:25 | ilyak | I can paste both if you bother |
| 13:25 | ilyak | They're loke 200 line each |
| 13:25 | ilyak | like* |
| 13:27 | dnolen | ilyak: which function seems the slowest? |
| 13:28 | ilyak | non-memoized version is four times slower than memoized one |
| 13:28 | abedra | stuartsierra, hey can you jump on skype? |
| 13:28 | dnolen | ilyak: are you memoizing that fn in js? |
| 13:28 | ilyak | sure |
| 13:30 | ilyak | The program does the following: reads four presorted file and calculates some things over records it read and writes to files |
| 13:31 | dnolen | ilyak: how long exactly does the js program version take and the clojure version take? |
| 13:31 | ilyak | js program does 270 ids per second (one master file line per multiple (0-100000) lines of other files |
| 13:31 | ilyak | clojure program does 70 |
| 13:32 | bulters | gday all. |
| 13:32 | ilyak | It's possible that I do some extra work in clojure version, e.g. parse some things eagerly |
| 13:32 | edw | Good afternoon. (GMT-5) |
| 13:34 | dnolen | ilyak: paste the source, js and clojure, not saying I'll see anything, but I'm skeptical that the clojure version can't be made significantly faster than a rhino/js program. |
| 13:34 | bulters | it's one of the awkward things I always experience on irc. |
| 13:35 | bulters | I'd like to say hi (perhaps thats an option), but good evening is - in most cases - only applicable to a small subset of users. |
| 13:35 | amalloy | ugt? |
| 13:35 | clojurebot | ugt is Universal Greeting Time: http://www.total-knowledge.com/~ilya/mips/ugt.html |
| 13:36 | bulters | thanks |
| 13:36 | amalloy | that said, if everyone greeted everyone who joined the channel, there'd be no room for meaningful conversation |
| 13:37 | amalloy | so it's pretty common on irc to not waste breath on hellos |
| 13:37 | bulters | amalloy: could be, i don't expect a full "hi newbie, nice you're back; anymore questions?" from anyone... |
| 13:38 | bulters | but for some reason i find joy in a short polite hi |
| 13:38 | amalloy | bulters: well, feel free |
| 13:38 | amalloy | it's not offensive or anything |
| 13:38 | bulters | amalloy: as I just did ;-) and no offense is taken at all... |
| 13:38 | amalloy | heh |
| 13:39 | bulters | as soon as nobody gets hurt ;-) |
| 13:39 | bulters | long** |
| 13:39 | ilyak | dnolen: clj version http://pastebin.com/E1KBiEKX |
| 13:40 | ilyak | dnolen: js version http://pastebin.com/5F1BMFqe |
| 13:40 | dnolen | ilyak: already see the problem. You need type-hints. That code'll hit crazy amounts of reflection. You'll probably see a 10X speed boost just by adding them. |
| 13:40 | ilyak | it's really lame before it was written in hurry |
| 13:41 | ilyak | dnolen: What to read about that? |
| 13:41 | aredington | @ilyak: http://clojure.org/java_interop#Java%20Interop-Type%20Hints |
| 13:41 | dnolen | ilyak: you can't just call Java methods like that and expect the code to be fast. the compiler doesn't know the types. |
| 13:43 | ilyak | So I should only do that when I call Java? |
| 13:44 | dnolen | ilyak: when performance matters yes, type-hinting is for dealing with Java (or primitive math in 1.2.0) |
| 13:46 | aredington | ilyak: If you (def *warn-on-reflection* true) you'll be told every time that clojure's having to use reflection to correctly type things, those are good candidates for type hinting as an optimization |
| 13:46 | ilyak | aredington: Did that |
| 13:46 | ilyak | Wow |
| 13:46 | dnolen | ilyak: aredington: (set! *warn-on-reflection* true) |
| 13:46 | ilyak | It switched gears obviously when I added three hints |
| 13:47 | dnolen | ilyak: like I said, a clojure being slower than rhino/js sounded outrageous to me :) |
| 13:47 | fliebel | heya devn |
| 13:48 | ilyak | dnolen: Can you help me setting some non-obvious hints? |
| 13:49 | ilyak | dnolen: Basically I need to tell clj that (:stop right), (:start right) and date are LocalDates |
| 13:49 | ilyak | and (:major right) is String |
| 13:49 | ilyak | Where do I put those? |
| 13:50 | dnolen | ilyak: line 25, 28, 31 all those need hints. I don't have time at the moment to point out each one unfortunately. |
| 13:51 | TimMc | ilyak: ^LocalDate foo tells the compiler that foo evaluates to a LocalDate. |
| 13:52 | ilyak | One sec, I'll paste a fresh version |
| 13:52 | edw | Is there any way to dynamically add project dependencies without re-starting Clojure? |
| 13:52 | amalloy | TimMc: i think dnolen is right though, he wants to put hints in the function params |
| 13:52 | amalloy | edw: no |
| 13:52 | edw | That is a downer. |
| 13:52 | TimMc | amalloy: Not having seen the code... probably. |
| 13:52 | edw | But thank you. |
| 13:52 | stuartsierra | edw: Kind of a fact of JVM life, unfortunately. |
| 13:53 | ilyak | dnolen: http://pastebin.com/NR2KY3y3 |
| 13:53 | ilyak | TimMc: |
| 13:53 | edw | I'd like to see (require '(lamina "0.4.0-SNAPSHOT")). |
| 13:53 | ilyak | How do I do a type hint on return type? |
| 13:54 | fliebel | Is there anyone around who eats Java concurrency for lunch? I have some code that *should* to all my understanding work, but hangs 1/100 times. https://gist.github.com/934781 Related Java code: http://stackoverflow.com/questions/5378391/closing-a-blocking-queue |
| 13:54 | dnolen | ilyak: (defn ^String foo [] ....) |
| 13:54 | TimMc | ilyak: Line 39, you probably want [^String string] for the arguments. |
| 13:55 | TimMc | Or wait... Integer/parseInt might not need that since there's no ambiguity. |
| 13:55 | ilyak | TimMc: Nope, it figured it out (does not complain) |
| 13:55 | TimMc | OK, cool. |
| 13:55 | dnolen | ilyak: rule of thumb, if your Clojure code isn't between 1X-4X of Java, something is wrong. |
| 13:56 | TimMc | dnolen: That reminds me, I need to do some performance analysis on my rasterizer. |
| 13:56 | TimMc | It was super slow compared to Java. I blame the lack of primitive-passing. |
| 13:56 | TimMc | (Clearly, it can't be my own fault... :-P) |
| 13:56 | amalloy | dnolen: well. if you *want* it to be close to java and it's not close, something is wrong. if you're putting together a program where elegance and/or ease of development is more important i wouldn't say something is wrong |
| 13:57 | stuartsierra | A thought: algorithms designed to be efficient with mutable data cannot be implemented efficiently with immutable data, and vice-versa. Discuss. |
| 13:57 | dnolen | stuartsierra: which is why I want Pods. |
| 13:57 | chouser | s/cannot/cannot always/ and I'm good to go |
| 13:58 | stuartsierra | s/cannot/can rarely/ |
| 13:58 | sexpbot | <stuartsierra> A thought: algorithms designed to be efficient with mutable data can rarely be implemented efficiently with immutable data, and vice-versa. Discuss. |
| 13:58 | ilyak | dnolen: How do I help it with write-next? |
| 13:58 | chouser | that'll do nicely. :-) |
| 13:58 | ilyak | ehm .writeNext |
| 13:58 | ilyak | it's CSVWriter.writeNext(String[]) |
| 13:58 | TimMc | ilyak: Hint it in the let |
| 13:59 | amalloy | ^"[String" i think |
| 13:59 | amalloy | or...there's an L in there somewhere |
| 13:59 | amalloy | &(class (into-array ["test"])) |
| 13:59 | sexpbot | ⟹ [Ljava.lang.String; |
| 14:00 | TimMc | ilyak: ^Hint lister (get ...) I think... |
| 14:00 | ilyak | TimMc: Okay |
| 14:01 | ilyak | It's almost done |
| 14:02 | ilyak | Now it could not figure out reflection for .plusDays (lines 133-134) |
| 14:03 | raek | iirc, ^"[String" can be written as ^strings |
| 14:03 | raek | or maybe that is only for primitives |
| 14:04 | ilyak | It still have some strange issues |
| 14:04 | amalloy | raek: i think it's primitives. string *might* be special cased, but i'd be surprised |
| 14:04 | ilyak | For example, I need to do (defn ^DateTime read-date-time [^String string] (.parseDateTime date-time-formatter string)) |
| 14:05 | ilyak | Why can't it figure out the determined return type of read-date-time? |
| 14:05 | amalloy | ilyak: you haven't told it what date-time-formatter is |
| 14:05 | raek | ilyak: functions always return Objects (in 1.2) |
| 14:06 | Andja | Ok, people I have a assignment due tomorrow for clojure and I really really need someone to give my code a look and tell me is my code ok and give me some tips perhaps. https://code.google.com/p/binary-search-tree-implementation/source/browse/trunk/%20binary-search-tree-implementation/tree.clj |
| 14:06 | Andja | please pm me :) |
| 14:06 | raek | ilyak: you cant put a typehint there, so you have to put it at all places where the function is called |
| 14:07 | ilyak | amalloy: It can infer that too |
| 14:07 | TimMc | ilyak: THe compiler *might* need to be told the type of qux in (.foo bar qux), but it *always* needs to know what type bar is. |
| 14:07 | fliebel | Andja: Why pm? |
| 14:07 | Andja | fliebel: Because I am to embarrased to talk in public :) |
| 14:07 | Chousuke | Andja: It could use some more spaces :P |
| 14:08 | Chousuke | and perhaps destructuring |
| 14:08 | fliebel | Andja: Except for the formatting, it looks okay to me. Except that your doc strings are on the wrong side of the arguments. |
| 14:08 | Andja | fliebel: I dont even know how to run my code without copy pasting it in emacs |
| 14:08 | Chousuke | instead of doing (:val tree) etc. all the time, destructure with {:keys [val L R]} instead |
| 14:08 | Chousuke | then you can just use val, L and R to refer to the values |
| 14:09 | Andja | Chousuke: Ok, thank you ill rewrite it |
| 14:10 | ilyak | TimMc: raek: http://pastebin.com/TfceKQ0n |
| 14:10 | Chousuke | eg. (defn makeseq [{:keys [val L R] :as tree}] (when tree (concat (makeseq L) [val] (makeseq R)))) |
| 14:10 | ilyak | Why does it complain that call to print can't be resolved? |
| 14:10 | ilyak | I mean, I did everything I could |
| 14:10 | TimMc | ilyak: Looks reasonable to me, but I'm not an expert on the compiler. |
| 14:11 | Chousuke | Andja: otherwise, it seems ok. But yeah, fix the formatting :) |
| 14:11 | fliebel | Whoa, is it just me, or are there *a lot* of open issues for Clojure? |
| 14:11 | ilyak | amalloy: dnolen: any ideas on http://pastebin.com/TfceKQ0n vs "call to print can't be resolved"? |
| 14:11 | raek | ilyak: this works (defn foo [] ...) (defn bar [] (let [^Foo f (foo)] ...)) but not this (defn ^Foo foo [] ...) (defn bar [] (let [f (foo)] ...)) |
| 14:12 | Andja | Chousuke: What do you think I should add to my project cus it looks kinda dry just like that on it's own. |
| 14:12 | raek | ilyak: basically, type hints are only considered inside functions. they are gone after the function is compiled |
| 14:12 | amalloy | candles and cupcakes |
| 14:12 | Chousuke | Andja: no idea :) |
| 14:12 | Andja | Chousuke: haha :) Thanx anyway m8 appriciate it! |
| 14:13 | stuartsierra | fliebel: There are a lot of JIRA tickets, with a lot of duplication. |
| 14:13 | ilyak | raek: So type hints inside (def are worthless? |
| 14:13 | raek | ilyak: now I saw that date-time-formatter was not a function, but the same thing holds |
| 14:13 | raek | ilyak: yes |
| 14:13 | ilyak | Why aren't they an error? |
| 14:14 | ilyak | And what can I do? I can't use global-bound java objects? |
| 14:14 | fliebel | stuartsierra: I see… Is there anything mere mortals can do to improve that situation? |
| 14:14 | raek | I have no answer reagarding the reason, but the compiler ignores metadata where it doesn't look for it |
| 14:15 | ilyak | raek: In fact it seems to not be the case |
| 14:15 | stuartsierra | fliebel: Add comments with explanations & links where you find duplicates. |
| 14:15 | ilyak | If I remove a type hint ^DateTime read-date-time, then .toLocalDate in read-local-date fail to resolve |
| 14:16 | ilyak | if I keep it, it resolves |
| 14:17 | raek | oh. hrm. maybe you're right |
| 14:17 | stuartsierra | Type hint metadata can go on Vars, symbols, or list expressions. |
| 14:17 | raek | didn't know that the compiler looked at the metadata of the var, in addition to the metadata on the code data structure |
| 14:18 | fliebel | stuartsierra: Okay. But… don't people use the search function themselves? |
| 14:18 | ilyak | oops |
| 14:18 | ilyak | I had a faulty type hint |
| 14:18 | ilyak | that's why it failed |
| 14:18 | stuartsierra | fliebel: not always |
| 14:19 | stuartsierra | we've had 3 different ticket trackers in 3 years, we're still recovering |
| 14:19 | TimMc | ilyak: Misspelling? |
| 14:19 | raek | does the compiler treat the :tag metadata of a var containing a fn as the type hint for the return value then? |
| 14:19 | fliebel | stuartsierra: Ouch, that does not help I guess. |
| 14:20 | aredington | Hopefully someone will wait till 2013 to write a ticket tracker in Clojure. |
| 14:20 | stuartsierra | raek: yes |
| 14:20 | ilyak | TimMc: Nope, I told it that date-time is String |
| 14:20 | raek | ilyak: please ignore what I have said... :-) |
| 14:20 | ilyak | Apparently it didn't believe |
| 14:20 | ilyak | The only issue I have standing is: |
| 14:20 | ilyak | 154 - reference to field toLocalDate can't be resolved |
| 14:25 | fliebel | stuartsierra: Ouch, this is harder than I thought. I found one duplicate so far. Can I ignore the ones by http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=importer? |
| 14:25 | stuartsierra | not necessarily. |
| 14:26 | stuartsierra | You can ignore all CONTRIB-* issues, however. |
| 14:26 | fliebel | And probably those by the core team as well. |
| 14:26 | stuartsierra | probably |
| 14:27 | cemerick | Projects go into JIRA, and _they never come out_ |
| 14:27 | stuartsierra | the core team is working on this — we had a whole meeting this morning about pruning tickets for the next release. |
| 14:27 | stuartsierra | But deleting duplicated or vaguely-defined tickets hasn't been as much of a priority. |
| 14:28 | stuartsierra | Got to go focus on my talk for #phillyete next week. |
| 14:29 | aredington | fliebel: if you use the advanced search feature you can scope things pretty precisely e.g. 'project = CLJ AND issuetype = Defect' will get you only the defects against the main clojure lang |
| 14:29 | aredington | I know embarrassingly too much about jira issue juggling so feel free to direct questions toward me :) |
| 14:29 | ilyak | wow |
| 14:30 | ilyak | It's /really/ fast now |
| 14:30 | ilyak | 2x the js version |
| 14:30 | ilyak | dnolen: |
| 14:30 | ilyak | 3x |
| 14:30 | hiredman | sounds like we need (as far as I know unwritten) jira-jdbc |
| 14:30 | hiredman | (a jdbc driver for jira) |
| 14:30 | fliebel | aredington: I figured that out, but now I have only 17 tickets left, so I must have selected to… selectively. |
| 14:32 | dnolen | ilyak: nice. |
| 14:33 | fliebel | Meh, I'd rather spend time fixing my own issue than browsing stuff by others. Only.. I'm really stuck. |
| 14:34 | ilyak | dnolen: last question for today |
| 14:34 | ilyak | http://pastebin.com/cFNx0SnG |
| 14:34 | ilyak | Is there a way to make it shorter? |
| 14:34 | ilyak | I mean, it's cool that it's fast, but 2x more lines is eww |
| 14:34 | ilyak | (one function) |
| 14:35 | fliebel | ~logs |
| 14:35 | clojurebot | logs is http://clojure-log.n01se.net/ |
| 14:35 | raek | ilyak: (map (fn [x] ...) coll) -> (for [x coll] ...) |
| 14:36 | dnolen | ilyak: can't dig in but I saw a lot of things I would do differently in your code. Using records in this kind of code seems pretty unnecessary. |
| 14:36 | raek | you can even do (for [x coll :let y (f x)] ...y...) |
| 14:36 | ilyak | cool tanks |
| 14:36 | ilyak | dnolen: I'm just dabbling |
| 14:36 | ilyak | I'll be back for advice one day :) |
| 14:37 | aredington | fliebel I get 42 back with 'project = CLJ AND issuetype = Defect and status=Open' |
| 14:37 | raek | s/:let y (f x)/:let [y (f x)]/ |
| 14:38 | fliebel | aredington: Okay, I'll have another look later &&&& < to find it in my search history |
| 14:38 | dnolen | ilyak: lines 51 59, would be shorter w/ destructuring. |
| 14:38 | dnolen | ilyak: destructuring could be used in quite a few places. |
| 14:40 | dnolen | ilyak: figure-out-best-major looks like it could be made way shorter. |
| 14:40 | Raynes | drewr: postal doesn't support SSL, does it? :| |
| 14:41 | drewr | Raynes: not directly, but it's trivial through msmtp or some other proxy |
| 15:01 | Raynes | drewr: I'll probably fork it and add it myself. |
| 15:01 | Raynes | Would you be opposed to direct SSL support? |
| 15:02 | drewr | not at all |
| 15:02 | drewr | just isn't a priority when other tools do it better |
| 15:03 | Raynes | drewr: Right, but I'd rather not depend on something can't be grabbed by maven, and JavaMail supports it. |
| 15:04 | Raynes | something that* |
| 15:05 | drewr | you need to expand your horizons :-) |
| 15:05 | drewr | however, if you do the work I'll certainly consider it |
| 15:07 | chrissbx | Is there a macro to split its arguments into right-associated binary calls? |
| 15:08 | chrissbx | e.g. (right-associate foo a b c) -> (foo a (foo b c)) |
| 15:08 | fliebel | chrissbx: reduce? |
| 15:09 | chrissbx | well that's a function, and it expects a list. |
| 15:10 | chouser | and will left-associate |
| 15:10 | fliebel | true |
| 15:11 | fliebel | hm, in Haskell there is foldl and foldr... |
| 15:11 | amalloy | fliebel: guess what is in amalloy-utils |
| 15:11 | fliebel | amalloy: Oh, I know this one! Let me think… lazy-reduce? |
| 15:12 | fliebel | no, lazy-recur! |
| 15:13 | fliebel | amalloy: How did you implement it? Let me see... |
| 15:13 | chouser | chrissbx: you're sure you want a macro? |
| 15:13 | fliebel | okay, I found unfold… |
| 15:14 | chrissbx | Well, it seemed like the natural thing: I want to turn a syntactical representation to another one |
| 15:14 | chrissbx | Yes I could create a list and then fold, but.. |
| 15:14 | chrissbx | that needs the list, and also it needs list construction syntax syntactically. |
| 15:14 | chrissbx | Seems like a double looser. |
| 15:15 | fliebel | oh, lazy-loop even, but amalloy, I can't find it :( |
| 15:15 | amalloy | fliebel: it's in amalloy.utils |
| 15:15 | amalloy | not utils.whatever |
| 15:15 | amalloy | i guess i might not have pushed it? |
| 15:15 | amalloy | haha apparently so |
| 15:15 | amalloy | sorry to taunt you fliebel |
| 15:16 | fliebel | haha sadface |
| 15:16 | amalloy | fliebel: i just implement it as (reduce (reverse-args-to f) (reverse coll)) |
| 15:16 | fliebel | amalloy: Do you happen to have an implementation of seque laying around locally as well? |
| 15:17 | amalloy | fliebel: no, but i was interested by your tweet. finish it up, i want it |
| 15:17 | fliebel | amalloy: It works, except sometimes it does not :( |
| 15:17 | amalloy | ouch |
| 15:18 | fliebel | Even though it's in java.util.concurrent, it's still not persistent, so it comes with all the classical java problems. |
| 15:33 | nlogax | anyone using "static", the static site generator? |
| 15:33 | nlogax | wondering why it crashes if i include a doctype in the default hiccup template |
| 15:45 | edw | Is there a clojure.string/split-like procedure where you specify what characters to collect, as opposed to which characters separate an element? E.g. (FOO "this is a test" #"[a-z]+") |
| 15:46 | amalloy | edw: re-seq? |
| 15:46 | ataggart | ,(re-seq #"[a-z]+" "this is a test") |
| 15:46 | clojurebot | ("this" "is" "a" "test") |
| 15:46 | edw | I think that'll do the trick. Thanks! |
| 15:53 | pdk | (doc reverse-args-to) |
| 15:53 | clojurebot | Excuse me? |
| 15:53 | pdk | ,(reverse-args-to +) |
| 15:53 | clojurebot | java.lang.Exception: Unable to resolve symbol: reverse-args-to in this context |
| 15:54 | amalloy | pdk: not a built-in |
| 15:54 | chouser | #(+ %2 %1) |
| 15:54 | pdk | in contrib then? |
| 15:55 | chouser | shorter, and no distracting alphabet chars! |
| 15:55 | amalloy | pdk: https://github.com/amalloy/amalloy-utils/blob/master/src/amalloy/utils/reorder.clj |
| 15:56 | arohner | is there a fn to update the metadata, like assoc-meta, or do I have to do it by hand? |
| 15:56 | amalloy | &(doc vary-meta) |
| 15:56 | sexpbot | ⟹ "([obj f & args]); Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadata." |
| 15:56 | arohner | amalloy: thanks. I should have find-doc'd first |
| 15:57 | dnolen | ,(let [flip (fn [f] (fn [& xs] (apply f (reverse xs))))] ((flip /) 2 4)) |
| 15:57 | clojurebot | 2 |
| 16:04 | bulters | this is odd; i added congomongo as a dependency in lein, tell it to use somnium.congomongo and I get a compile error |
| 16:04 | bulters | am I forgetting something? |
| 16:04 | amalloy | lein deps? |
| 16:05 | bulters | that's done |
| 16:05 | amalloy | and it successfully got into your lib directory? |
| 16:05 | bulters | yes, including dependencies |
| 16:06 | bulters | restarted swank |
| 16:08 | bulters | ok, got it... I tried out congomongo without somnium. before restarting swank |
| 16:10 | ideamonk | Hi I'm very new to clojure, and am trying to nest a function inside another and call the nested function (mycount2) from outer function (mycount). But it seems everytime I try running it, I get a nil, am I calling the nested function the wrong way? is there a way to assign default values to arguments of a function in clojure? http://paste.pocoo.org/show/376541/ .. also I'm very new to functional programming itself. Looking for any |
| 16:11 | pdk | you're using fn wrong |
| 16:11 | ohpauleez | ideamonk: I'm looking at your paste now |
| 16:12 | pdk | ex. (fn [x y] (+ x y)) would simply create and return an anonymous function that returns x + y, it won't give it a name or make it available to call by name |
| 16:12 | ideamonk | pdk: isn't fn like anonymous functions, that can be created in-place and called in-place ? |
| 16:12 | pdk | yes |
| 16:12 | pdk | if you want to give it a name |
| 16:12 | pdk | you'd either use (defn function-name [arguments] body...) to give it a name that can be used at the toplevel |
| 16:13 | pdk | or store it within something such as in a let block to have it available in a local scope |
| 16:13 | ideamonk | pdk: Thx, im trying to rectify now. |
| 16:13 | pdk | ex. (let [myfn (fn [x y] (+ x y))] body...) will define myfn as the function given and will make it accessible from within the body of the let statement by that name |
| 16:14 | amalloy | ohpauleez: you okay with releasing a non-snapshot of clj-github? i'm using it for 4clojure.com and want to reduce our snapshot usage |
| 16:14 | ohpauleez | amalloy: Yeah, it's still matches the API right now and has tests where it matters most |
| 16:15 | ohpauleez | Raynes does the releases to clojars though |
| 16:15 | amalloy | ohpauleez: i know. he didn't want to release without checking with you, since you've been doing more dev than him |
| 16:15 | Raynes | ohpauleez: Cool, I'll release it later. |
| 16:16 | amalloy | i'm in a similar position with clojail |
| 16:16 | Raynes | amalloy: Remind me, please, because I know I'm going to forget. |
| 16:16 | ohpauleez | amalloy, Raynes: Cool, yeah, go for it |
| 16:16 | pdk | take a look at the reply to the paste |
| 16:16 | pdk | or rather here it is http://paste.pocoo.org/show/376547/ |
| 16:16 | pdk | er correction |
| 16:16 | ideamonk | pdk: thanks :) |
| 16:17 | pdk | (fn mycount [coll] should be (defn mycount [coll] if you want to be able to refer to mycount by name outside of that function def |
| 16:17 | pdk | the way fn alone works is |
| 16:17 | ideamonk | pdk: im doing 4clojures :) they're like in place fill in the blanks |
| 16:17 | pdk | (fn fn-name [arguments] lets you refer back to the function you're writing by calling it with fn-name if it's defined recursively |
| 16:17 | pdk | but that won't make fn-name refer to the function from outside |
| 16:18 | ideamonk | hmm |
| 16:18 | pdk | replacing fn with defn in (fn mycount [coll] defines it by the name mycount and makes it accessible at the toplevel |
| 16:19 | pdk | basically (defn myfn [args] ...) = (def myfn (fn [args] ...)) |
| 16:19 | pdk | and def defines symbols that can be referred to by name at any scope |
| 16:19 | ideamonk | yes |
| 16:22 | hiredman | pdk: no, def creates vars |
| 16:22 | hiredman | not symbols |
| 16:22 | hiredman | the reader and the symbol function create symbols |
| 16:25 | bulters | amalloy: didn't know about 4clojure; very nice :D |
| 16:26 | amalloy | bulters: it's only a few days old, so that's why you didn't know :P |
| 16:28 | bulters | amalloy: works really nice; working through the problems now :D |
| 16:30 | pdk | so do you register an acct for this 4clojure deal |
| 16:31 | peteriserins | oh god, I wish I knew that fns can be named before doing the 4clojure problems by loop recur only |
| 16:31 | amalloy | pdk: you don't have to, but you should: www.4clojure.com/register |
| 16:32 | peteriserins | didn't let me use def so I thought explict recursion is discouraged |
| 16:32 | amalloy | peteriserins: nope, just def is discouraged :) |
| 16:33 | peteriserins | amalloy: btw what's the idiom for contributing problems? should one fork the dataset? |
| 16:33 | bulters | can you recur in a lambda? |
| 16:33 | amalloy | peteriserins: yes, for now |
| 16:33 | amalloy | fork the repo, change data_set, push, send a pull request |
| 16:33 | amalloy | we have a feature request to add a nicer ui for that |
| 16:33 | peteriserins | yeah that'd be very welcome |
| 16:35 | bulters | amalloy: rather than trying it out, i'll ask you (not to cheat): if you ask write a function, does it check if a function really is written? |
| 16:35 | bulters | or does (reverse (first list)) also work for problem 19? :P |
| 16:35 | amalloy_lunch | bulters: no. the test cases there get run, and that's about it |
| 16:36 | bulters | ok, thanks. enjoy your lunch |
| 16:36 | amalloy_lunch | someone submitted "reduce conj ()" as a solution to one problem |
| 16:36 | bulters | ha! :D |
| 16:36 | peteriserins | amalloy_lunch: how do you view others' solutions? |
| 16:47 | spewn | For all the ones in the form "(= ___ ...)", the most trivial "solution" seems to be "=);" |
| 17:00 | krl | can you define protocol functions with variable amount of arguments? |
| 17:01 | matthias_ | can i check which versions are avaiable of a dependency? |
| 17:01 | cemerick | krl: no, you can't use varargs in protocols (yet, perhaps) |
| 17:02 | krl | hmm. no way to get around this/other ways of doing multidispatch? |
| 17:02 | cemerick | matthias_: http://mavencentral.sonatype.com/ is there for central; You should be able to spelunk through clojars if that's where the dependency you're after is deployed. |
| 17:02 | cemerick | krl: multimethods, if that suits you |
| 17:02 | matthias_ | thanks |
| 17:02 | amalloy | peteriserins: there's a button to tweet your solution. i only see the ones that get tweetet |
| 17:02 | cemerick | protocols do not offer multiple dispatch |
| 17:02 | amalloy | but check on twitter for #4clojure |
| 17:04 | krl | cemerick, ah true, had my concepts wrong. single dispatch is enough for me |
| 17:04 | krl | looking at multimethods, thx |
| 17:14 | peteriserins | amalloy: cool, thanks |
| 17:35 | devn | how to dispatch on type with multimethods |
| 17:35 | devn | err when there's a protocol involved |
| 17:36 | amalloy | (defmulti foo (fn [a & _] (class a)))? |
| 17:36 | raek | devn: why not use protocols and types directly? |
| 17:37 | devn | nah, it's like (defprotocol Foo (dothis [this] "foo bar") (dothat [this] "baz qux")) |
| 17:38 | devn | (reify Foo (dothis [this] (str "dothis")) (dothat [this] (str "dothat"))) |
| 17:39 | devn | when you do this many times it seems like it's a bit redundant |
| 17:40 | devn | it feels like there should be a way to dispatch with a multimethod based on something being a Foo |
| 17:40 | devn | does that make sense? |
| 17:40 | ataggart | Why do you have those strings in your defprotocol? |
| 17:40 | raek | so what would the different dispatch values be? |
| 17:40 | devn | docstrings |
| 17:41 | ataggart | good, so then what's the redundancy? |
| 17:41 | devn | I want to say, if the thing is a Foo, do this, but if it's a String, do that |
| 17:43 | devn | i end up with (cond (satisfies? Foo ...) (dothis) (isa? (class ...) String) ...) :default (throw (RuntimeException. ...))))) |
| 17:43 | ataggart | (extend-protocol Foo String (dothis ...)) |
| 17:43 | devn | hmm, trying that, give me a moment :) |
| 17:43 | ataggart | Foo is the prototype, not a type |
| 17:44 | ataggart | so this: "if the thing is a Foo, do this, but if it's a String, do that" is a possibly broken sentence |
| 17:44 | ataggart | should Foo be a type or a protocol? |
| 17:45 | stuartsierra | If you're dispatching on it, then it's a type. |
| 17:45 | stuartsierra | A protocol is that which does the dispatching. |
| 17:45 | ataggart | true, though inconsistent with his examples, hence the question |
| 17:45 | raek | devn: to summarize: protocols give you dynamic dispatch on the type of the first argument - even with others' types |
| 17:50 | TimMc | 'You tripped the alarm! eval is bad!" |
| 17:50 | TimMc | :-) |
| 17:50 | Raynes | >_> |
| 17:50 | Raynes | Was there some hidden context to that? :o |
| 17:51 | TimMc | No, just noting that the same security (clojail?) is in place on 4clojure as in one of the bots. |
| 17:51 | devn | raek: stuartsierra: ataggart: thanks :) |
| 17:51 | stuartsierra | 'welcome |
| 17:52 | TimMc | I guess I posted a bit late for the context to be obvious. |
| 17:52 | Raynes | TimMc: Aye, yes. |
| 17:52 | Raynes | TimMc: I work on 4clojure as well. |
| 17:54 | TimMc | The Top Users page doesn't get recomputed right away, I see. |
| 17:55 | TimMc | Raynes: Grrr, I do not like problem 4. |
| 17:56 | Raynes | I didn't write that. ;) |
| 17:56 | amalloy | TimMc: yeah, a project Raynes and i are involved in, which needs sandboxing...not at all surprising that it uses clojail :P |
| 17:56 | TimMc | Raynes: Well, express my displeasure to whoever did. :-P |
| 17:56 | Raynes | Will do. |
| 17:57 | TimMc | (There's something fundamentally icky about telling users to put in a sequence of forms for a single form.) |
| 18:03 | TimMc | Raynes: I think I wouldn't find it problematic if there was a demo problem that showed multiple forms entered as a solution. |
| 18:07 | ohpauleez | TimMc: There's a getting started section that shows that, but I think it should be integrated into the problem set |
| 18:26 | TimMc | It doesn't show multiple forms. |
| 18:26 | TimMc | If I were coming straight from another Lisp, problem 4 would have confused me a lot more than it already did. |
| 18:38 | schlechtv | When using cake to execute a clojure "script": how can I pass commandline args? It doesn't seem to use ~main as an entry point ... |
| 18:46 | Raynes | _fogus_: Ping. |
| 19:01 | chrissbx | I'm missing the documentation of quasiquote |
| 19:02 | chrissbx | What's wrong with (defmacro ist [expr res] `(is (= ',res ,expr))) ? |
| 19:03 | amalloy | chrissbx: ~, not , |
| 19:03 | amalloy | er |
| 19:03 | amalloy | the single character to unquote is ~ |
| 19:03 | chrissbx | Ok, but it already complains about is, no such variable mynamespace/is |
| 19:04 | amalloy | you need to define the macro in a namespace that knows about is |
| 19:04 | amalloy | presumably the one from clojure.test or some such |
| 19:04 | amalloy | &`walk |
| 19:04 | sexpbot | ⟹ clojure.core/walk |
| 19:04 | chrissbx | (ns mynamespace (:require clojure.test)) |
| 19:04 | amalloy | that's only a require, not a refer |
| 19:05 | chrissbx | aha |
| 19:05 | amalloy | if you wrote clojure.test/is, it would work |
| 19:05 | chrissbx | Ok, thanks. |
| 19:07 | chrissbx | Ah, comma seems to be a noop. |
| 19:07 | amalloy | chrissbx: it's whitespace |
| 19:07 | chrissbx | yep |
| 19:08 | amalloy | &(+,1,2,3,,) |
| 19:08 | sexpbot | ⟹ 6 |
| 19:11 | scottj | I want to implement a foo where (foo "abc" "ac") => 2/3 and (foo "abc" "cba") => 1/3, any obvious/simple ways to do this? |
| 19:12 | Kowboy | hello |
| 19:13 | amalloy | &(map #(if (= %1 %2) 1 0) "abc "cba") |
| 19:13 | sexpbot | java.lang.Exception: EOF while reading string |
| 19:13 | amalloy | &(map #(if (= %1 %2) 1 0) "abc" "cba") |
| 19:13 | sexpbot | ⟹ (0 1 0) |
| 19:13 | amalloy | scottj: now just sum the list and divide by count |
| 19:14 | scottj | &(map #(if (= %1 %2) 1 0) "abc" "ac") |
| 19:14 | sexpbot | ⟹ (1 0) |
| 19:15 | scottj | so doesn't work for both cases |
| 19:15 | amalloy | scottj: so far you haven't asked for any particular behavior when the strings aren't the same length |
| 19:17 | amalloy | oh, you have |
| 19:17 | amalloy | haha |
| 19:17 | amalloy | it was sneakily word-wrapped on my client. anyway, if you could explain where you want that 2/3 number to actually come from... |
| 19:18 | scottj | number of characters in %2 in same order as %1 |
| 19:18 | amalloy | $google longest common subsequence |
| 19:18 | sexpbot | First out of 16200 results is: Longest common subsequence problem - Wikipedia, the free encyclopedia |
| 19:18 | sexpbot | http://en.wikipedia.org/wiki/Longest_common_subsequence_problem |
| 19:24 | scottj | yeah that's it, thanks for the pointer |
| 19:25 | amalloy | scottj: good, hope you find something useful there. the usual solution always had trouble fitting in my head |
| 19:37 | chrissbx | Is there some kind of an assert form that returns the value if it's ok? e.g. (first (assert* pair? (foo bar))) |
| 19:38 | chrissbx | Hm, how do you actually check for a non-empty list? |
| 19:38 | amalloy | seq |
| 19:39 | amalloy | chrissbx: (doto (foo bar) (->> (assert pair?))) would be one way to do it with existing tools |
| 19:39 | chrissbx | amalloy: re seq, hu? That returns a sequence, not a boolean. |
| 19:40 | amalloy | &(map seq [[] [1]]) |
| 19:40 | sexpbot | ⟹ (nil (1)) |
| 19:40 | amalloy | nil is like false, anything else is true. you don't need an actual boolean |
| 19:40 | chrissbx | aha, hu |
| 19:41 | chrissbx | Well, seq fails if its argument is not already a sequence or empty. |
| 19:41 | chrissbx | Which doesn't concern me in my current chunk of code, but still. |
| 19:41 | amalloy | &(doc coll?) |
| 19:41 | sexpbot | ⟹ "([x]); Returns true if x implements IPersistentCollection" |
| 19:46 | chrissbx | How do I expand a piece of code completely, or n layers? Both macroexpand-1 and macroexpand only expand 1 layer. |
| 19:47 | amalloy | &(use 'clojure.walk) |
| 19:47 | sexpbot | ⟹ nil |
| 19:47 | amalloy | &(doc macroexpand-all) |
| 19:47 | sexpbot | ⟹ "([form]); Recursively performs all possible macroexpansions in form." |
| 19:48 | chrissbx | Thanks |
| 19:48 | amalloy | chrissbx: not strictly true, though. macroexpand expands N layers of macros - it just doesn't expand macros in the *arglist* |
| 19:48 | amalloy | &(macroexpand-1 '(doto x inc)) |
| 19:48 | sexpbot | ⟹ (clojure.core/let [G__29748 x] (inc G__29748) G__29748) |
| 19:48 | amalloy | &(macroexpand '(doto x inc)) |
| 19:48 | sexpbot | ⟹ (let* [G__29756 x] (inc G__29756) G__29756) |
| 19:49 | chrissbx | yes, no subforms (I've just read the docs) |
| 19:50 | ideamonk | has anyone encountered any problem with the last z in https://www.4clojure.com/problem/36 ? |
| 19:52 | amalloy | ideamonk: i wrote that problem. what do you mean, encountered problem? |
| 19:53 | ideamonk | amalloy: yup the solution which works locally isn't working there, weird , ending with java.lang.Exception: Unable to resolve symbol: z in this context (NO_SOURCE_FILE:0) |
| 19:54 | amalloy | then you're doing it wrong :P. can you paste into irc the solution you're putting in the 4clojure text box? |
| 19:55 | ideamonk | amalloy: http://pastebin.mozilla.org/1210219 |
| 19:56 | ideamonk | works locally, while on 4clojure page its a "java.lang.Exception: Unable to resolve symbol: z in this context" |
| 19:57 | ideamonk | amalloy: i hope im not doing something stupid :P |
| 19:58 | amalloy | ideamonk: i have bad news for you, then |
| 19:58 | amalloy | :) |
| 19:58 | ideamonk | ah |
| 19:58 | amalloy | &(let [x 7] [y 3] x) |
| 19:58 | sexpbot | java.lang.Exception: Unable to resolve symbol: y in this context |
| 19:59 | amalloy | let only treats the first vector as a binding, is my point |
| 20:00 | amalloy | &(let [x 7, y 3] y) |
| 20:00 | sexpbot | ⟹ 3 |
| 20:00 | ideamonk | if we fill the last blank with "[z 1]" , it becomes |
| 20:01 | ideamonk | &(= 1 (let [z 1] z)) |
| 20:01 | sexpbot | ⟹ true |
| 20:01 | amalloy | ideamonk: there's no "last blank" |
| 20:01 | amalloy | all three blanks are filled with the entire text you enter |
| 20:01 | ideamonk | amalloy: aha i've been assuming this all time ! |
| 20:01 | ideamonk | got it then !! |
| 22:38 | ideamonk | amalloy: have you done #44 on 4clj ? what could be wrong http://pastebin.mozilla.org/1210284 , seems to work perfect for testcases given, fails on unit tests |
| 22:42 | amalloy | ideamonk: try it with a large negative rotation |
| 22:43 | amalloy | eg, a list of size 3, rotated by -9, should stay the same |
| 22:43 | ideamonk | AWW |
| 22:43 | ideamonk | ah ah THX! :) |
| 23:48 | joshua__ | $findfn [true true true] true |
| 23:48 | sexpbot | [clojure.core/== clojure.core/sequential? clojure.core/second clojure.core/last clojure.core/reversible? clojure.core/distinct? clojure.core/boolean clojure.core/vector? clojure.core/counted? clojure.core/associative? clojure.core/< clojure.core/peek clojure.core/fir... http://gist.github.com/938243 |