Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Alternatives to sed + awk
- Date: Fri, 11 Mar 2011 13:32:03 +0900
- From: "Stephen J. Turnbull" <turnbull@example.com>
- Subject: Re: [tlug] Alternatives to sed + awk
- References: <AANLkTim_-D9CFYC8TNp33ni85zB+QBA7jV=BpLN=4SbZ@example.com> <4D6F8D94.9040109@example.com> <87ei6nl906.fsf@example.com> <AANLkTimk1z41fSvQQmU+7fE-1Krd_kuo3_z-1SYD5rW6@example.com> <87ipvskik1.fsf@example.com> <AANLkTi=_6DoBt+xfQVOwM6KyKrxxgA_Ec9bhp751f15y@example.com> <8762rsjkdx.fsf@example.com> <AANLkTik=tHOgTRvcvNd0qsx9-o9MuqBnWUjkWVn+0U_7@example.com> <4D793EDF.2090308@example.com>
Simon Cozens writes: > So long as it's a domain that happens to have exactly the same syntax as Lisp. I can't speak to the Ruby version of the above sentence, but although I'm sympathetic to it in the Lisp version, I'm not 100% so. The reason is that even without reader macros, Lisp is "asymptotically syntax-free". There are a couple of bumps in the road, which I'll admit up front: you can't do arbitrary things with lexical syntax (eg, quote marks and parentheses can't be redefined), and you can't have significant whitespace (except for separating tokens).[1] And you'll always need a few parentheses visible to get the ball rolling (eg, requiring the package that implements the DSL, and around the list that contains the program in the DSL). However, in the DSL part you can do almost anything you want with symbols. The classic example of a DSL in Lisp is the loop macro, which implements a very un-Lispy DSL for describing iteration. Here's a relatively extreme, but not untypical, example from the HyperSpec[2]: ;; Another example of the extended form of LOOP. (loop for n from 1 to 10 when (oddp n) collect n) => (1 3 5 7 9) Look Ma! No parentheses! Almost: you have to have parens at the beginning and end of the loop expression. And the parity test has parentheses. But note! The parity test is not part of the domain (ie, specifying iteration)! It would also be possible to get rid of the parentheses for functions with constant arity, ie, you in theory could write an alternative-loop macro which could be used like this: (alternative-loop for n from 1 to 10 when oddp n collect n) or even (alternative-loop for n from 1 to 10 when n is oddp collect n) Thus, Lisp is "asymptotically syntax-free". If you are at all familiar with Lisp macros, that becomes pretty obvious upon reflection. Then, there's also Maxima, which is a very thin lex/parse wrapper around a DSL that lithpth. Whaddya think, Simon? N.B. I don't claim this is practical. No Lisp programmer in their right mind would write alternative-loop, it would be too much effort for too little gain. It would also be fragile in practice, because human readers would *require* proper indentation to read it. So real attempts at DSLs in Lisp will either display a lot of Lisp syntax, or have a separate lex/parse stage like Maxima does. Footnotes: [1] Those are examples, not intended to be a complete list. [2] http://www.lispworks.com/documentation/HyperSpec/Body/m_loop.htm Examples are at the end.
- Follow-Ups:
- Re: [tlug] Alternatives to sed + awk
- From: Simon Cozens
- References:
- [tlug] Alternatives to sed + awk
- From: Nguyen Vu Hung
- Re: [tlug] Alternatives to sed + awk
- From: Alexander Danilov
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Alexander Danilov
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Josh Glover
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Josh Glover
- Re: [tlug] Alternatives to sed + awk
- From: Simon Cozens
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Alternatives to sed + awk
- Next by Date: Re: [tlug] Alternatives to sed + awk
- Previous by thread: Re: [tlug] Alternatives to sed + awk
- Next by thread: Re: [tlug] Alternatives to sed + awk
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links