Re: [q-lang-users] Suggestions on how to debug?
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2006-12-19 22:57:56
|
Albert Graef wrote: > Andrew Berg wrote: >> It looks to me like "regex_next" is doing all the work, and if asked to predict, I would guess that it is tail recursive. > > No, the current version is not. And yes, I guess you're right with your > suspicion that regex_next is the culprit here. It shouldn't be a big > deal to rewrite regex_next so that it's tail-recursive, though. Ok, here is a tail-recursive implementation of regex. Just put this at the beginning of your script and fetch_history "AA" goes through without a hitch (takes a while, though). (I might also use this definition in the next version of clib, but not right now as I haven't tested it thoroughly yet and I don't want to hold back the 7.6 release any longer.) special regex ~OPTS ~REGEX ~S EXPR, regex_next ~Xs EXPR; special check ~P X Y; regex OPTS:String REGEX:String S:String EXPR = check (regmatch OPTS REGEX S) (reverse (regex_next [EXPR] EXPR)) []; regex_next Xs EXPR = check regnext (regex_next [EXPR|Xs] EXPR) Xs; check P:Bool X Y = X if P; = Y otherwise; check P X Y = P otherwise; Also note that using regex to just split a string at a given delimiter is really overkill. There's the split function which does this much faster (clib provides a C implementation of that function). To use this, just s/regsplit "g"/split/ in your script and fetch_history "AA" runs much faster. HTH, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |