StackOverflow TV Opportunity to Promote Clojure
StackOverflow just announced an experimental project to produce videos in its New York City office. This could be a great opportunity to polish up one of your presentations and promote Clojure to a wide audience. No speaker fees, but reasonable travel costs covered. Post: http://meta.stackoverflow.com/q/270574/1756702 Email: t...@stackoverflow.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Best way to create a namespace at runtime from a web app
Have you tried the aptly named create-nshttp://clojuredocs.org/clojure_core/clojure.core/create-ns ? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: regex
On Friday, April 18, 2014 8:28:03 AM UTC-5, Thumbnail wrote: I had a couple of insights. First, to allow the dfa to be generated programmatically, I changed it from a map to a vector. This means that the next state can just be an integer. Second, I decided that the terminal state would always be at index 0 ... Shouldn't a DFA allow for *any* *set* of states to be terminal? For instance, the minimal DFA for (ab)*(1 + a) has two states, both terminal. I haven't read through the above, but will have to later as I am familiar with the excellent linked article, so thanks for bumping this back to the top. As to your question, there is a straightforward translation from multiple terminal states to a single one. Add a special terminal input symbol to your alphabet and consider any input strings to be terminated by that symbol. For each of the terminal states add a transition to a single terminal state for the terminal symbol. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: The Cons in iterate's return value
On Wednesday, April 16, 2014 10:35:14 PM UTC-5, Mars0i wrote: But then should realized? be able to deal with a Cons containing a LazySeq? (Is this an issue worthy of JIRA? I've never submitted there, and am not sure I know enough to do so. Willing to try to figure it out.) No, realized? works as intended on a single object. If you want to know if there is an unrealized portion remaining of a sequence, just roll your own function to step through it, being careful not to force realization of unrealized portions while doing so. Untested example: (defn seq-realized? Returns false if there is an unrealized tail in the sequence, otherwise true. [s] (if (instance? clojure.lang.IPending s) (if (realized? s) (if (seq s) (recur (rest s)) true) false) (if (seq s) (recur (rest s)) true))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Questions regarding Map vs Record and usage
You can refer-in the first (factory function) to another namespace; for the second you'd have to import the class. I prefer the first. The third is special syntax for the reader. As to the last question, I don't know, but it allows you to define your own. For example, (defrecord Book [title author] clojure.lang.IFn (invoke [this x] (get this x)) (invoke [this x not-found] (get this x not-found))) (def b (-Book Lord of the Rings, Tolkien)) (b :title) ;= Lord of the Rings But you could alter the behavior as desired. On Wednesday, April 9, 2014 1:51:01 PM UTC-5, Anthony Ortiz wrote: I see that there are several ways of instantiating a record : (-Book Lord of the Rings, Tolkien) (Book. Lord of the Rings, Tolkien) #user.Book{:title Lord of the Rings, :author Tolkien} Questions : 1) The second version is referred to as the original version so I'm wondering which is the preferred method. 2) Why is the third version not within a list? I thought that for the language to consider something callable it had to be the first argument in a list (eg : (+ 1 2)) 3) The record that is returned via (def b [version of choice goes here]) is treated as a map when using the form (:title b) but doesn't treat it as a map when using the form (b :title) which seems pretty inconsistent to me; is there are valid reason for this inconsistency? I'm sure I'm missing something. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Lazy sequence - how they work internally
On Tuesday, April 8, 2014 7:57:10 AM UTC-5, sorin cristea wrote: What exactly you mean by '*The point was you aren't using lazy-seq as intended here since you are always creating a singleton sequence*' ? In my sum function...I intend to compute sum of elements of a collection. Lazy-seq is intended to build sequences. Generally you'd have each invocation of lazy-seq produce one or more elements of a sequence. You are only nominally building a sequence. It is always just one element. You are reducing a collection to a sum. That is the job of reduce. If you want to delay evaluation for a given argument, use a thunk or a delay. (defn my-sum [n] (reduce + (range n))) (def my-result 10) ; my-result is 45 (eagerly evaluated) (def my-thunked-result (fn [] (my-sum 10))) ; the sum is not calculated until evaluating (my-thunked-result), answer is not cached (def my-delayed-result (delay (my-sum 10))) ; the sum is not calculated until forcing @my-delayed-result, answer is cached for subsequent use [I]f I [d]o this *(def x **(test-fc ...))*, and then *x,* this is not the same thing with *(test-fc ...)* ?, I understand the issue related to time to compute this sum, but the same time is taken when I call x, right ? Yes, that's what I said. Only in the first case evaluation is delayed until you request the value of `x` and in the second it is requested immediately to print at the REPL. You might find it instructive to put some `println`s in your code to see how and when your calculation is progressing and to use a large but still reasonable size collection, say 1 million elements. Thanks for the hint with trampoline function, really interested . Sorin. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Name for this pattern: side-effect from swap!
See https://groups.google.com/d/topic/clojure/2dHvX7bf7nA/discussion, http://stackoverflow.com/a/22409846/1756702, where the old and new state of an atom is returned using the lower-level compare-and-set! operation. On Tuesday, April 8, 2014 10:41:50 AM UTC-5, John Hume wrote: I sometimes find that after mutating an atom, I want to create some side-effect that depends on the old and new state as well as the context in which the change was made. Because of the dependence on context, a watch doesn't work (unless there's something I'm not thinking of). So I add things to the new atom state (returned by swap!) purely to tell the calling code what side-effect to have (or give it the data it needs to decide what side-effect to have). That additional state isn't used anywhere other than the fn that called swap!. One gotcha to this approach is that one must be careful not to leave some old side-effect causing state in place to cause another side-effect based on stale data. Is there a name for this pattern? A standard way of implementing it? A better alternative? One alternative I'm aware of is using mutable locals (provided by https://github.com/ztellman/proteus) as a side-channel of communication from swap!. Both approaches strike me as messy, though a let-mutable probably makes it more obvious that something funny is going on, and it doesn't pollute the atom. Thanks. -hume. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Fn as value matcher in core.match
It is always matching the first clause because it is getting translated into a `let` binding. In match, the left-hand side `get` is just a symbol, not the `var` it resolves to, so might as well be `(let [fun assoc] (match fun foo foo!))` where `foo` will just be bound to `assoc`. Match does not recognize vars on the left, but does recognize local bindings, so one option is to install them first (let [fun assoc get get assoc assoc] (match fun get get assoc assoc :else other)) Another option would be to use predicates (let [fun assoc] (match fun (_ :guard (partial identical? get)) get (_ :guard (partial identical? assoc))assoc :else other)) Another would be to wrap the functions in a way their value is respected, e.g. as a key in a map (let [fun assoc] (match {fun nil} {get _} get {assoc _} assoc :else other)) None of these are ideal, but the last seems the least offensive to me. One might wish for a special `(:value x)` syntax for such cases. On Monday, April 7, 2014 7:24:10 AM UTC-5, Serzh Nechyporchuk wrote: How can I match fns as values? For example: (let [fun assoc] (match [fun] [get] get [assoc] assoc :else other)) The example above is not match correctly. It always matches on first clause. Thank you. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How do I detect the end of a file without catching an exception?
On Monday, April 7, 2014 1:14:40 PM UTC-5, guns wrote: On Mon 7 Apr 2014 at 11:07:37AM -0700, Simon Brooke wrote: OK, the second question I've sort of answered for myself, by riffing on the source of line-seq: (defn expr-seq Returns forms from src (assumed to be Clojure source) as a lazy sequence of expressions [^java.io.PushbackReader src] (when-let [expr (read src)] (try (cons expr (lazy-seq (expr-seq src))) (catch RuntimeException eof However, line-seq doesn't bother with catching an exception (presumably because it's not using a PushbackReader). So I come back to my first question: how do I detect the end of a file? Use clojure.core/read with three params: [stream eof-error? eof-value] From the Slamhound source: (take-while #(not= ::done %) (repeatedly #(read rdr false ::done))) guns If using clojure.edn, which might be a good idea here, the syntax is slightly different for specifying an EOF marker, e.g. (let [sentinel (Object.)] (take-while #(not= sentinel %) (repeatedly #(edn/read {:eof sentinel} file -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Lazy sequence - how they work internally
The point was you aren't using lazy-seq as intended here since you are always creating a singleton sequence. What's going on behind the scenes here is in effect just trampolining thunks. (defn thunked-sum [sum coll] (if-let [[x more] (seq coll)] (fn [] (thunked-sum (+ sum x) more)) sum)) (trampoline (thunked-sum 0 (range 10))) ;= 45 The trampoline portion of your lazy seq is the while loop in this part of the Java implementation of LazySeq final synchronized public ISeq seq(){ sval(); if(sv != null) { Object ls = sv; sv = null; while(ls instanceof LazySeq) { ls = ((LazySeq)ls).sval(); } s = RT.seq(ls); } return s; } If you do (test-fc (range 210432423543654675765876879)) at your REPL, evaluation is forced for the print, but because your input is so large, the calculation time is prohibitively long. If you placed this in a def instead, evaluation would be delayed until requested at which point it would then take prohibitively long to complete. On Monday, April 7, 2014 3:01:54 PM UTC-5, sorin cristea wrote: Hi Gianluca, I have a question ; why when a run/execute command/code line (test-fc (range 210432423543654675765876879)) it's not executed the function test-fc and return the sum for all 210432423543654675765876879 elements? why should I put the test-fc reference to a variable, x, like you present below. ( this is related to your phrase - your function computes a sequence of just one element (the sum of the collection members - why ?) In this case (def x (test-fc (range 210432423543654675765876879)) I see here a problem, I keep a reference to the head of sequence and this will imply that the GC will can't garbage the unused items, if is wrong what I'm say please correct me. thanks a lot Sorin. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Basic string modification question
Using subs (no need for join) is the way I would go, just define (defn replace-at [s n c] (str (subs s 0 n) c (subs s (inc n (replace-at hello 1 a) ;= hallo and carry on. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: remove first?
On Wednesday, April 2, 2014 3:39:47 PM UTC-5, Christopher Howard wrote: On Wed, 2 Apr 2014 14:07:47 -0600 Timothy Baldridge tbald...@gmail.com javascript: wrote: I don't know of anything built-in, but this should do the trick: (defn remove-first [f [head tail]] (if (f head) tail (cons head (lazy-seq (remove-first f tail) Timothy Thanks. This seems to work for my purposes, although I modified it to handle the empty vector: (defn remove-first [f [head tail]] (if (not head) [] (if (f head) tail (cons head (lazy-seq (remove-first f tail)) This implementation doesn't seem to work on everything that remove works on: com.example.myapp= (remove #(= [1 2] %) {1 2 3 4}) ([3 4]) com.example.myapp= (remove-first #(= [1 2] %) {1 2 3 4}) UnsupportedOperationException nth not supported on this type: PersistentArrayMap clojure.lang.RT.nthFrom (RT.java:835) To fix that, use `seq` on the collection argument. Also, if you want a emtpy sequence as a result instead of nil, just move the lazy-seq up since (lazy-seq nil) is an empty sequence. (lazy-seq (when-let [[head tail] (seq coll)] ...) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Strange behaviour for proxy when two abstract classes are passed in
On Monday, March 31, 2014 4:34:17 PM UTC-5, zcaudate wrote: I know this is a silly example but I am curious to know what is happening with the proxy method. I have set up two calls to proxy: 1. (def cp (proxy [java.util.AbstractMap clojure.asm.ClassVisitor] [])) 2. (def cp (proxy [clojure.asm.ClassVisitor java.util.AbstractMap] [])) The first call is fine and it return cp. The second call gives me an exception. You cross-posted to Stack Overflow Stack Overflowhttp://stackoverflow.com/q/22779892/1756702. Copy of my answer there: Neither will work in Clojure 1.6.0. In 1.5, `clojure.asm.ClassVisitor` was an interface instead of an abstract class. Proxy expects at most one class followed by optional interfaces. As `java.util.AbstractMap` is an abstract class, it cannot appear second in the list of class-and-interfaces. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: REPL: viewing data structures containing infinite lists
On Tuesday, April 1, 2014 11:00:37 AM UTC-5, Andreas Liljeqvist wrote: Is there any good reason for not providing a default value for *print-length*? I think that if you *really* want to print a list containing 100K items, you would have to set *print-length*. Basically it seems less harmful to set it to a nice value by default(42?) than possible locking up the REPL. For the lein REPL, merge this into your ~/.lein/profiles.clj {:user {:repl-options {:init (set! *print-length* 42)}}} -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Function from a symbolic expression
On Monday, March 31, 2014 12:13:25 PM UTC-5, Jony Hudson wrote: (defmacro functionalise [ex var] (let [arg (gensym) body (postwalk-replace {var arg} ex)] `(fn [~arg] ~body))) This works as written, it is just that macros do not evaluate their arguments, so you do not want to quote you expression. (def foo (functionalise (+ 2 x) x)) (foo 40) ;= 42 If you are working with quoted expressions, you'll have to eval in the macro and take the one-time hit there (defmacro functionalise2 [ex var] (let [arg (gensym) body (clojure.walk/postwalk-replace {var arg} ex)] `(fn [~arg] ~(eval body (def foo2 (functionalise2 '(+ 2 x) x)) (foo2 40) ;= 42 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: java interop help for beginner calling java class
Thanks the help is much appreciated created file ocfLZWBW,java added package my.nice.lzw; to the top of the file changed /* */ public class OcfLZW to /* */ public class OcfLZWBW compiled ocfLZWBW.java to a class file of ocfLZWBW.class (no errors) in eclipse added the ocfLZWBW.class files in eclipse i see public class my.nice.lzw.ocfLZWBW when i use the class file editor added (let [oi (my.nice.lzw.OcfLZWBW.) buff buffout] ;; instantiate an object of that class (.expand oi buff buffout)) ;; call its expand() method fired up the repl get a compilerexception java.lang.ClassNotFoundException: my.nice.lzw.ocfLZWBW On Friday, March 28, 2014 12:15 PM, Tassilo Horn t...@gnu.org wrote: bww00amd...@yahoo.com bww00amd...@yahoo.com writes: I have read so much i cant see the tree for the forest. and need some help calling the ocfLZW class below from clojure. If that's really the complete class definition... /* */ public class OcfLZW /* */ { ... then you can't use it from Clojure because it's defined in the default package. There's no way to refer to such classes from any other package except from the default package itself (no matter if from Clojure or Java). Solution: Add a package my.nice.lzw; to the top of the java file. Then you can instantiate it and call its method's from Clojure like so: (let [oi (my.nice.lzw.OcfLZW.) ;; instantiate an object of that class s-inefficient ... out ...] (.expand oi s-inefficient out)) ;; call its expand() method HTH, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Junior or Senior Clojure Developer wanted - Banking, London
For London based Clojure roles, you may want to consider posting in https://groups.google.com/forum/#!forum/london-clojurian-jobs :) On Friday, 21 February 2014 17:08:50 UTC, Jonny Kaye wrote: Hi All, I have a role within a leading Investment Bank based in London, looking for an experienced Clojure developer. If you have a knowledge or commercial experience with Scala or Java then that would be desirable. If you have worked on a Grid computing platform, this will also put you at an advantage. Looking for a hardcore programmer through and through, someone who enjoys solving puzzles and has experience with Data structures. The role is at AVP level, so mid- senior, and you would be situated in the front office, so the ideal candidate will be a very good communicator. If you are eligible to work in the UK without requiring sponsorship, please call me on 02076085820 to discuss. Permanent position paying between £55,000- 85,000 dependent on experience. If you happen to know of anybody who is a solid Clojure developer with any of the other skills listed above, My company offer generous referral fees. Please do get in touch if interested, and send your CV to jonath...@cititec.com. Thank you, Jonathan Kaye -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.