On Wed, Jan 26, 2011 at 8:38 PM, Noah Lavine <noah.b.lav...@gmail.com> wrote: > Hello, > >> I'm the guy that originally wrote this for GSOC, so I figured I'd jump >> in. I'd be happy to help with getting the PEG module merge-ready. > > Great! > >> keyword-flatten is described in api-peg.texi. It's basically a >> special case of context-flatten which collapses S-expressions >> according to the symbol they start with. From the documentation: >> @deffn {Scheme Procedure} keyword-flatten terms lst >> A less general form of @code{context-flatten}. Takes a list of >> terminal atoms @code{terms} and flattens @var{lst} until all elements >> are either atoms, or lists which have an atom from @code{terms} as >> their first element. >> @lisp >> (keyword-flatten '(a b) '(c a b (a c) (b c) (c (b a) (c a)))) @result{} >> (c a b (a c) (b c) c (b a) c a) >> @end lisp > > Okay. I was confused about the behavior of keyword-flatten when the > car of its argument is not in its list of keywords. I expected that to > change, but it didn't. Looking at it now, is it true that the car of > the argument never changes? So keyword-flatten flattens the sublists, > but has to leave the overall one alone?
Yeah, the overall list is always there; only the sublists will ever be collapsed down. But the car can change. It flattens until you have a list where each element either: 1. Is an atom. or 2. Is a list whose first element is in the list of keywords. So the car of the argument will change if it's a list that doesn't start with the right keyword. E.g.: (keyword-flatten '(a) '((c (a b)) (a b) (b a))) -> (c (a b) (a b) b a) > >> peg-string-compile is a function that will compile PEGs expressed as >> strings into lambda expressions. It does this by first parsing the >> string using the PEG-parsing-PEG, then turning the output into an >> S-expression representation of a PEG, compressing it, and passing the >> compressed S-expression to peg-sexp-compile. It's used if you e.g. >> call peg-match with a string instead of an S-expression as the first >> argument. > > I tried running peg-string-compile and then passing the result to > eval, but I got an error because there was no symbol 'Begin. (capital > B intended) Do you know what's going on with that? It might be > something weird involving memoized symbols. Also, just to make sure I > get it - this function produces Scheme code, right? (As opposed to > Tree-IL or any of Guile's other languages.) That's odd. Could you paste in the lambda expression it generates? (Yeah, it produces Scheme code.) > > Noah >