previous up contents next
Left: Last Up: Standard library function functions Right: Hyphenate

Sed

Sed is a very simple-minded substitution and deletion function, suggested by John Carroll, and inspired by the (vastly more powerful) Unix utility of the same name. We suspect that it can be defined in DATR itself but have not attempted to do so here. Like Unix sed it declares its own separator character. The syntax is as follows:
Sed:< separator atom+ separator atom* separator atom* >.
The three separator tokens must be identical, the first two atom sequences can be anything except that neither may contain the separator character, the final atom sequence is unconstrained and may only be implicit (i.e., it only gets specified only through the regular DATR path extension mechanism). Invocations of Sed that violate these syntactic requirements fail.

Here are some examples:

    Sed:</ a / e / a b ra c a d a b ra> = e b ra c e d e b ra.
    Sed:<- x y z - x z - x x z z y y x y z z y x> = x x z z y y x z z y x.
    Sed:<a b r a c a d a b r a> = d a c a.
    Spell:
        <> == Sed:</ hafta / have to />.
    UnSpell:
        <> == Sed:</ have to / hafta />.
    DeleteOne:
        <$x> == Sed:<| $x | |>.
    StripComma:<> == DeleteOne:<,>.
    DeleteTwo:
        <$x $y> == Sed:<| $x $y | |>.
    Transpose:
        <$x $y> == Sed:<| $x $y | $y $x |>.

One could imagine beefing this function up (regular expression syntax, named substrings of atoms, etc.) but even this minimal version looks like a very handy thing to have around.


---------------------------------------------------------

Copyright © Roger Evans, Gerald Gazdar & Bill Keller, Tuesday 10 November 1998