Using 'eval' is really slow; I suspect that's what's killing your performance here. Also, parsing a string to an expression every time might hurt too.
Here's my crack at it: https://gist.github.com/2462109 This one takes 36 seconds on my laptop. Memory usage is pretty constant at about 33M. (Sorry it's so ugly! I need sleep~~) It works by creating a list that looks like: '(10 + 9 - 8 * 7 / 6 c 5 + 4 - 3 * 2 / 1) Then, it just parses the arithmetic expression. First, it gets rid of concatenation (the 'c symbol): '(10 + 9 - 8 * 7 / 65 + 4 - 3 * 2 / 1) Then division and multiplication: '(10 + 9 - 56/65 + 4 - 6) And finally addition and subtraction: '(1049/65) ...to arrive at a single number (in this case, an exact rational fraction.) Theoretically simple, but probably also inefficient--I'm just trading parsing strings into expressions for parsing giant lists into expressions. Still, at least there's no (eval). It could be improved to use less list processing functions, inexact arithmetic, typed racket, etc... (The 'module+' form was recently added to 5.3, which should be out soonish? If you're not using the latest racket, just delete the lines that give you errors until it works) 17 hours ago, ashok bakthavathsalam wrote: > For the benefit of the members on this mailing list, I am > cross-posting a question > <http://bit.ly/JmB931>I asked on StackOverflow and the excellent answers > therein. > > "I hacked together several code snippets from various sources and > created a crude > implementation <http://dl.dropbox.com/u/10901898/yearcalc.rkt> of a Wolfram > Blog article at http://bit.ly/HWdUqK - for those of you that are > mathematically inclined, this might be very interesting. Not surprisingly, > given that I'm still a novice at Racket, the code takes too much time to > calculate the results (>90 min versus 49 seconds for the author) and eats > up a lot of memory. I suspect it is all about the definition (expListY) > which needs to be reworked. Anybody want to take a stab at improving the > performance and efficiency? I apologize for the unintelligible code and > lack of better code comments." > > % ashok -- Reclined in a defunct and truly obese satellite dish, _mike ____________________ Racket Users list: http://lists.racket-lang.org/users