Search code examples
haskelllispparentheses

Give example of actual Parenthesis Hell program


Some of you may be familiar with Parenthesis Hell (code here). Well, nice way to waste some time between evening phone calls, right?

I successfully used ghc to compile these five files. The interpreter seems to work if I run

$ ./ph

But since I don't really understand Lisp/cdr/car stuff very well, I quickly ran into trouble trying to do a functioning program. I thought at least some of them were supposed to print something to standard output...

$ ./ph () ()
-bash: syntax error near unexpected token `)'
$ ./ph () (3)
$ ./ph () (())
$
$ ./ph (()())
-bash: syntax error near unexpected token `('
$ ./ph "()()"  # suggestion in comment
ph: ()(): openFile: does not exist (No such file or directory)
$ ./ph  # actual behavior with returns
()
()
ph: Prelude.read: no parse

Needless to say, any attempt at using the Hello World in the "doc" led to lots of "syntax error near unexpected token" messages. Any ideas? Or does everything evaluate to nil and so this is just an elaborate Lisp joke, except with two actual compilers? Thanks!

(Note: Lisp aficionados will be doing a service by teaching more people about how to interpret this parenthesis stuff, which I have to admit will be useful for me anyway in a completely different context.)

Edit 2: @dfeuer at least has a resolution which worked, though I do wonder whether it is possible to use interactively from the shell.

$ cat hello
(()()(()()(()()()()((()()(()(()((()((()()()((()((()()()((()((((()()(()()()()()()(((()(((()((()((((()(((()()(()()((()((()()()((()()(()()()()(()()()()(()()()()(()(())))))))))))))))))))))))))))))))))))))))))))))))))
$ ./ph hello
Hello world!

Bizarre and yet awesome.


Solution

  • I don't think it expects code in its arguments. It looks to me like it looks for filenames (and a command line option named -v).

    It also seems like it only accepts one parenthesized expression per program. So something like () (()) would be invalid but (() (())) would be okay (or at least well-formed). If you wanted to use this from the command line, you could use echo since it also reads from stdin:

    echo "(()()(()()(()()()()((()()(()(()((()((()()()((()((()()()((()((((()()(()()()()()()(((()(((()((()((((()(((()()(()()((()((()()()((()()(()()()()(()()()()(()()()()(()(())))))))))))))))))))))))))))))))))))))))))))))))))" | ./Test