From: Evans Winner
Subject: Colon commands
Date: 
Message-ID: <86r6gmca17.fsf@timbral.net>
Some research seems to indicate that at least OpenMCL, ACL and LispWorks
maybe have some kind of facility that allows the definition of commands
that can be used at the repl that look like--

:command

--or maybe--

:command arg1 [arg2 ... argn]

I know at least clisp has something like this at least in the debugger.
Is this is standard Common Lisp facility?  (There is also a comma command
syntax in scsh, i know, as well.)

Sorry if the question is vague; i don't know if there is an established
term for this.  I can't find a reference in the Hyperspec.  In any case,
it might be nice to be able to define commands like that for convenience
at the repl.  Can it be done?--or is there a reason it's a bad idea?

From: Rainer Joswig
Subject: Re: Colon commands
Date: 
Message-ID: <joswig-04DE6C.11365413012008@news-europe.giganews.com>
In article <··············@timbral.net>,
 Evans Winner <······@timbral.net> wrote:

> Some research seems to indicate that at least OpenMCL, ACL and LispWorks
> maybe have some kind of facility that allows the definition of commands
> that can be used at the repl that look like--
> 
> :command
> 
> --or maybe--
> 
> :command arg1 [arg2 ... argn]
> 
> I know at least clisp has something like this at least in the debugger.
> Is this is standard Common Lisp facility?  (There is also a comma command
> syntax in scsh, i know, as well.)
> 
> Sorry if the question is vague; i don't know if there is an established
> term for this.  I can't find a reference in the Hyperspec.  In any case,
> it might be nice to be able to define commands like that for convenience
> at the repl.  Can it be done?--or is there a reason it's a bad idea?

There is no reason it is a bad idea. Most Lisp systems have something
like that.
There is no standard for this. Everybody does it somehow differently.
There is not even a widely used portable one for the terminal - besides
what you get when you use SLIME + Emacs. McCLIM comes with a
window-based listener.

One simple type of command is when the REPL allows you
to get rid of the top-level parentheses. LispWorks
does that for example for functions with arguments.
You can type at the LispWorks listener:

 CL-USER 7 > compile-file "foo.lisp"
 ;;; Compiling file foo.lisp ...


Useful REPLs have quite a few services:

* command loops, break loops, commands, command tables
* completion for commands, lisp symbols and arguments
* history (redo)
* dribble
* error handling, restarts, processes
* debugger, inspector, trace, step
* line editing
* help

and some more
From: Maciej Katafiasz
Subject: Re: Colon commands
Date: 
Message-ID: <af36ae77-c132-4aa0-ac1e-4bcd45af5973@c23g2000hsa.googlegroups.com>
On Jan 13, 11:36 am, Rainer Joswig <······@lisp.de> wrote:
> Useful REPLs have quite a few services:
>
[snip]
> * dribble

What's that?

Cheers,
Maciej
From: Zach Beane
Subject: Re: Colon commands
Date: 
Message-ID: <m3tzlh8zvd.fsf@unnamed.xach.com>
Maciej Katafiasz <········@gmail.com> writes:

> On Jan 13, 11:36 am, Rainer Joswig <······@lisp.de> wrote:
>> Useful REPLs have quite a few services:
>>
> [snip]
>> * dribble
>
> What's that?

http://www.lispworks.com/documentation/HyperSpec/Body/f_dribbl.htm has
information about the standard dribble.

Zach
From: Pascal Bourguignon
Subject: Re: Colon commands
Date: 
Message-ID: <87r6gl5xq1.fsf@thalassa.informatimago.com>
Evans Winner <······@timbral.net> writes:

> Some research seems to indicate that at least OpenMCL, ACL and LispWorks
> maybe have some kind of facility that allows the definition of commands
> that can be used at the repl that look like--
>
> :command
>
> --or maybe--
>
> :command arg1 [arg2 ... argn]
>
> I know at least clisp has something like this at least in the debugger.
> Is this is standard Common Lisp facility?  (There is also a comma command
> syntax in scsh, i know, as well.)

It is not standard.  The role of comma is defined only in the context
of backquote. 

> Sorry if the question is vague; i don't know if there is an established
> term for this.  I can't find a reference in the Hyperspec.  In any case,
> it might be nice to be able to define commands like that for convenience
> at the repl.  Can it be done?--or is there a reason it's a bad idea?


Note that at least in Allegro Common Lisp, the character prefixing
these commands (both user defined and system provided) is
configurable.


In the case of clisp, there's no prefix character for user commands.
They can be any symbol, not just keywords:

C/USER[23]> (com.informatimago.pjb::define-user-commands (:fecha date user1::dote)
                "Interactive commands"
              "Prints the date."
              (com.informatimago.common-lisp.interactive:date))
:FECHA
C/USER[24]> :fecha
2008-01-13 20:24:57
C/USER[25]> date
2008-01-13 20:25:00
C/USER[26]> user1::dote
2008-01-13 20:25:04




For clisp users:

To define more easily user commands in clisp, I use these macros:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter *user-command-groups* (make-hash-table :test (function equal)))
  (defun ensure-list (item) (if (listp item) item (list item))))

;;(setf custom:*user-commands* nil)

(defun generate-user-commands ()
  (setf custom:*user-commands*
        (let ((commands '()))
          (maphash
           (lambda (category command-list)
             (dolist (command  command-list)
               (destructuring-bind (names docstring body) command
                 (push (coerce
                        (let ((vfun (gensym)))
                          `(lambda ()
                             (flet ((,vfun () ,@body))
                               (list
                                ,(format nil ·····@(~{~S ~}~) ~A" names docstring)
                                ,@(mapcar (lambda (name)
                                            `(cons ,(format nil "~(~S~)" name)
                                                   (function ,vfun)))
                                          names)))))
                        'function) commands)))
             (push (coerce
                    `(lambda () (list ,(format nil "~2%~A:" category)))
                    'function) commands))
           *user-command-groups*)
          commands))
  (values))

(defmacro define-user-commands (names category docstring &body body)
  (let ((names (ensure-list names)))
    `(let ((entry (find ',names  (gethash ',category *user-command-groups* '())
                        :test (function equal)
                        :key (function first))))
       (if entry
           (setf (second entry) ',docstring
                 (third  entry) ',body)
           (push (list ',names ',docstring ',body)
                 (gethash ',category *user-command-groups* '())))
       (generate-user-commands)
       ',(first names))))

(defun delete-user-command (name)
  (maphash (lambda (category commands)
             (setf commands (delete name commands
                                    :test (function member)
                                    :key (function first)))
             (if commands
                 (setf (gethash category *user-command-groups*) commands)
                 (remhash category *user-command-groups*)))
            *user-command-groups*)
  (generate-user-commands))


Refer to the Implementation Notes for teh description of custom:*user-commands*.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Rainer Joswig
Subject: Re: Colon commands
Date: 
Message-ID: <joswig-3ABA20.21003713012008@news-europe.giganews.com>
In article <··············@thalassa.informatimago.com>,
 Pascal Bourguignon <···@informatimago.com> wrote:

> Evans Winner <······@timbral.net> writes:
> 
> > Some research seems to indicate that at least OpenMCL, ACL and LispWorks
> > maybe have some kind of facility that allows the definition of commands
> > that can be used at the repl that look like--
> >
> > :command
> >
> > --or maybe--
> >
> > :command arg1 [arg2 ... argn]
> >
> > I know at least clisp has something like this at least in the debugger.
> > Is this is standard Common Lisp facility?  (There is also a comma command
> > syntax in scsh, i know, as well.)
> 
> It is not standard.  The role of comma is defined only in the context
> of backquote.

The comma is used by some Lisp REPLs. They have REPL modes: command preferred and
Form preferred (plus command only, Lisp only). In command-preferred mode,
the comma is used to prefix Lisp code, so that it is not
interpreted as commands. It is called a 'form dispatch character'.
The 'Form preferred mode' has a command dispatch character, a colon.
Some CLIM listener may use this.

 Form preferred:

 :Copy File foo.lisp foo1.lisp    is interpreted as a command
 copy                             is interpreted as a variable

 Command preferred:

 Copy File foo.lisp foo1.lisp    is interpreted as a command
 ,copy                           is interpreted as a variable


...
From: Evans Winner
Subject: Re: Colon commands
Date: 
Message-ID: <86zlv9bby1.fsf@timbral.net>
Rainer Joswig <······@lisp.de> writes:

    The comma is used by some Lisp REPLs. They have REPL modes: command
    preferred and Form preferred (plus command only, Lisp only).  In
    command-preferred mode, the comma is used to prefix Lisp code, so
    that it is not interpreted as commands.  It is called a 'form
    dispatch character'.

But this is not part of standard CL, right?  Is there a portable way to
do it?  (It sounds like something one could create with a reader-macro,
but `:' and `,' as are a lot of other characters, so it might be
inherently un-portable...?)
From: Rainer Joswig
Subject: Re: Colon commands
Date: 
Message-ID: <joswig-D556A6.23321913012008@news-europe.giganews.com>
In article <··············@timbral.net>,
 Evans Winner <······@timbral.net> wrote:

> Rainer Joswig <······@lisp.de> writes:
> 
>     The comma is used by some Lisp REPLs. They have REPL modes: command
>     preferred and Form preferred (plus command only, Lisp only).  In
>     command-preferred mode, the comma is used to prefix Lisp code, so
>     that it is not interpreted as commands.  It is called a 'form
>     dispatch character'.
> 
> But this is not part of standard CL, right?

Right, REPLs are not an extensive part of the standard. Very
little about the REPL user interface is said in the standard.

>  Is there a portable way to
> do it?  (It sounds like something one could create with a reader-macro,
> but `:' and `,' as are a lot of other characters, so it might be
> inherently un-portable...?)

Either you use one of the portable REPLs (I've mentioned SLIME
and McCLIM) or you have to use the implementation specific
stuff.
From: Evans Winner
Subject: Re: Colon commands
Date: 
Message-ID: <86ve5xb7q5.fsf@timbral.net>
Rainer Joswig <······@lisp.de> writes:

    Either you use one of the portable REPLs (I've mentioned SLIME
    and McCLIM) or you have to use the implementation specific
    stuff.

Ok.  Got it.  Thank you.
From: Pascal J. Bourguignon
Subject: Re: Colon commands
Date: 
Message-ID: <7cbq7ofsrw.fsf@pbourguignon.anevia.com>
Evans Winner <······@timbral.net> writes:

> Rainer Joswig <······@lisp.de> writes:
>
>     The comma is used by some Lisp REPLs. They have REPL modes: command
>     preferred and Form preferred (plus command only, Lisp only).  In
>     command-preferred mode, the comma is used to prefix Lisp code, so
>     that it is not interpreted as commands.  It is called a 'form
>     dispatch character'.
>
> But this is not part of standard CL, right?  Is there a portable way to
> do it?  (It sounds like something one could create with a reader-macro,
> but `:' and `,' as are a lot of other characters, so it might be
> inherently un-portable...?)

You can implement REPLs portably, even REPLs implementing strange
syntaxes for characters like #\: and #\,.

But indeed, the REPL provided by the implementations are rather
implementation dependent, because they are rather underspecified by
the standard. You cannot provide the same kind of features in a REPL
based on punch card than in a REPL based on 3D virtual reality
interfaces, much less on mind reading devices.

-- 
__Pascal Bourguignon__
·························@anevia.com
http://www.anevia.com
From: Raffael Cavallaro
Subject: Re: Colon commands
Date: 
Message-ID: <2008011410593316807-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2008-01-14 08:20:19 -0500, ···@anevia.com (Pascal J. Bourguignon) said:

> You cannot provide the same kind of features in a REPL
> based on punch card than in a REPL based on 3D virtual reality
> interfaces, much less on mind reading devices.

I believe this last is more properly called a RESPL
;^)
From: Kent M Pitman
Subject: Re: Colon commands
Date: 
Message-ID: <uve5xw3e3.fsf@nhplace.com>
Evans Winner <······@timbral.net> writes:

> Some research seems to indicate that at least OpenMCL, ACL and LispWorks
> maybe have some kind of facility that allows the definition of commands
> that can be used at the repl that look like--
> 
> :command
> 
> --or maybe--
> 
> :command arg1 [arg2 ... argn]
> 
> I know at least clisp has something like this at least in the debugger.
> Is this is standard Common Lisp facility?  (There is also a comma command
> syntax in scsh, i know, as well.)

The use of colon has nothing to do with the ":" as far as I know.

Because keywords are bound to themselves, there is little point in a REPL
to asking their value.  Consequently, I believe the reason :foo was chosen
as a command is that one can just call READ normally and see if the result
was a keyword, and in that case just treat it as a command.  Consider the
following two interactions for LispWorks, for example.  In the first case,
there is no leading colon; in the second case, no colon at all.

  CL-USER 1 > keyword:?

  :bug-form <subject> &key <filename>
           Print out a bug report form, optionally to a file.
  :get <variable> <command identifier>
           Get a command from the history list and put it in a variable.
  :help    Produce this list.
  :his &optional <n1> <n2>
           List the command history, optionally the last n1 or range n1 to n2.
  :redo &optional <command identifier> 
           Redo a previous command, identified by its number or a substring.
  :use <new form> <old form> &optional <command identifier> 
           Redo command after replacing old form with new form.
  NIL

  CL-USER 1 > #.(intern "?" "KEYWORD")

  :bug-form <subject> &key <filename>
           Print out a bug report form, optionally to a file.
  :get <variable> <command identifier>
           Get a command from the history list and put it in a variable.
  :help    Produce this list.
  :his &optional <n1> <n2>
           List the command history, optionally the last n1 or range n1 to n2.
  :redo &optional <command identifier> 
           Redo a previous command, identified by its number or a substring.
  :use <new form> <old form> &optional <command identifier> 
           Redo command after replacing old form with new form.
  NIL

> Sorry if the question is vague; i don't know if there is an established
> term for this.  I can't find a reference in the Hyperspec.  In any case,
> it might be nice to be able to define commands like that for convenience
> at the repl.  Can it be done?--or is there a reason it's a bad idea?

You can easily write your own REPL, but there is no very strict
spec-defined REPL ... Just some general conventions about how variables
like -, +, ++, +++, *, etc. are intended to be managed _if_ there is a
REPL at all.

The main reason there is not a total convention about this is that in some
implementations there may be a desire to use other conventions.

On Symbolics Genera, : _was_ an escape into a command parser, in the case
of :form-preferred prompting, where everything was a form unless prefixed
by a parser.  In :form-only mode, there was no such escape.  In :command-only
mode, you were always in command mode.  In :command-preferred mode, I believe
you didn't need a prefix for commands but could use , to get to forms.  In
the Symbolics debugger, single keystrokes (characters with various "bucky
bits" set, what one would now call modifier bits) were co-opted as command
accelerators.

In LispWorks, there are two debugger modes--one that is command line based
and uses these commands, but another that is a GUI debugger and does not.

Common Lisp has tried to encourage uniformity where possible but not to tie
the hands of implementations wanting to do better.  A spec that required 
keywords to behave a certain way might be seen as one that required
implementations to have old-fashioned interfaces.  Or such was the fear,
as I recall.

There was pressure to remove the "environment functions/commands" from the
spec altogether.  But I'm glad they weren't removed.  Feeble as the conformance
requirements are for commands like ROOM, DESCRIBE, DISASSEMBLE, ED, 
DOCUMENTATION, etc., it's nice to have hinted to implementations that these
are things that matter to a community of users.  And they create touch points
for people who are new to an implementation to get a foothold.
From: Steven M. Haflich
Subject: Re: Colon commands
Date: 
Message-ID: <1nyjj.960$EZ3.487@nlpi070.nbdc.sbc.com>
Kent M Pitman wrote:

>> Some research seems to indicate that at least OpenMCL, ACL and LispWorks

> On Symbolics Genera, : _was_ an escape into a command parser, in the case
> of :form-preferred prompting, where everything was a form unless prefixed
> by a parser.

As a point of history, I believe I was the one responsible for this use 
of the colon char in a repl.  More than 20 years ago several of us at 
Franz were discussing how to provide various useful repl functionality 
such as load, compile-file, and abort without requiring the user to 
enter forms.  We were thrashing what syntax to use when I suggested the
leading colon char.  I can remember part of the message being "When was
the last time you needed to evaluate a keyword?"

Nonetheless, I'm pretty sure the LispM command repl had already used
colon in some sort of similar context, although with different
machinery.  I have never pondered how the inheritance of this feature
passed from one implementation to another, and am disinterested in
doing it now.

> Common Lisp has tried to encourage uniformity where possible but not to tie
> the hands of implementations wanting to do better.

One could argue that Common Lisp has tried to discourage doing better
(in the language development sense) by failing to tie the hands of
implementations, but if I presented that question casual readers would
think me a troll...

(Do implementations have hands?)