in reply to Re: Re: Re: Elegant way to parse an optional prefix with default?
in thread Elegant way to parse an optional prefix with default?

OK, I see what you're up to. You throw a (possibly extra) & on the front, then match an optional extra one. Instead of removing to leave behind, capture as $2 and assign back to the same variable. As a bonus, you're taking the trailing > as well (per other discussions).

If it's already known to be syntactically legal, that should do the trick. It doesn't generalize to any kind of default prefix if said prefix could be doubled originally. Otherwise, we have:

def-prefix . string matches def-prefix? (prefix) (remainder)
That's a good find worth remembering. Thanks.

—John

  • Comment on Re: Re: Re: Re: Elegant way to parse an optional prefix with default?
  • Download Code