In the definition of 'automaton, you have the macro call (mkrule _). I don't think you want 'mkrule to be a macro, because I don't think you actually care about the symbol _. The first thing I suggest is to replace "mac mkrule" with "def mkrule".
After this change, I'm still not quite sure what your code is trying to do (I haven't clicked your links yet), so I'll try some example cases:
For one thing, it looks like you might want that (car (1 (2 3) (4 5))) to be just 1. You can fix this by changing (car ,i) to ,(car i).
Since you end up with function calls like (3 (cdr str)), it looks like you're trying to make several functions under the same scope (using Anarki's 'withr/p), and it looks like 'str is a variable that contains the remaining inputs of the automaton.
In this case, I recommend changing `(list (cdr ,i) (fn ...)) so that it's (list (cdr i) `(fn ...)), since you probably didn't want that 'list symbol in the 'withr/p call.
To make this easy to test, here's the complete code, with Anarki's definition of 'withr/p and my updates to 'mkrule:
; a 'with that works for defining recursive fns
(mac withr/p (bindings . body)
" Scheme's 'letrec.
See also [[withr]] [[where]] "
`(let ,(map1 car bindings) nil
,@(map [cons 'assign _] bindings)
(def mktransition (tn) (list (car tn) (list (last tn) '(cdr str))))
(def mktransitions (ts)
(each x (map1 mktransition ts)
(accfn (car x))
(accfn (last x)))))
(def mkrule (r)
(let i r
(list (car i) `(fn (str)
(if (empty str) t
(case (car str)
,@(mktransitions (cdr i))))))))
(mac automaton (i r) `(withr/p ,(map1 [mkrule _] r) ,i))
Seems to work!
arc> (matches-aabb '(a a a a b b b b))
arc> (matches-aabb '(a a a a b b b b a))
arc> (matches-aabb '(a a a a))
arc> (matches-aabb '(b b))
arc> (matches-aabb '())
arc> (matches-aabb '(b a))
arc> (matches-aabb '(c))
Now that I look at your Gist, I realize I could have saved myself some time figuring this out. :) I also realize you were aiming for a slightly different interface:
Good luck. I could use one -- I've wanted to use it with Twitter for a while. I started writing one myself, then realized I needed a unit test framework, so I've been working on that. Oh, the perils of a language lacking libraries.
Would you like some help? As long as it's free software, I'd love to assist.
(It's not a normal C++ project. I use readable diff directives inside :(..) to add the test harness to the skeleton program at https://github.com/akkartik/wart/blob/cc70d66ee6/literate/00.... But now that this is done, any function I write with 'test_' is automatically run in test mode. Look at the makefile to see how I do that with minimal code.)
Anyways, tell me what language and I'm sure we can get you quickly past this hurdle.
Honestly, there are some fiddly bits about the unit test framework I don't like, but mainly I wanted to write one.
I actually applied with it for Lisp In Summer Projects (http://lispinsummerprojects.org/), which is why I haven't announced it -- you're supposed to do the work yourself, without help. And people here like to help out and post code. :-p
Luckily, at this point it's got the main features I want, so I can actually use it.
Sweet. I had been wanting to play around with the unit test code too -- i'm excited to see what you've put together.
The oauth utility is also for the LISP contest -- we'll see how far I get over the next few weeks.
Either way I'm planning on uploading a few bits and pieces to Anarki or my own repos over the next couple of weeks. (spent some time on anarki's web.arc, the state machine stuff, oauth, some lazy evaluation stuff, etc...)
That makes sense :) I'd love to hear more about what's fiddly about the existing version (I have different versions at http://github.com/akkartik/arc, etc.) and why you need the features (suites, nested suites, failure messages, anything else?)
I'm going to have to go to bed soon, as I need to wake up in eight hours and twenty minutes, and I've promised myself I'm going to try to sleep enough, for once.
So I'll just explain what, in my mind, is the biggest difference -- how I want to use it. To run the anarki test-iso test, you execute the entire `(test-iso ..)` sexp. If you want to run a bunch of tests, you have to execute all the sexps.
That's kind of a hassle. Especially if you find a bug, have a bunch of tests that fail, then change a small thing in the function, and want to re-run all the tests.
In my unit-test.arc, all you have to do is call `(run-suites suite-name)`, and it'll run as many tests as you've got in `suite-name`. You don't have to copy a bunch of sexps into the repl or reload the file (and what if you want to run a subset of a file? You can't). Also -- and this is one of the features I'm currently working on (https://bitbucket.org/zck/unit-test.arc/issue/21/after-runni...), what if you run one hundred tests at once? Do you really want to parse -- with your eyes, like a bloody scribe -- every single line of output to find the seven tests that broke? And when you then make a fix, you're not going to want to parse them again, so you'll only run the seven that failed before. So if you broke something else, you won't find that out.
So, what falls out of my desire to run a set of tests easily and repeatably, and have summarized output? Some sort of grouping, with a single point of entry to run the tests -- that is to say, test suites.
Please correct me if I've missed any feature of Anarki's test framework. I did read its code and try it, but I didn't look into other files for supporting functionality.
"If you looked at it closely, I made many changes in the spirit of getting something running that PG (and you!) would likely not agree with."
I didn't see the repo while it was online, but I've always looked forward to Arc (or at least Anarki) becoming usable as a Racket language at some point, even if it were an awkward fit. Just how disagreeable are we talking, here? :)