Re: [ANN] Discontinuing 4clojure.com

2021-07-13 Thread Alan Malloy
oring one of these groups over the others. On Monday, July 12, 2021 at 9:13:09 PM UTC-7 brando...@gmail.com wrote: > Thank you Alan for all the work and time put into 4clojure, and thank > those of you who've started and contributed to 4ever-clojure! > > Cheers, > Bran

Re: [ANN] Discontinuing 4clojure.com

2021-07-11 Thread Alan Malloy
I've also exported the problem data: https://drive.google.com/file/d/1hHrygxAs5Do8FpHC9kphYnmyTwZvISnb/view?usp=sharing. On Sunday, July 11, 2021 at 2:22:33 PM UTC-7 Alan Malloy wrote: > I'm happy to see this project, and I think exporting some data is a > reasonable comprom

Re: [ANN] Discontinuing 4clojure.com

2021-07-11 Thread Alan Malloy
>> live on. >> >> Cheers, >> Srihari >> >> On Tuesday, July 6, 2021 at 1:12:44 PM UTC+5:30 Robert P. Levy wrote: >> >>> Hi Alan, >>> >>> Just as a thought. If it's minimal work on your end (eg. if the folks >>> from Roam

[ANN] Discontinuing 4clojure.com

2021-07-04 Thread Alan Malloy
TL;DR: Turning off 4clojure.com by the end of July 2021 Hello, 4clojure problem solvers. You've probably noticed SSL errors on 4clojure.com over the last week. The old decrepit system 4clojure runs on has finally gotten out of date enough that I can't even figure out how to get it recent enough

Re: Strictly tagged clojure

2015-08-08 Thread Alan Malloy
> >> Hey Reid, >> >> I've forwarded this over to Rich and Stu to take a look at. >> >> Alex >> >> On Thursday, August 6, 2015 at 11:46:09 AM UTC-5, Reid McKenzie wrote: >>> >>> Hello all, >>> >>> Alan Malloy an

Re: Size of Java serialized Clojure data structures

2015-08-07 Thread Alan Malloy
You must be doing something wrong, or describing your method badly, because the vector [:a1 1] doesn't take nearly that much space in my experiments. The first object you write to a stream requires quite a bit of overhead, but after that future objects are relatively cheap. Here's an example you

Re: [ANN] lein-4clj

2014-03-19 Thread Alan Malloy
Can you explain the difference between this and https://github.com/bfontaine/lein-fore-prob? I haven't really looked since back when https://github.com/broquaint/lein-foreclojure-plugin was new (in lein 1!), but it seems like there is a lein2 plugin already. On Wednesday, March 19, 2014 4:37:46

Re: Is ^{:once true} still necessary for lazy-seqs?

2014-02-20 Thread Alan Malloy
^:once is absolutely needed for lazy seqs, because it allows the closed-over variables to get cleared while the lambda is *still running*, rather than waiting for it to finish. You can see the difference in this repl session: user> (let [x (for [n (range)] (make-array Object 1)), f (^:once

Re: Project Euler problem in clojure

2013-06-20 Thread Alan Malloy
More importantly than any of these things, he is hanging onto the head of a very, very large sequence with (def lazytri (map triangle (range))). This will lead to serious memory pressure, and perhaps eventually a slowdown as this sequence takes up all the memory in his app and the GC strains to

Re: type-hints positioning convention?

2013-06-17 Thread Alan Malloy
Typehints for functions are only useful on vars. There is no code anywhere, as far as I know, that looks at the metadata attached to anonymous functions. On Monday, June 17, 2013 11:04:45 AM UTC-7, Ambrose Bonnaire-Sergeant wrote: > > I'm not sure. I guess we're stuck with tagging locals at that

Re: possible side-effect/problem in http://clojure.org/concurrent_programming

2013-06-14 Thread Alan Malloy
The laziness of map is irrelevant here, because .invokeAll is treating it as a collection and realizing it all immediately. Your version with for is just as lazy. What's actually changed is that your map and for produce entirely different outputs: the version with map calls test-fn, and the ver

Re: "I don't feel the absence of a debugger, because I've learnt enough that I don't ever need a debugger."

2013-05-28 Thread Alan Malloy
On Tuesday, May 28, 2013 1:01:46 PM UTC-7, Ben Mabey wrote: > On 5/28/13 1:05 PM, Lee Spector wrote: > > On May 28, 2013, at 2:40 PM, Ben Mabey wrote: > > The flag is a system property: > "-Dclojure.compiler.disable-locals-clearing=true". So you can add that > string to your project.clj's :

Re: Bug in transients: Cannot add more than 8 items to a transient map

2013-05-11 Thread Alan Malloy
Also, maps don't have an ordering, so the function is misguided by definition. You can use a sorted-map, if having the map's keys is very important to you, but generally it's just confusion that leads to wanting this in the first place. If you do decide the map must be sorted in a specific orde

Re: Quick question on protocols

2013-05-10 Thread Alan Malloy
case > - much like extend-type default in ClojureScript. > > > On Fri, May 10, 2013 at 6:06 PM, Alan Malloy > > wrote: > >> Even when the interface and class you've extended them to are related by >> inheritance? I thought the most-derived implementation was

Re: Quick question on protocols

2013-05-10 Thread Alan Malloy
Even when the interface and class you've extended them to are related by inheritance? I thought the most-derived implementation was chosen, and only when there's a "tie" like a class that implements two unrelated interfaces, both of which have had the protocol extended to them. If it were comple

Re: style questions -- clojure newbie

2013-04-23 Thread Alan Malloy
Raynes recently released https://github.com/Raynes/least, a Clojure client for the last.fm API. Have you looked into just using his, rather than reinventing the API layer yourself? On Tuesday, April 23, 2013 2:12:37 PM UTC-7, Huey Petersen wrote: > > Howdy, > > I'm a clojure fan but quite new to

Re: Arrays and indexes

2013-04-18 Thread Alan Malloy
(for [[y cols] (map-indexed vector rows) [x cell] (map-indexed vector cols)] (display cell y x)) ? On Thursday, April 18, 2013 3:14:19 AM UTC-7, edw...@kenworthy.info wrote: > > So, I want a 2 dimensional array. > > I think the best way to implement this is a vector of vectors. > > Now I

Re: Type hinting generated functions

2013-04-15 Thread Alan Malloy
If all the functions you want to generate accept doubles, you can just modify str-sym to include a (with-meta (symbol ...) {:tag 'double}) and it should generate exactly the code in your hand-written version. As an aside, there's no reason for str-sym to be a macro: it should just be a function

Re: Difficulty working with complex protobuf objects [protobuf "0.6.2"]

2013-04-11 Thread Alan Malloy
0.6.2 is six months old. I don't think anything about this has changed since then, but you should at least try [org.flatland/protobuf "0.7.2"] and see if that does what you expect. On Thursday, April 11, 2013 8:39:12 AM UTC-7, David Pidcock wrote: > > > I have some Java classes generated elsewhe

Re: Function recurring regardless of condition

2013-04-08 Thread Alan Malloy
You might be interested in https://github.com/amalloy/clusp/blob/master/src/snusp/core.clj, my Clojure interpreter for SNUSP (which is brainfuck with different control-flow mechanics). It's purely functional, and IMO does a good job of separating concerns; both of those are things it sounds lik

Re: -> operator and monads

2013-04-03 Thread Alan Malloy
Not even that: -> is not a function composition operator at all, but a form-rewriting macro. You can perfectly well write (-> [x xs] (for (inc x))) to get (for [x xs] (inc x)), and that is not composing any functions. The two things are entirely separate. On Wednesday, April 3, 2013 12:45:55 PM

Re: Attempt at rethrow macro

2013-04-01 Thread Alan Malloy
This is how every macro and special form works. I know you like to complain, but the alternative is simply not possible: macros have complete control of expanding their bodies, and any macros therein are expanded later, not before. Try writing a macro system that goes the other way, and see how

Re: Attempt at rethrow macro

2013-04-01 Thread Alan Malloy
On Monday, April 1, 2013 10:26:43 AM UTC-7, Alf wrote: > I am guessing the problem is that the rethrow macro is expanded and passed > to the reader/compiler before the handle-ex macro is. And at that point the > compiler sees catch as a "standalone-symbol", not as part of the try > special form

Re: Floating point comparator issue?

2013-03-29 Thread Alan Malloy
Comparator.compare returns an int. (int 0.2) and (int -0.2) both return 0. Thus, your comparator is returning 0, saying "I don't care what order these go in". On Mar 29, 6:44 pm, JvJ wrote: > Alright check this out: > > ;; Normal subtraction as comparator sorts in ascending order > (sort-by ident

Re: Quirk with printing regexps

2013-03-28 Thread Alan Malloy
On Thursday, March 28, 2013 5:36:45 PM UTC-7, Andy Fingerhut wrote: > > I don't understand why (re-pattern "a\\\nb") would match the same thing. > I would have guessed that it wouldn't, but it does indeed do so. For all I > know that could be bug or weird dark corner case in the Java regex >

Re: Working with a huge graph - how can I make Clojure performant?

2013-03-28 Thread Alan Malloy
Have you looked at https://github.com/jordanlewis/data.union-find ? Personally, I'd prefer it to Christophe's implementation, since his blog post seems to start with "I dislike this algorithm"; I also helped out a bit in writing this version. On Monday, March 11, 2013 10:37:39 AM UTC-7, Balint

Re: Map destructuring variations in Pedestal

2013-03-20 Thread Alan Malloy
Yes. Apparently you can put whatever garbage you want into the `:or` map: each local is looked up in that map to see if it has a default, but nobody ever checks to see if there are unused keys in the defaults map. So `:or {::type :jety}` has no impact at all on the generated code: there is no l

Re: set!

2013-03-13 Thread Alan Malloy
On Wednesday, March 13, 2013 2:46:06 PM UTC-7, puzzler wrote: > On Wed, Mar 13, 2013 at 2:06 PM, Marko Topolnik > > > wrote: > > >> As far as I understand it, *set!* modifies the *thread-local* binding, >> just like the *binding* macro, but doesn't delimit a definite scope of >> validity for t

Re: Like "if", but it composes functions

2013-02-20 Thread Alan Malloy
36 AM UTC-8, Laurent PETIT wrote: > > Hello, > > Why the names fix / to-fix ? > > 2013/2/20 Alan Malloy >: > > Useful has functions that do this and more: fix or to-fix, according to > > taste. Your iffn is just the three-argument case of to-fix: (def magnify >

Re: Like "if", but it composes functions

2013-02-19 Thread Alan Malloy
Sorry, forgot to link to useful: https://github.com/flatland/useful/blob/develop/src/flatland/useful/fn.clj#L30 On Tuesday, February 19, 2013 9:53:57 PM UTC-8, James MacAulay wrote: > > Sometimes I find myself writing code like this: > > (defn magnify [n] (if (pos? n) (inc n) (dec n))) > > ...an

Re: Like "if", but it composes functions

2013-02-19 Thread Alan Malloy
Useful has functions that do this and more: fix or to-fix, according to taste. Your iffn is just the three-argument case of to-fix: (def magnify (to-fix pos? inc dec)). But fix and to-fix accept more or fewer arguments as well, so that (fix x pos? inc) is like (if (pos? x) (inc x) x), and (to-f

Re: What compiles into a method body?

2013-02-04 Thread Alan Malloy
Basically each lambda compiles into a method body, and the size of its lexical environment doesn't matter very much, only the amount of code inside the lambda's (fully macroexpanded) body. So in (fn a [x] (foo (letfn [(b [] (bar)) (c [] (baz))])), a only "pays for" foo, and b and c pay for bar

Re: How to solve Collatz Conjecture problem for huge numbers using clojure parallelism tricks?

2013-02-01 Thread Alan Malloy
(max-key :power mario luigi) On Thursday, January 31, 2013 6:08:21 PM UTC-8, Leandro Moreira wrote: > > Running through this problem I also faced the weird situation, so: > > Given two maps > (def mario {:color "red" :power 45}) > (def luigi {:color "green" :power 40}) > > I want the max between b

Re: why did lein just download Clojure 1.5?

2013-01-29 Thread Alan Malloy
`lein deps :tree` will show you the tree of dependencies, and you can see which of your dependencies has a bad dependency specification overriding the one in your project.clj. Typically it turns out a dependency is saying something like "I must have the very latest Clojure, whatever that is", w

Re: special case in binding vector syntax for function definitions?

2013-01-25 Thread Alan Malloy
In (let [[x :as y] [1 2]]), there is already an object to make y "point to": the vector [1 2]. in ((fn [x :as y]) 1 2), there is no such object. On Friday, January 25, 2013 2:18:39 PM UTC-8, Ben wrote: > > Both of these work: > > user> (let [[x & y] [1 2]] [x y]) > [1 (2)] > user> (let [[x :as

Re: CLJS: protocol interfaces don't seem to support variable args in the arglist, like [ & opts]

2013-01-16 Thread Alan Malloy
On Wednesday, January 16, 2013 11:17:41 AM UTC-8, Aaron Cohen wrote: > On Wed, Jan 16, 2013 at 12:53 PM, Frank Siebenlist > > > wrote: > >> Thanks for the confirmation. >> >> I know that destructuring is supported in protocols as I'm using with >> much pleasure - kind of assumed it would work a

Re: Is keyword-params middleware safe?

2013-01-16 Thread Alan Malloy
Keywords are garbage-collected if no references to them exist. I think this is as of Clojure 1.3, but I'm not sure exactly; perhaps it's always been true. You can see it easily enough at https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java#L32 - there's a map from s

Re: replacing specific symbols in arbitrary expressions

2013-01-14 Thread Alan Malloy
(clojure.tools.macro/symbol-macrolet [P +, M -, T *] ...) The tools.macro code-walker is much smarter and more careful than any that you or I will ever write. On Monday, January 14, 2013 3:31:40 AM UTC-8, Jim foo.bar wrote: > > Hi everyone, I hope you're all well! > > I recently faced a probl

Re: clojurescript gensym does not generate a unique symbol?!

2013-01-04 Thread Alan Malloy
Certainly it does work the same way in JVM-Clojure: user=> (gensym) G__1278 user=> (gensym) G__1281 user=> (gensym) G__1284 user=> (= 'G__1287 (gensym)) true Whether that's a bug or a case of "If it breaks when you do that, then don't do it" isn't for me to say, but I would be pretty surprised t

Re: zip-reduce

2012-12-24 Thread Alan Malloy
Except of course zip-seq doesn't need the f, acc arguments. Sorry about that. On Monday, December 24, 2012 7:18:17 PM UTC-8, Alan Malloy wrote: > > Probably better to write it more generally, by creating a seq from a > zipper and then just using the ordinary reduce functi

Re: zip-reduce

2012-12-24 Thread Alan Malloy
Probably better to write it more generally, by creating a seq from a zipper and then just using the ordinary reduce function on that zip: (defn zip-seq [f acc z] (map node (tree-seq branch? children z))) (reduce f acc (zip-seq some-zipper)) On Monday, December 24, 2012 6:27:00 PM UTC-8, JvJ w

Re: inserting code into reify methods

2012-12-24 Thread Alan Malloy
You don't need any of the typehints in your reify body. The compiler infers argument and return types from the interface definition. On Monday, December 24, 2012 5:35:35 AM UTC-8, nkonovalov wrote: > > Hi. > > I have a java interface. > Something like this this. > > public interface ITest { >

Re: Confused about comp

2012-12-15 Thread Alan Malloy
Nonsense. Why would that be any faster? (join coll) is defined as (apply str coll). On Saturday, December 15, 2012 12:21:45 PM UTC-8, Marek Šrank wrote: > > ...which should be also a lot faster :) > > On Saturday, December 15, 2012 5:44:01 PM UTC+1, Armando Blancas wrote: >> >> (comp (partial app

Re: Strange behaviour: nested def in proxy method body

2012-12-13 Thread Alan Malloy
On Thursday, December 13, 2012 4:14:23 AM UTC-8, Marshall Bockrath-Vandegrift wrote: > kristianlm > writes: > > > I'm enjoying testing Java code with Clojure and it's been a lot of fun > > so far. Coming from Scheme, the transit is comfortable. However, I > > encountered a big surprise when I

Re: Specific reduce function version

2012-12-09 Thread Alan Malloy
You seem to have written (reduce (fn [acc [a b]] ...) (partition 2 1 coll)). On Sunday, December 9, 2012 7:39:21 AM UTC-8, Alexander Semenov wrote: > > Hi, folks. > > I'm wondering if Clojure library has 'reduce' function version which is > like (reduce f coll) - i.e. it applies function to coll

Re: Sorted Sets With Duplicate Elements

2012-11-20 Thread Alan Malloy
On Tuesday, November 20, 2012 10:29:18 AM UTC-8, Andy Fingerhut wrote: > > > On Nov 20, 2012, at 10:12 AM, Mark Engelberg wrote: > > > Clojure's sorted collections must be provided with a sorting function > where items "tie" if and only if they are equal. > > > > (sorted-set-by #(compare [(se

Re: Proposed change to let-> syntax

2012-11-15 Thread Alan Malloy
The primary point of let-> is that you can insert it into an existing -> pipeline. (-> foo (stuff) (blah) (let-> foo-with-stuff (for [x foo-with-stuff] (inc x))) Your proposal breaks this. On Thursday, November 15, 2012 10:35:59 AM UTC-8, Alex Nixon wrote: > > Hi all,

Re: Difference between JVM and CLR when destructuring a lazy sequence

2012-11-15 Thread Alan Malloy
Binding to [& rst] must realize an element of the sequence, to determine if there are any left, and it promises to never bind (), only nil. On Thursday, November 15, 2012 7:23:05 AM UTC-8, ffailla wrote: > > I believe I have discovered differing behavior between the JVM and CLR > implementations

Re: How to get the namespace for an unqualified symbol?

2012-11-12 Thread Alan Malloy
Yikes! Try ((juxt (comp ns-name :ns) :name) (meta (resolve 'inc))) - name information is stored on the var's meta in a clojure-friendly way - no need to use undocumented behavior on the java internals. On Monday, November 12, 2012 11:05:15 AM UTC-8, Ambrose Bonnaire-Sergeant wrote: > > Evil, bu

Re: Proposal/request: Give clojure.core/conj a unary implementation

2012-11-03 Thread Alan Malloy
There is never a reason to write (apply conj ...). Instead, use `into`, which does the same thing but faster and with fewer characters. On Saturday, November 3, 2012 3:27:24 PM UTC-7, CGAT wrote: > > It would be nice if clojure.core/conj had a unary implementation > >([coll] coll) > > Th

Re: downcast

2012-10-24 Thread Alan Malloy
Clojure doesn't care about casting, so you can ignore this issue entirely. But also, it's not an issue: the same code would fail in Java, because Clojure's integer literals are Long, not Integer. (cast Long (cast Number 1)) would work fine. On Oct 24, 2:12 pm, Steffen Panning wrote: > Hello Group

Re: Redubicle NIO

2012-10-18 Thread Alan Malloy
As a general-macro aside, you are multiply-evaluating the `f` argument, by expanding it in-place inside the recursive clause. This is almost certainly not what you want, and you could avoid it by starting with (let [f# ~f] ...). Better still, ask why this is a macro at all. This should really just

Re: Replacing nested let statements with assignments

2012-10-18 Thread Alan Malloy
On Oct 18, 12:02 pm, David Nolen wrote: > On Thu, Oct 18, 2012 at 2:55 PM, Alan Malloy wrote: > > It's rare to get tired of this, because nobody does it: it's not > > common because your interleaved statements are side-effecting only, > > which is not encourage

Re: Replacing nested let statements with assignments

2012-10-18 Thread Alan Malloy
It's rare to get tired of this, because nobody does it: it's not common because your interleaved statements are side-effecting only, which is not encouraged in Clojure, and rarely needed. Certainly sometimes it's the best way to do something, but not so often that I'd become frustrated; if anything

Re: parallel alpha-beta pruning possible?

2012-10-16 Thread Alan Malloy
You will get better results from a game-programming forum, or indeed from a google search for "parallel alpha beta" than from a bunch of clojure guys with no particular experience in your problem domain. On Oct 16, 1:27 pm, "Jim - FooBar();" wrote: > After watching this presentation[1] by Brian G

Re: trampoline not compatible with reducers?

2012-10-16 Thread Alan Malloy
Reducers don't enter into the picture at all: this code is just as broken with clojure.core/reduce and clojure.core/map. The immediate problem that Kevin is trying to draw your attention to is that you are calling (reduce max (map my-fn coll)), where my-fn sometimes returns a number, and sometimes

Re: Evaluating an anonymous function with closure

2012-10-15 Thread Alan Malloy
On Oct 15, 1:07 pm, "Jim - FooBar();" wrote: > On 15/10/12 19:42, Ben Smith-Mannschott wrote: > > > If the distinction I'm trying to make is not clear to you, I'd suggest > > having a look athttp://www.infoq.com/presentations/Clojure-Macros (It > > does a good job exploring these kinds of distinct

Re: Evaluating an anonymous function with closure

2012-10-15 Thread Alan Malloy
Evaluating function literals is not intended to work; that it works for non-closure functions should be treated as a coincidence. On Oct 15, 2:19 am, Gergely Szabó wrote: > Hello, > > could someone please explain the behavior that is shown in the gist below? > > https://gist.github.com/3891587 >

Re: Evaluating an anonymous function with closure

2012-10-15 Thread Alan Malloy
Evaluating function literals is not intended to work; that it works for non-closure functions should be treated as a coincidence. On Oct 15, 2:19 am, Gergely Szabó wrote: > Hello, > > could someone please explain the behavior that is shown in the gist below? > > https://gist.github.com/3891587 >

Re: Intern a var from outside namespace

2012-10-11 Thread Alan Malloy
On Thursday, October 11, 2012 9:03:38 PM UTC-7, David Jacobs wrote: > > I would like to create function names programmatically. So far, I have > code that works: > ... > Where am I going wrong? > > David > Sentence one. Don't do it that way: namespaces are not very good hashmaps, but hashmaps

Re: apply: increase performance by 60% for fixed length

2012-10-07 Thread Alan Malloy
On Sunday, October 7, 2012 7:56:53 PM UTC-7, Ben wrote: > > On Sun, Oct 7, 2012 at 3:53 PM, Alan Malloy > > wrote: > > This is nonsense. If s is fixed-size at compile-time, you would never > use > > apply to begin with. Why bother with (applyn 10 + [1 2 3 4 5 6

Re: apply: increase performance by 60% for fixed length

2012-10-07 Thread Alan Malloy
This is nonsense. If s is fixed-size at compile-time, you would never use apply to begin with. Why bother with (applyn 10 + [1 2 3 4 5 6 7 8 9 10]) when you could just write (+ 1 2 3 4 5 6 7 8 9 10)? On Sunday, October 7, 2012 2:15:28 PM UTC-7, Marc Dzaebel wrote: > > *apply *is slow. However yo

Re: comp inside macro

2012-09-26 Thread Alan Malloy
(a) There's no reason for this to be a macro at all: you don't need to prevent evaluation of anything, and you don't need to transform any syntax. Just write a function: (defn asdf [& {:keys [a]}] (println (comp (partial + 1) a))) (b) To make this a macro, just be more careful about what you evalu

Re: Nested functions on #() reader

2012-09-17 Thread Alan Malloy
Indeed, there's no need for anything to be a reader macro, except concision. You can write this as an ordinary macro, eg, (crazy-fn %a %%b %%%c). If you try that and find it's awesome, share it with others. If it's universally loved, perhaps someday it could be a reader macro. On Monday, Septem

Re: Sort and Java 1.7

2012-09-12 Thread Alan Malloy
Vote to close as "not a real question". The signature of java.util.Collections/sort hasn't changed since 1.5, when generics were introduced, and it should still be basically compatible with what it was when it was introduced in 1.2. On Wednesday, September 12, 2012 5:54:22 AM UTC-7, Canonical.C

Re: reporting function inputs as part of exceptions

2012-09-03 Thread Alan Malloy
Slingshot's throw+ generates an exception object that includes, among other things, all the locals in the context of your throw. On Monday, September 3, 2012 9:03:42 PM UTC-7, Timothy Pratley wrote: > > I'm working on a project where it would be quite convenient to have the > input values to the

Re: using take-while with pred function that has state

2012-09-03 Thread Alan Malloy
(map #(do %2 %1) c1 c2) is a neat trick I hadn't seen in this context; thanks for showing me! On Sunday, September 2, 2012 10:26:07 PM UTC-7, Stephen Compall wrote: > > On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: > > I have written the following function using take-while and a pred > >

Re: Howto not reindent in (emacs) clojure-mode

2012-08-26 Thread Alan Malloy
I just use C-j instead of RET in the rare cases that I want to leave the previous line alone. On Sunday, August 26, 2012 4:15:54 PM UTC-7, frye wrote: > > Hey all, > > > There'll probably be a quick solution to this. But I have emacs with > clojure-mode installed. And it has this very annoying

Re: clojure.logic project.clj file

2012-08-15 Thread Alan Malloy
Blech. I've found having the project.clj helpful myself for the same reason David has: it's easy to start up lein (swank or repl) and hack around. I'm opposed to removing it unless there's someone it's actually hurting. On Wednesday, August 15, 2012 3:00:27 PM UTC-7, Sean Corfield wrote: > > On

Re: Pattern of Succinctness

2012-08-12 Thread Alan Malloy
This doesn't work. On Sunday, August 12, 2012 12:44:11 PM UTC-7, Pierre-Henry Perret wrote: > > I prefer (filter (partial not nil?) coll) as a HOF > > Le dimanche 12 août 2012 20:46:59 UTC+2, rmarianski a écrit : >> >> On Sun, Aug 12, 2012 at 11:22:55AM -0700, Takahiro Hozumi wrote: >> > > (fil

Re: Writing code to get the source of a function

2012-08-08 Thread Alan Malloy
(println (with-out-str (foo))) is silly - it's the same as (do (foo) nil), which in many cases (eg, in this one) is the same as just (foo). On Wednesday, August 8, 2012 6:25:35 AM UTC-7, Joshua Ballanco wrote: > > On Wed, Aug 08, 2012 at 09:19:15AM +, Samuel Lê wrote: > > Dear all, > > > >

Re: serlization of map ---- Invalid token: :

2012-08-06 Thread Alan Malloy
You are attempting to serialize the empty keyword. The empty string, "", is fine to store, but : is not. You will get the same error from (read-string ":"). On Monday, August 6, 2012 4:55:23 AM UTC-7, 4m1r wrote: > > I am using Storm which is based on Clojure. while emitting a map which has > k

Re: reduction to tail recursion

2012-07-23 Thread Alan Malloy
I don't see how the definition of primitive-recursive is relevant to this. You can transform primitive recursion to tail recursion if you allocate a "stack" of your own on the heap, and don't mind that it might grow without bound. Or you can transform to continuation-passing or trampolines (fun

Re: s-expression levels and higher order functions

2012-07-19 Thread Alan Malloy
No, but it's pretty easy to write: (defn map-depth [f coll depth] (if (zero? depth) (map f coll) (for [x coll] (map-depth f x (dec depth) On Tuesday, July 17, 2012 7:17:19 PM UTC-7, Seth Chandler wrote: > > I'm new both to Clojure and to this group, so please be gentle. I com

Re: atom and lock

2012-07-18 Thread Alan Malloy
Sorta off-topic from the main discussion, but in reference to the error you pointed out, one clever fix for this is to add a delay around the future: (defn cache-image [icache url] (let [task (delay (future (download-image url)))] (doto (swap! icache update-in [url] #(or % task)) (->

Re: Concatenating InputStreams (was: Re: Parsing SGML)

2012-07-13 Thread Alan Malloy
y on Earth not?), but it's still intended to be used by Clojure code. On Friday, July 13, 2012 12:40:07 PM UTC-7, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am 13.07.2012 um 19:25 schrieb Alan Malloy: > > > (defn coll->enumeration [coll] > > (clojure.lang

Re: Concatenating InputStreams (was: Re: Parsing SGML)

2012-07-13 Thread Alan Malloy
(defn coll->enumeration [coll] (clojure.lang.SeqEnumeration. coll)) On Friday, July 13, 2012 7:13:54 AM UTC-7, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > I think you don't handle the switching of streams correctly. You have to > keep track with atoms. But then you run into thread-safety is

Re: Parsing SGML

2012-07-10 Thread Alan Malloy
Just create a Reader over the file, and do something like (take-while identity (repeatedly #(read-one-wellformed-xml-tag the-reader))). It needs some fleshing out for boundary conditions, but I hope you get the general idea. On Tuesday, July 10, 2012 6:04:23 AM UTC-7, Wolodja Wentland wrote: >

Re: mutual reference in FP style

2012-07-06 Thread Alan Malloy
If the value is something easy to compute, like a backreference in a tree, and you only need it while walking, why bother to store it at all? Especially if you're going to need to use mutable state, which will make your whole tree less useful for all kinds of things. Here's an example, in which

Re: idempotency

2012-06-30 Thread Alan Malloy
That's really a stricter requirement than idempotence (ie, functional purity). I don't believe the compiler ever does this. The JVM might, if it's able to inline some particular method call and discover therein that no mutation happens, but that's probably pretty rare given the amount of indire

Re: aot compilation of clojure source code...

2012-06-21 Thread Alan Malloy
On Thursday, June 21, 2012 2:36:21 PM UTC-7, Phil Hagelberg wrote: > > "Jim - FooBar();" writes: > > > Yes ok I do get that...but wouldn't you agree that is slightly easier > > for plain Java than it is for clojure? Especially for someone that has > > no idea how the clojure compiler works...fo

Re: How to do aynchrounous producer/consumer

2012-06-15 Thread Alan Malloy
(map consume (seque (produce-lazily))) On Friday, June 15, 2012 6:44:39 PM UTC-7, Warren Lynn wrote: > > > What I want to do is something I probably have done dozens of times in > C++: two threads, one thread putting items in a queue, another taking it > out (FIFO). How to do it in Clojure? I am

Re: Using read-string and macros together

2012-06-13 Thread Alan Malloy
This can't work as a macro - Sean's suggestion is just as broken as yours, in that it needs the form supplied to be a compile-time literal, because macros are expanded at compile-time. You can do this at runtime with eval: something like (defn xr [s] (eval `(fn [] ~(read-string s, though of

Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-13 Thread Alan Malloy
useful has a partition functionpowerful enough to make the "find increasing subsequences" part pretty easy: (defn lis [coll] (or (->> coll (partition-between (partial apply

Re: If a protocol creates a Java interface under the covers...

2012-06-12 Thread Alan Malloy
On Jun 12, 5:56 am, "Jim - FooBar();" wrote: > On 12/06/12 13:53, Jim - FooBar(); wrote: > > > On 12/06/12 13:47, Meikel Brandmeyer (kotarak) wrote: > >> If update-position is a protocol function just call it without the > >> dot. Just like a normal function. Then any reflection will go away > >>

Re: using -> on a nested hash-map with string keywords.

2012-05-31 Thread Alan Malloy
Yes, but really to GET a value nested IN a series of maps, he should just be using get-in, rather than threading anything at all. On May 31, 7:59 am, Dave Ray wrote: > Keywords implement IFn meaning they can act as functions that look > themselves up in a map. Strings are just strings. Replace "b

Re: Recursive lets

2012-05-29 Thread Alan Malloy
On May 29, 9:54 am, "nicolas.o...@gmail.com" wrote: > Is there a way to write something like: > > (let [x (foo1 (fn []  (bar y))) >       y  (foo2 x)]   ) > > where the y on line 1 refers to y in line 2? > > I currently use an atom and an affectation to "tie the loop"... I agree with the othe

Re: Do you leave a Swank / nREPL in your production servers?

2012-05-25 Thread Alan Malloy
On May 25, 2:30 pm, Sean Corfield wrote: > The :host specifies the IP (or hostname) to listen on so if you want > external access you'll need to listen on an IP that is externally > accessible. If you listen on "0.0.0.0" then it'll listen on any IP > address so you can REPL in from outside as well

Re: Idiomatic usage of partial

2012-05-17 Thread Alan Malloy
#() syntax can accept as many arguments as you like. For example, you can define partial using #(): (defn partial [f & args] #(apply f (concat args %&))) On May 16, 7:13 pm, greg r wrote: > The reader notation is limited to the arity of the number of arguments > provided.  partial allows varia

Re: NullPointerException

2012-05-17 Thread Alan Malloy
"There's nothing wrong" is a pretty strong statement. It works, but it is definitely the wrong way to do things. Using a letfn, or external helper functions, is a much better approach. On May 17, 12:19 pm, Armando Blancas wrote: > The redefinition of functions somehow is spooking the compiler. Bu

Re: Idiomatic usage of partial

2012-05-16 Thread Alan Malloy
On May 16, 2:05 pm, Stuart Sierra wrote: > Every literal instance of `fn` or `#()` compiles to a new class definition. > This is only at compile time: once the code is running, each execution of > the `fn` expression merely creates an instance of that class. > > partial is implemented in terms of

Re: Partitioning a list when the result of a predicate becomes a certain value.

2012-05-10 Thread Alan Malloy
On May 10, 3:19 pm, Jack Moffitt wrote: > >    (when-let [s (seq coll)] > >      (let [run (cons (first s) (take-while #(not= value (f %)) (next > > s)))] > >       (cons run (partition-when f value (seq (drop (count run) s > >      ) > >    ) > >  ) > > ) > ... > > What test? > > (seq coll) i

Re: Partitioning a list when the result of a predicate becomes a certain value.

2012-05-10 Thread Alan Malloy
https://github.com/flatland/useful/blob/develop/src/useful/seq.clj#L189 is a more general version of partition-by, which can easily handle your requirements. On May 10, 2:11 pm, Ant wrote: > Hi all, > > I am battering my head against the following problem which I'm sure is > straightforward if on

Re: Reducers

2012-05-08 Thread Alan Malloy
My understanding is that reducers/map merely returns a new function (or something like a function, maybe an instance of IReducible or something), and all actual computation is done during the reduce. So dynamic bindings around the scope of the map have no effect at all. On May 8, 10:57 am, Mark En

Re: LinkedHashMap not well supported

2012-04-30 Thread Alan Malloy
On Apr 30, 7:53 pm, kurtharriger wrote: > Sounds good. Ill submit a patch for walk. Im not real sure why apply hash-map > didnt work, but if figure it out Ill add that too. For the same reason that (apply hash-map {1 2, 3 4}) doesn't work: the maps seqs as ([1 2] [3 4]), not as (1 2 3 4). -- Y

Re: Typed Clojure 0.1-alpha2

2012-04-21 Thread Alan Malloy
He did say, compile-time error. These errors are at run-time - that is, the following is just as obviously bad, but generates no warning until bar is called: (defn foo [x] 1) (defn bar [y] (foo y 1)) ;; compiles fine (bar 5) ;; throws runtime exception On Apr 21, 5:14 pm, Softaddicts wrote: >

Re: Treatment of nil/null in a statically typed Clojure

2012-04-19 Thread Alan Malloy
On Apr 19, 4:06 pm, James Reeves wrote: > On 19 April 2012 19:46, Ambrose Bonnaire-Sergeant > > wrote: > > I've been doing some thinking about the treatment of nil in a > > statically typed version of Clojure. > > Statically typed in what way? Java's type system doesn't seem > particularly suited

Re: a convenience idea for test functions

2012-04-17 Thread Alan Malloy
IMO this is fairly absurd for a language default, but you can easily do this yourself in a number of ways. For example: (defmacro define-preds [& preds] (cons `do (for [pred preds] `(defmacro ~(symbol (str pred "+")) ~'[obj then else] (list '~'if (list '~pred ~'obj

Re: Should I better use a state monad (and how)?

2012-04-16 Thread Alan Malloy
On Apr 15, 8:25 pm, Nicolas Buduroi wrote: > I'm working on a turn-based game and I'm looking for a good way to manage > states. In the game each turn is composed of multiple phases. I started by > using atoms for the phases field (this is a sequence of functions) in a > record and realized that i

Re: where do you put the docstring in a deftype declaration?

2012-04-12 Thread Alan Malloy
A deftype creates a java class, not a clojure var. Classes have no slots to store a docstring. Just put a comment somewhere. On Apr 12, 9:52 pm, Frank Siebenlist wrote: > Confusingly yours, FrankS. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

  1   2   3   4   >