Technically, all these solutions are flawed.
With the input
["a" "a" "a_1"]
you'll get back
["a" "a_1" "a_1"]
To truly address this, you need to also add the newly formatted filename
into the "seen" map, which none of the suggested solutions do.
--
--
You received this message because you are
On Fri, Jan 10, 2014 at 11:43 AM, Jonas Enlund wrote:
> That's why I wrote my solution like I did, i.e., concatenate "_1" when a
> new string is found. This would result in the vector ["a_1" "a_2" "a_1_1"]
>
Right, I agree that works, as does my "tack unique numbers onto the end of
everything" so
On Fri, Jan 10, 2014 at 11:52 AM, Colin Yates wrote:
> way to take the wind out of our sails! Well spotted :).
It's not too hard to fix. Here's an adapted version of Jonas' solution
that should do the trick:
(defn uniqueify [items]
(first
(reduce (fn [[results count-map] item]
On Fri, Jan 10, 2014 at 12:55 PM, Colin Yates wrote:
> Being really anal I could claim the original a_2 should remain a_2 and the
> third instance of a jump to being a_3.
>
Sure, but that would require two passes. Otherwise, there's no way when
you encounter the third "a" to know there's an "a
Laurent, your approach doesn't quite work:
=> (uniquify ["a_1" "a" "a"] (fn [s n] (str s \_ n)))
["a_1" "a" "a_1"]
On Fri, Jan 10, 2014 at 1:34 PM, Laurent PETIT wrote:
> okay, new take solving the issue raised by Mark:
>
> (defn uniquify [in format-fn]
> (loop [[item :as in] (seq in)
>
Very clever!
On Fri, Jan 10, 2014 at 8:10 PM, Håkan Råberg wrote:
> Another style, using channels for local state, but could been plain old
> iterators, slight golf warning:
>
> (require '[clojure.core.async :refer [to-chan
> (defn uniquify [s formatter]
> (let [g (memoize #(to-chan (cons % (
If I understand you correctly, this is known as the "union-find" problem.
All you care about is whether two items are in the same component of the
graph. The key here is to keep track of two maps, one map from each item
to a "canonical item" in its component, and one map from each canonical
item
Whoops, typo, should have been:
"(if (<= (count component1) (count component2))"
Corrected:
(defn register-same-as [{:keys [keys->canonical
canonical->components]
:as component-graph}
key1 key2]
(let [canonical1 (keys->canonical key1 key1)
I'm familiar with the path compression technique for union-find, but I tend
not to use it for two reasons:
1. That technique generally assumes you are going to continue to compress
the path with each *find* operation, not just the union. This means you
need to either use a mutable structure or el
Consider the really slow fib function:
(defn fib [n]
(if (< n 2) n (+ (fib (dec n)) (fib (- n 2)
Now, let's say I want to compute the fib of some number n and timeout and
return nil if it takes longer than a second.
(defn try-fib [n]
(let [ch (timeout 1000)]
(go (>! ch (fib n)))
(
So far, this is the only way I've figured out that works:
(defn try-fib [n]
(let [ch (timeout 1000)
th (Thread. #(>!! ch (fib n)))
_ (.start th)
answer (http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Gr
On Wed, Jan 22, 2014 at 2:51 AM, Jozef Wagner wrote:
> You can put the computation into a future, and cancel the future after the
> timeout.
>
I experimented with that, but it didn't seem to work. I suspect that
"canceling a future" doesn't really do what I think it should do. I would
appreciat
ight loop, it must check explicitly
> whether the interrupt flag is set and abort. If it is waiting on some
> resource, it will receive InterruptedException.
>
> Regards,
> Praki Prakash
>
>
> On Wed, Jan 22, 2014 at 11:20 AM, Mark Engelberg > wrote:
>
>> On
If you want to be able to control an arbitrary long-running function, a
> safe way is to run it in a separate process. That way you can safely
> terminate it anytime you want. Of course this opens up a lot of other
> issues :)
>
>
> On Wed, Jan 22, 2014 at 9:15 PM, Mark Engel
So I guess this gets back to my earlier question: when is it safe to
terminate a thread?
I know that I often hit Ctrl-C in the REPL to terminate a long running
function, and I've never really worried about it screwing things up.
On Wed, Jan 22, 2014 at 1:29 PM, Shantanu Kumar wrote:
>
>
> On Th
I thought clj-nstools was for Clojure 1.2 only. Not true?
On Thu, Jan 23, 2014 at 1:07 AM, Konrad Hinsen <
googlegro...@khinsen.fastmail.net> wrote:
> --On 21 janvier 2014 23:15:50 -0800 t x wrote:
>
>I have the following problem:
>>
>> (ns foo.bar
>> ...
>> ...
>> ... )
>>
>> There'
I've been having trouble figuring out how to use clojure.java.jdbc
effectively, for example, how to rename tables, do work in transactions,
etc. Is there full documentation with examples somewhere?
On Fri, Jan 31, 2014 at 11:33 AM, Sean Corfield wrote:
> clojure.java.jdbc - Clojure's contrib l
I'm working on a program that involves deeply nested data structures. I'm
running into numerous problems working with such structures in Clojure. It
appears that many of Clojure's core functions involving hashing and
equality produce stack overflows with deeply nested data structures, making
it n
On Fri, Jan 25, 2013 at 11:54 PM, Christophe Grand wrote:
> Hi Mark,
>
> The hasheq chaching patch got applied between beta1 and beta2 so it's not
> in alpha5.
>
Thanks. I tried the new release candidate, and the caching is definitely
working, but the issues I raised still remain. Specifically,
I haven't had any luck getting Light Table to work on Windows 7, and it's
still in a very rough state. I wouldn't recommend it at this time.
On Sat, Jan 26, 2013 at 10:56 AM, Ryan Cole wrote:
> It's actually pretty simple, if you decide to use leiningen and light
> table, the editor. All you ha
On Sun, Jan 27, 2013 at 12:15 PM, Ryan Cole wrote:
> I guess I don't understand what's so difficult about getting Clojure, or
> Light Table, to work on Windows (7). I literally just installed the JDK,
> put the bin directory of it on my $PATH, and with that alone, Light Table
> will work just fin
As Laurent pointed out, Eclipse Counterclockwise is pretty close to being a
the kind of full-stack snapshot you're looking for, and it works great and
installs easily on Windows. You simply download Eclipse (a zip file which
doesn't really need to be "installed"), run it, and install
counterclockw
I just went through the process of converting my map-based program over to
records, hoping it would improve speed. Much to my dismay, it actually
slowed my program down substantially. With some profiling, I discovered
that one possible explanation is that (at least in RC4) hashing of records
is a
Clojure 1.5 RC-4
--
--
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
;
>>>
>>> => (time (dotimes [n 1000] (hash {:x "a" :y 3})))
>>> "Elapsed time: 70.037502 msecs"
>>>
>>>
>>> => (time (dotimes [n 1000] (hash (A. "a" 3
>>> "Elapsed time: 5307.93947 ms
On Sun, Feb 3, 2013 at 2:42 AM, Shantanu Kumar wrote:
> I was able to shave off some more by writing (not= 0 (rem i d)) as (<
> 0 (rem i d)).
>
Haven't tested, but based on past experience I would expect (not (zero?
(rem i d))) to be the fastest way, or possibly
(pos? (rem i d))
In general, zer
In these examples, the map/record is freshly created each time through the
loop, so caching should not be a factor.
In fact, later in the thread, AtKaaZ posted an example which demonstrated
his timing results when computing the hash repeatedly on the same object.
Oddly, the performance of hashing
Yes, you're misunderstanding sets which, as implemented in Clojure, are
inherently finite. That 4clojure problem is all about learning how to work
with infinite sequences.
I recommend you start by building a helper function that "intersects" two
sorted infinite sequences. It doesn't already exis
Sets are stored in a very specific way that enables intersection to be fast
- proportional to the size of the smaller set.
Intersecting arbitrary sequences can't be done particularly efficiently.
If Clojure's intersection worked on sequences (perhaps by first converting
to sets behind the scenes),
On Fri, Feb 15, 2013 at 8:19 AM, Jules wrote:
> But now you still don't have leiningen, which is essential if you want to
> do anything non toy. The installation page of CCW does describe how to
> create a leiningen project, but doesn't say that you first have to manually
> install leiningen.
>
P.S. I've been very happy with the latest version of leiningen on Windows.
--
--
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 pa
Another idea: try using arrays of longs, rather than ints, since that is
what Clojure prefers.
--
--
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 moder
On Mon, Feb 18, 2013 at 1:41 PM, Tom Hall wrote:
> I think it's a shame he wrote the article around Christmas and chose a
> less well known problem, I have looked at several Clojure Barbershop
> Problem solutions so have a better idea now what an idiomatic solution
> to this sort of problem might
On Fri, Feb 22, 2013 at 7:47 PM, Korny Sietsma wrote:
> Isn't that always the way, though? Build your program in a powerful,
> expressive language, then profile it, find the critical parts, and optimise
> them - where possible in the same language, and where that's too
> ugly/painful, drop down a
On Sun, Feb 24, 2013 at 5:50 AM, bernardH
wrote:
> FWIW, I, for one, am really glad that Clojure allows us to select
> precisely which nice tools we want (have to) throw away (persistent data
> structures, dynamic typing, synchronized) when the need arises. Reminds me
> of the "don't pay for what
On Sun, Mar 3, 2013 at 7:06 PM, Lee Spector wrote:
> So now I'm just checking for () and handling it specially, and that works.
> But still it doesn't seem right that (str ()) =>
> "clojure.lang.PersistentList$EmptyList@1" and I wouldn't be surprised if
> this tripped up others in the future (an
On Sun, Mar 3, 2013 at 7:30 PM, Jack Moffitt wrote:
> I think you're looking for pr-str. For example:
>
> (pr-str (take 10 (iterate inc 0)))
> ;;=> (0 1 2 3 4 5 6 7 8 9)
>
Thanks! But that makes me wonder:
Why doesn't printf use either pr-str or print-str to handle the %s format
strings?
(pri
In Clojure, there are a handful of global variables that you can set!, for
example
(set! *warn-on-reflection* true)
Is there any mechanism for providing a similar feature in a user library?
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post
;m generally of the philosophy that ideally, a language should make
available for users any features it uses in its own built-in libraries, so
I'm hoping there's a way to do it.
On Wed, Mar 13, 2013 at 12:06 PM, Michael Klishin <
michael.s.klis...@gmail.com> wrote:
> 2013/3/13 Mar
On Wed, Mar 13, 2013 at 2:09 PM, Cedric Greevey wrote:
> To expand on what Marko said, the set!able Vars that come with Clojure
> just have thread-local bindings created already in the REPL thread. They're
> really only meant to aid developers working at the REPL, rather than to be
> set! as part
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 the binding. You can *set!* any dynamic var with the same
> semantics.
>
You can
On Wed, Mar 13, 2013 at 2:36 PM, Michael Klishin <
michael.s.klis...@gmail.com> wrote:
> alter-var-root works fine for that purpose, e.g.
>
> https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/core.clj#L168-171
>
Thanks. That's probably what I'll end up doing. Still, it wou
OK, that answers my question. Thanks for the insights everyone!
--
--
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
On Sun, Mar 17, 2013 at 6:07 PM, vemv wrote:
> Reading a raw string stored in a file is already trivial :)
>
I'm aware that one can store a raw string in a file. But in many
instances, this would be absurd. For the kind of rapid interactive
development we have in Clojure, we don't necessarily
On Sun, Mar 17, 2013 at 11:23 PM, Softaddicts
wrote:
>
> I find raw string handling in XML simply ugly :)
Agreed.
>
> Do you have a suggestion on how to represent raw strings ? Something
> concrete
> we could discuss about ?
>
>
In several languages, they use a sequence of three double-quotes
On Mon, Mar 18, 2013 at 12:38 PM, Marko Topolnik
wrote:
> This is just about the same as
>
> (def ^:const pi (compute-estimate-of-pi))
>
>
>
OK, just tried out ^:const in my code and it seems to strip off any meta
data associated with the object stored in the var. That ruins its utility
for my pu
On Mon, Mar 18, 2013 at 8:31 PM, Kemar wrote:
> Explicitly derefing the var and calling meta on it works:
>
> (meta @#'c) -> {:amazing true}
>
> No idea as to why though...
>
Quirky. I assume that explicitly derefing the var defeats the speed
benefits of ^:const, yes?
--
--
You received thi
On Tue, Mar 19, 2013 at 12:57 AM, Bronsa wrote:
> If I remember correctly, this is a bug due to the fact that constant empty
> literals are handled in a special way from the compiler.
>
>
Interesting. I see you are correct that the problem only occurs on
metadata attached to an empty literal. S
On Thu, Mar 21, 2013 at 11:54 AM, Razvan Rotaru wrote:
> Is there an alternative to the code above (preferably simple and elegant),
> which will return the etire sequence?
>
(pr-str (map + [1 2 3]))
or
(print-str (map + [1 2 3]))
There are subtle differences between pr-str and print-str, (which
I've been impressed with the quality of the InfoQ videos. Most other tech
videos I see are unwatchable precisely because there isn't enough
resolution to see the content on the presenter's screen clearly. Having
the slides side-by-side makes an enormous difference. Waiting several
months for a q
On Mon, Mar 25, 2013 at 12:13 PM, Cedric Greevey wrote:
> In fact, your statement is wrong as to very basic economics. The value of
> being there at the conference isn't alterable by something that hasn't, at
> that point, even happened yet. A delayed release only takes value *away*
> from the *v
According to the Java docs, Java strings support eight escape characters.
http://docs.oracle.com/javase/tutorial/java/data/characters.html
One of the valid escape characters is \'
Clojure strings are supposed to be the same as Java strings, but when I
type the following string into the Clojure REP
I'm in reader hell right now, trying to puzzle out how escape sequences and
printing work for strings and regular expressions.
I notice that:
(re-pattern "a\nb")
(re-pattern "a\\nb")
(re-pattern "a\\\nb")
all produce semantically equivalent regular expressions that match "a\nb"
The middle one pr
On Thu, Mar 28, 2013 at 5:08 PM, Mark Engelberg wrote:
> However, the first and last example print as:
> #"a
> b"
>
Follow up question:
Is there any way to make (re-pattern "a\nb") print as #"a\nb"?
I've tried pr, print-dup, and various combinati
I'm on 1.5.1 and I get that too, but even though:
(pr #"a\nb") prints in a sane, readable way
(pr (re-pattern "a\nb")) does not.
The latter is what I need to print in a nice way.
On Thu, Mar 28, 2013 at 5:42 PM, Andy Fingerhut wrote:
> On Thu, Mar 28, 2013 at 5:15
On Thu, Mar 28, 2013 at 6:16 PM, Andy Fingerhut wrote:
> When you say a "sane, readable way", do you mean human-readable, or
> readable via clojure.core/read or clojure.core/read-string?
>
I meant human readable
>
> (defn print-regex-my-way [re]
> (print "#regex \"" (str re) "\""))
>
If you
On Thu, Mar 28, 2013 at 7:52 PM, Mikhail Kryshen wrote:
> On Thu, 28 Mar 2013 17:08:46 -0700
> Mark Engelberg wrote:
>
> > Bug or feature?
>
> Certainly a feature for complex patterns with whitespace and embedded
> comments.
>
> For example, the following rege
On Thu, Mar 28, 2013 at 6:36 PM, Andy Fingerhut wrote:
> (defn print-regex-my-way [re]
> (print "#regex ")
> (pr (str re)))
>
> That might be closer to what you want.
>
Yes. That does the trick. That extra level of converting the regular
expression to a string does the trick because pr "doe
On Sat, Mar 30, 2013 at 11:33 AM, Mark Engelberg
wrote:
> On Thu, Mar 28, 2013 at 6:36 PM, Andy Fingerhut
> wrote:
>
>> (defn print-regex-my-way [re]
>> (print "#regex ")
>> (pr (str re)))
>>
>> That might be closer to what you want.
>&
On Sun, Mar 31, 2013 at 10:46 PM, Andy Fingerhut
wrote:
> If you print it as a string, then want to read it back in and convert back
> to a regex, you must read it as a string, then call re-pattern on it. That
> should preserve the original meaning.
>
> Printing it as a string, and trying to read
On Mon, Apr 1, 2013 at 1:00 AM, Michał Marczyk wrote:
> Could you just preprocess the strings passed to re-pattern (or
> patterns if you're getting those as input) to replace literal newlines
> with escape sequences? I'm assuming you don't care about ?x given the
> result you wish to achieve.
>
T
Right now, I'm experimenting with seesaw. In Clojars, it appears the
latest version is 1.4.2.
When I include [seesaw "1.4.2"] in my project.clj file, then the REPL comes
up as 1.3.0 (even though I explicitly define clojure 1.5.1 as a dependency
in the project.clj file). How do I make my preferre
Thanks everyone!
--
--
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
I'm having trouble figuring out how to sign a library when deploying it to
clojars.
I'm using lein 2.1.2 and the clojars plugin (0.9.1).
I pasted my ssh key into clojars profile.
I successfully created a pgp pair with gpg, and as per directions, pasted
the entire public key into my clojars profi
When I do "lein deploy clojars", the tool hangs after reporting that it has
created the jar.
Any idea what might be causing it to hang?
On Fri, Apr 5, 2013 at 7:19 PM, Nelson Morris wrote:
> Yep. There is an issue for making it work over scp, which the
> lein-clojars plugin uses, at
> https://g
Instaparse is an easy-to-use, feature-rich parser generator for Clojure.
The two stand-out features:
1. Converts standard EBNF notation for context-free grammars into an
executable parser. Makes the task of building parsers as lightweight and
simple as working with regular expressions.
2. Works
On Tue, Apr 9, 2013 at 1:33 AM, Tassilo Horn wrote:
> Nice, but providing the grammar as a plain string looks somewhat
> unnatural to me. Why not something like this (parser being a macro)?
>
> (def as-and-bs
> (parser
> S = AB* .
> AB = A B .
> A = "a" + .
> B = "b" + .))
>
What version are you running?
As far as I know, .3 isn't even a valid representation for a number --
you'd have to write it as 0.3. So I'm not sure where you're running that
code snippet such that you don't get an immediate error.
On 1.5.1:
=> (+ 0.3 1.7)
2.0
That said, I think most programmer
On Tue, Apr 9, 2013 at 2:41 AM, Mark Engelberg wrote:
> What do you think would be gained by making it a macro? From my
> perspective, a macro is essentially just a string that is being processed
> by the Clojure reader (and thus subject to its constraints). If the
> grammar were
Thanks for the suggestion. I based the syntax off of EBNF, and hadn't run
across ABNF notation before your link just now. It shouldn't be too hard
to add support for ABNF's repetition syntax and comments. Getting the
semantics of the terminal values to precisely match the ABNF spec seems
like mo
Ah. That's pretty funny :)
On Tue, Apr 9, 2013 at 2:48 AM, Jim foo.bar wrote:
> Hey Mark, don't get paranoid :)... this is all Cedric did!
>
> user=> (def .3 0.4)
> #'user/.3
>
> user=> (+ .3 1.7)
> 2.1
>
> Jim
>
>
>
>
> On
Wow, the enthusiastic response has been really gratifying. Thanks for the
kind words; I hope as people try it out that it lives up to the hype.
On Tue, Apr 9, 2013 at 4:47 AM, Laurent PETIT wrote:
> Do you have a roadmap for the next releases ?
>
Initially, my focus will be on gathering feedba
On Tue, Apr 9, 2013 at 7:14 AM, Tassilo Horn wrote:
> IMHO, it would be cool if a clojure parser library would use a similar
> format (exploiting clojure data structures beyond lists where they make
> sense), at least internally. Of course, one could still have other
> frontends like for the EBN
On Wed, Apr 10, 2013 at 12:22 AM, sesm wrote:
> Hi Mark,
>
> Amazing stuff, I didn't know, that such general parsing techniques even
> exist!
>
> One minor comment: it would be nice to add direct links to GLL papers and
> https://github.com/epsil/gll github repo to save people some googling
> tim
On Thu, Apr 11, 2013 at 7:08 AM, Stathis Sideris wrote:
> Thanks, this looks fantastic! Is there any way to include comments in the
> syntax at all?
Last night I started a v1.1 branch to start work on these feature
requests. The first feature I added was, in fact, support for EBNF comment
synt
On Thu, Apr 11, 2013 at 7:41 PM, Dmitry Kakurin wrote:
> But your parser rules are somewhat new to me.
> Both variations are accepted:
>
> add = add-sub <'+'> add-sub
> add = mul-div <'+'> add-sub
>
> And in both cases some generated parsers are correct (arithmetically
> speaking :-) ),
On Fri, Apr 12, 2013 at 1:55 PM, Dmitry Kakurin wrote:
> Here is where my question is coming from:
> If I were to use such parser in production I'd like it to be unambiguous.
> And I'd like to detect ambiguity early, before my software ships/deployed.
> Preferably during build/packaging/deployment
On Fri, Apr 12, 2013 at 5:55 PM, Brandon Bloom wrote:
> Your readme says "I had difficulty getting his Parsing with Derivatives
> technique to work in a performant way". I was wondering if you could
> please elaborate.
>
> What kind of performance did you achieve?
> How does that compare to the G
Yes, quite possible. I've added it to the enhancement list on the github
issues page.
On Sat, Apr 13, 2013 at 2:45 AM, David Powell wrote:
>
> Would it be possible to have an option to tag the parse tree with
> meta-data indicating the character offset (or line & column)?
>
> --
> Dave
>
>
--
On Thu, May 2, 2013 at 7:19 AM, Max Gonzih wrote:
> Hi, what do you think about dsl version using map?
>
The short answer is that this is already supported. In the github readme,
you'll find a section labeled "Combinators", in which I outline
instaparse's dsl for creating grammars as a map from
What tools exist in Clojure for understanding whether a given variable is
boxed or primitive?
To get a better handle on boxing, I started playing around with things like:
(def x 1)
(def ^int x 1)
(def x (int 1))
I want to know how Clojure is storing that 1 in the various cases.
The only tool I
Instaparse is an easy-to-use, feature-rich parser generator for Clojure.
The big idea behind instaparse is to make it simple to convert grammars to
parsers without needing to know the idiosyncrasies of LL1, LALR, and other
esoteric grammar restrictions imposed by most parser generators.
When I ann
As part of the instaparse library, I created a wrapper around Clojure's
vectors that keeps the hashcode updated as the vector is modified. In
scenarios where you take a vector and then hash, then modify, then hash,
then modify, then hash, etc., this strategy of "incremental hashing" is
essential t
On Tue, May 14, 2013 at 3:56 AM, Jim wrote:
> many thanks for this! :)
>
> btw, is there any place where one can find your discussion between you and
> Christophe? I'd love to know more about equiv...alternatively, do you plan
> on making public what you've learned in some sort of demo/tutorial?
On Tue, May 14, 2013 at 6:17 AM, Laurent PETIT wrote:
> Mark, the combined qualities of the code, the documentation, the
> communication, is inspiring !
>
Aw shucks. I'm blushing. Thanks guys.
--Mark
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" gr
Yes, but in (some versions of) Scheme, (sqrt -1) yields i.
Representing complex numbers and just doing math between two complex
numbers is not the problem. Retrofitting Clojure math so that all
operations work on the entire numeric tower, allowing you to
seamlessly manipulate complex and non-comp
It's great to be discussing the possibility of enhanced primitive support.
I like most of the proposals. But this part troubles me:
# For bigints, specify bigints
* new literal bigint format 42N
# bigints contagious, no more auto-reductions
* (\+ 0N 21 21) => 42N
One of the big reasons
Thanks for the responses.
Going back to the naive factorial function:
(defn fact [n]
(if (zero? n) 1 (* n (fact (dec n)
Right now,
user=> (fact 40)
8159152832478977343456112695961158942720
Under the proposed changes,
user=> (fact 40)
java.lang.ArithmeticException: integer overflow
On Thu, Jun 17, 2010 at 9:20 PM, David Nolen wrote:
> The problem is that it distinctly *not* easy to write fast numeric code in
> Clojure. It requires expert Clojure knowledge.
Right, but with just the prim branch and a shorthand for long literals, you get:
(defn ^:static fib ^long [^long n]
(
Hmmm, here's an idea:
How about inside of a static function with type annotations, all
literals are automatically converted into long and doubles, otherwise
behavior stays the same.
So:
(defn ^:static fib ^long [^long n]
(if (<= n 1)
1
(+ (fib (dec n)) (fib (- n 2)
is automatically co
On Thu, Jun 17, 2010 at 11:01 PM, David Nolen wrote:
> What's the problem?
> David
It's a composability issue.
Elaborating on Anthony's explanation, let's say you call (fact (foo n)).
Do you know what values of n, when passed to foo, produce a value
large enough that fact will produce an excepti
On Thu, Jun 17, 2010 at 9:06 PM, Stuart Halloway
wrote:
> It will be much easier for people to write fast library code (including in
> Clojure and contrib). So if you ever use Clojure libraries, you will get a
> speed boost.
I am skeptical of this claim. Since static functions lose some of
the
On Fri, Jun 18, 2010 at 1:52 PM, Rich Hickey wrote:
> I've revised and enhanced the strategy, based upon the feedback here. I
> think it is a nice compromise.
Looks good to me.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, s
I've spent a number of years looking for a functional programming
language suitable for the kind of work I do. evaluating Clojure,
Haskell, Erlang, Scala, F#, Mozart, ML, Clean, Racket, and probably
some others I'm not thinking about right now. For me, once Clojure
hit 1.0 status, it was clearly
An idea to consider:
How about keeping the arbitrary-precision default, but add a loop'
construct to the family of +',-',*',inc', and dec' for primitive
optimization? The loop' construct would bind primitive literals,
whereas the loop construct would keep the literals boxed, so people
who don't w
I'm confused. In the latest scheme, what is the eventual plan for
handling a recur to a loop element that was initialized with a
primitive? Are boxed numbers automatically coerced to the primitive?
Would a long be coerced to a double, or double to long? Under what
scenarios will you get a warnin
On Sat, Jun 19, 2010 at 6:32 AM, Rich Hickey wrote:
> Really? It seems tedious to me. Don't you get tired of saying int i = 42 in
> Java, when you know full well the compiler knows 42 is an int? I do, and
> Clojure is competing with languages that infer the right types without the
> redundancy.
On Sat, Jun 19, 2010 at 12:20 PM, Nicolas Oury wrote:
> Not "ordinary" code. 10^19 is big.
Nicolas, I think you misunderstand my point. I'm talking about
loop/recur behavior. If you initialize a loop with the literal 1, and
then recur with a number 2 that's pulled from a collection (and thus
bo
On Sat, Jun 19, 2010 at 4:10 PM, Michał Marczyk
wrote:
> (defn fact [n]
> (loop [n n r 1]
> (if (zero? n)
> r
> (recur (dec n) (* r n)
Thanks for posting this surprisingly simple example of something that
looks like it should work, but wouldn't under the current proposal.
Really
On Sat, Jun 19, 2010 at 5:13 PM, David Nolen wrote:
> Huh? That doesn't look like it's going to work at all.
> 1) 1 is primitive, we know that, accept it
> 2) we don't know the type of n, what will (* r n) be?
> 3) BOOM!
Yes David, if you have a deep understanding of how loop/recur
interacts with
701 - 800 of 1205 matches
Mail list logo