Subject: Re: OPFR ("Outer-Parenthesis-Free REPL") released
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 09 Mar 2009 08:06:47 -0500
Newsgroups: comp.lang.lisp
Message-ID: <ZvqdnatzJ976iSjUnZ2dnUVZ_gqWnZ2d@speakeasy.net>
Evans Winner  <thorne@timbral.net> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > To recap: OPFR ("Outer-Parenthesis-Free REPL") is a
| > meme/pattern/library(?)  for a reader that wraps a set
| > of parens around whatever the user types and then passes
| > that to EVAL (then PRINTs & LOOPs).
| 
| What is this used for?  I have thought that this kind of
| thing would be a nice feature in a lisp-based command language.
+---------------

Yup, if you qualify that with "domain-specific", that's exactly what
it provides. You can search for the sveeral previous tiems I've talked
about it here, but briefly, OPFR is intended for making domain-specific
"command languages" that happen to be written in CL, via the simple trick
of providing parens around each input line and then calling EVAL. To make
sure that the end user seldom (if ever) needs to type a real Lisp sexp,
one should also provide sufficient pre-defined domain-specific functions
that can take simple constant arguments [though possibly allowing optional
and keyword args], so that users rarely need to type parens.

But because the "command language" is *such* a thin shim over the
CL REPL, the full power of CL is instantly available to "power users"
who want to do more than the application designer initially provided
them in the pre-defined functions. E.g., suppose you have written a
hardware test control program (call it HTC), and have provided a few
"commands" (functions) such as RESET-BOARD, RELOAD-BOARD, & START-BOARD:

    htc> reset-board 3
    htc> reload-board 3 chip 17 file "foo.bin"
    htc> start-board 3
    htc> 

A power user will quickly [or slowly, whatever] pester you and
learn that they can write:

    htc> loop for b in boards do (reset-board b)
    htc> 

Pretty soon, they're writing nasty/fun stuff like this:

    htc> (loop for b in boards do
	   (loop for c in chips do
	     (reset-board b)
	     (reload-board b chip c file (format nil "foo-~d-~d.bin" b c))
	     (start-board b)))
    htc> 

and then realizing they can put such things into their own scripts with:

    $ cat my-script
    #!/usr/bin/env htc
    (loop for b in boards do
      (loop for c in chips do
	(reset-board b)
	(reload-board b chip c file (format nil "foo-~d-~d.bin" b c))
	(start-board b)))
    $ 

And for the ones who're not quite so eager, you just make sure that
your "htc" program is written so that when run with no arguments one
gets an OPFR REPL, but when run with args it takes them as one "command"
on the line. Then instead of typing this:

    $ htc
    htc> reset-board 3
    htc> reload-board 3 chip 17 file "foo.bin"
    htc> start-board 3
    htc> ^D
    $ 

the "half-power users" will type this to the shell [yes, there's that
bit of nastiness about single-quoting the double quotes -- oh, well!]:

    $ htc reset-board 3
    $ htc reload-board 3 chip 17 file '"foo.bin"'
    $ htc start-board 3
    $ 

and the "3/4-power users" will write scripts like this:

    $ cat my-script
    #!/bin/sh
    for b in `cat boards`
    do for c in `cat chips`
       do htc reset-board $b
          htc reload-board $b chip 17 file "\"foo-$b-$c.bin\""
          htc start-board $b
       done
    done
    $ 

+---------------
| For that matter, a really feature-full such command language seems
| like it would be an easy thing for those we-have-to-make-lisp-more-
| popular people to come up with.
+---------------

1. Note: I'm *NOT* one of thos "we-have-to-make-lisp-more-popular" people.
   I'm quite willing for it to remain a "secret weapon" [albeit an open
   secret].  ;-}  ;-}

   I just want to be *permitted* to use Lisp to write little domain-specific
   apps that other people in my work environment will need to run from time
   to time. Using OPFR as the interface permits just enough reduction in
   the ambient parenthephobia for using CL to be tolerated.

2. Since in practice you can get >90% of what is needed for command-line
   apps from OPFR plus a handful of domain-specific functions, there's
   no benefit in wasting time on developing a "really feature-full command
   language". The few power users who could benefit from the "features"
   can just be taught to use the full CL EVAL.

+---------------
| Not that I'm volunteering, because, you know, people can just roll
| their own if they need it.
+---------------

Exactly, which is why OPFR is more a "meme" or "pattern", rather than
a "library". I don't really expect anyone to use it for anything serious
without whacking on it a bit to make it fit their own local requirements.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607