top | item 7956246

Lisp implementation in sed

207 points| inglesp | 11 years ago |github.com | reply

60 comments

order
[+] nate_martin|11 years ago|reply
Would someone mind giving a quick explanation of how this works? I have only used sed to replace text in files and directories. How do people write interpreters and game loops with this unix utility?
[+] mtdewcmu|11 years ago|reply
With difficulty.

I started playing with the idea of making a programming language out of sed at one point, but then I decided that, even if I succeeded, it would be a waste of time.

I didn't take into account Hacker News.

[+] jes5199|11 years ago|reply
the sed language allows conditional jumps to labels. That makes it powerful enough to write programs in.

If you had to just write programs by running a series of sed substitution expressions to a file over and over, and not use conditionals... it might still be possible to program in. Much harder to think about, though.

[+] asgard1024|11 years ago|reply
Wouldn't the opposite - stream editor (programmable) in Lisp - be more useful?
[+] aaronem|11 years ago|reply
Well, if you count Emacs in batch mode, such a thing already exists.
[+] justinator|11 years ago|reply
Well, OK: I'm curious, can I use the sed to Perl utility, to then make a Lisp implementation in Perl?
[+] justinator|11 years ago|reply
Trying this myself, it returns an error:

    s2p: expression #1: extra characters after command (d)
Thankfully, I've never had the job of porting a sed script to Perl, so I'm not exactly sure what that's all about. The docs mention this error, but don't explain what it means,

http://perldoc.perl.org/s2p.html

[+] bndr|11 years ago|reply
This is amazing. Just reading the code makes my head hurt, but you implemented a language with it.
[+] lengads|11 years ago|reply
Here, for example, is the implementation of `atom` (I think):

  /(atom /{
    /\[\S\+\]/{
      s/.*/[]/
      bpop_context
    }
    s/.*/t/
    bpop_context
  }
[+] bane|11 years ago|reply
So I guess if all languages are eventually converging on Lisp, are all Lisps eventually converging on sed? Is sed the bottom turtle or are there more?
[+] IvyMike|11 years ago|reply
Now you have three problems.
[+] krapp|11 years ago|reply
Oh come on. They took an unreadable language and implemented a slightly less unreadable language in it. That's at least two problems and one solution.

To what, I don't know.