
Lisp implementation in sed - inglesp
https://github.com/shinh/sedlisp
======
mseri
Ahahah. Awesome. There is even an 'awk' version:
[https://github.com/darius/awklisp](https://github.com/darius/awklisp)

~~~
abecedarius
I wrote that, and I gotta say sed is a much crazier target.

More sed fun:
[http://aurelio.net/projects/sedsokoban/](http://aurelio.net/projects/sedsokoban/)

~~~
mzs
Kudos, there was also this one:
[http://www.cs.cmu.edu/afs/cs/Web/Groups/AI/lang/lisp/impl/aw...](http://www.cs.cmu.edu/afs/cs/Web/Groups/AI/lang/lisp/impl/awk/0.html)
Possibly based on the same newsgroup post?

~~~
abecedarius
That one's a cooler hack because it runs in old awk, from before they
supported user-defined functions. The whole read-eval-print composition is a
straight-line series of loops, with the recursions unrolled into explicit
stack manipulation. If you want to see how to write fairly readable code
within those restrictions, it's instructive. It even has a cooler name. (I
said so when bringing it up in my documentation.)

On the other hand, awklisp has some value as a readable Lisp interpreter in a
lower-level but still reasonable language, in between the usual Lisp-in-Lisp
and Lisp-in-C tutorials.

------
nate_martin
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
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.

~~~
catshirt
woah woah woah. we don't just throw around "waste of time" like that :)

~~~
mtdewcmu
I was wrong, obviously.

------
asgard1024
Wouldn't the opposite - stream editor (programmable) in Lisp - be more useful?

~~~
aaronem
Well, if you count Emacs in batch mode, such a thing already exists.

------
justinator
Well, OK: I'm curious, can I use the sed to Perl utility, to then make a Lisp
implementation in Perl?

~~~
justinator
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](http://perldoc.perl.org/s2p.html)

------
bndr
This is amazing. Just reading the code makes my head hurt, but you implemented
a language with it.

~~~
lengads
Here, for example, is the implementation of `atom` (I think):

    
    
      /(atom /{
        /\[\S\+\]/{
          s/.*/[]/
          bpop_context
        }
        s/.*/t/
        bpop_context
      }

~~~
sejje
If this was (the only available) programming, I'd quit.

Kudos, I think, to the author. His pain tolerance exceeds mine by a vast
amount.

~~~
quotemstr
> If this was (the only available) programming, I'd quit.

We started with nothing, remember? Just the bare metal. If this were the only
available programming, I'd write an interpreter for a better language.

Never imagine that your current suite of tools is all there is.

~~~
Someone
It will be a challenge to make an interpreter for a better language faster
than dead slow.

I would bet on a compiler for a better language instead. That way, only one
person would have to wait ages and ages. I doubt the result would be fast, but
it wouldn't be insanely, insanely, insanely slow, either.

------
bane
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
Now you have three problems.

~~~
krapp
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.

~~~
mtdewcmu
Having a Lisp will make it a little easier to write the Javascript
interpreter. Baby steps.

~~~
bdonlan
Oh, excellent. Once I have JS I'll be able to run Clojure code on it.

