Subject: [clisp-list] CLisp prompts

From: Michael Graffam <[email-masked]>
Date: Thu Nov 27 09:55:06 2003

Hello all,

I'm new to Lisp, so please be gentle.

Could someone please help me out with changing clisp's command line
prompts?

I can't seem to redefine the system::prompt-string functions. I can do it
by setting the *prompt* variable, but this has the undesired
effect of always placing a '>' (system::prompt-string3) after my prompt.

Can I get complete control over the prompt? I'd like to embed some
character coding into it (to establish a connection with TeXmacs).

I'd like to construct the following prompt (\002 is ASCII 2, etc)

\002channel:prompt\005*PROMPT*\005

*PROMPT* would be the displayed text of the prompt -- the usual clisp
strings would be fine. I just don't want anything after the final \005

---

From: Pascal J.Bourguignon <[email-masked]>
Date: Thu Nov 27 10:29:03 2003

> strings would be fine. I just don't want anything after the final \005

In my copy of CLisp implementation notes, it's written:

    The variable CUSTOM:*PROMPT* controls the appearance of the
    prompt. When its value is a function, it is called and its value
    is printed with PRINC. Otherwise, the value itself is printed with
    PRINC. The default value of CUSTOM:*PROMPT* prints "package[n]> "
    where package is the shortest (nick)name of the current package
    *PACKAGE* if it is the same as it was in the beginning or if it
    does not contain symbol T (it is assumed that in the latter case
    you would want to keep in mind that your current package is
    something weird); and n is the ordinal number of the current
    prompt (hopefully, it will remain finite). To help you in
    constructing your own fancy prompts, two functions and one
    variable are provided:

    function EXT:PROMPT-NEW-PACKAGE

        returns *PACKAGE* or NIL if the current package is the same as
        it was initially

    function EXT:PACKAGE-SHORT-NAME

        takes one argument, a package, and returns its shortest name
        or nickname

    variable EXT:*COMMAND-INDEX*

        contains the current prompt number; it is your responsibility
        to increment it (this variable is bound to 0 before saving the
        memory image).

There is no mention of SYSTEM::PROMPT-STRING

In any case,  the '::' should have alterted you  on the PRIVATE nature
of  SYSTEM::PROMPT-STRING, that  is  of the  informal INTERDICTION  of
accessing and modifying it.

Personnaly, I've got no problem in changing the value of CUSTOM:*PROMPT*

[29]> (let ((my-counter 0)) 
        (defun my-prompt () (format nil "~D ---> " (incf my-counter))))
MY-PROMPT
[30]> (setf custom:*prompt* (function my-prompt))
#<CLOSURE MY-PROMPT NIL (DECLARE (SYSTEM::IN-DEFUN MY-PROMPT))
  (BLOCK MY-PROMPT (FORMAT NIL "~D ---> " (INCF MY-COUNTER)))>
1 ---> > 

For   the  "  >"   returned  by   SYSTEM::PROMPT-STRING3,  I   see  no
documentation about  how to  prevent it, but  you can  always redefine
this function:

5 ---> (EXT:WITHOUT-PACKAGE-LOCK ("SYSTEM")
         (defun SYSTEM::PROMPT-STRING3 () ""))
SYSTEM::PROMPT-STRING3
6 ---> "Hello World!"
"Hello World!"
7 ---> 

-- 
__Pascal_Bourguignon__                          http://www.informatimago.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Living free in Alaska or in Siberia, a grizzli's life expectancy is 35 years,
but no more than 8 years in captivity.           http://www.theadvocates.org/

---

From: Michael Graffam <[email-masked]>
Date: Thu Nov 27 13:24:14 2003

>          (defun SYSTEM::PROMPT-STRING3 () ""))

Thank you! That was the key to my problem.

Would you happen to know how to suppress the warnings generated by that
code? I redefine the prompt in an initialization file, and I'd like to
suppress the warnings during startup.

This is great, though. Thanks again for your help.

I now have CLisp running as a plugin to GNU TeXmacs (www.texmacs.org).
This will likely be in the next development release of TeXmacs in a few
days. Next up is to get some Lisp code written that generates TeXmacs
markup (I'm looking forward to viewing Lisp programs graphically in
TeXmacs!)

Of course, TeXmacs can render LaTeX too, so existing Lisp code will prove
useful.

---

From: Pascal J.Bourguignon <[email-masked]>
Date: Thu Nov 27 13:49:06 2003

> suppress the warnings during startup.

What do  you mean? The  point of EXT:WITHOUT-PACKAGE-LOCK is  to avoid
any warning about redefining a function in a locked package.  

[8]> (EXT:WITHOUT-PACKAGE-LOCK ("SYSTEM") (defun SYSTEM::PROMPT-STRING3 () ""))
SYSTEM::PROMPT-STRING3
[9]

What warning do you get?

> Of course, TeXmacs can render LaTeX too, so existing Lisp code will prove

That's  nice to see  more applications  using common-lisp  (instead of
scheme/guile) as an extension language!

---

From: Michael Graffam <[email-masked]>
Date: Fri Nov 28 03:11:04 2003

> [8]> (EXT:WITHOUT-PACKAGE-LOCK ("SYSTEM") (defun SYSTEM::PROMPT-STRING3 () ""))

WARNING:
DEFUN/DEFMACRO: redefining function SYSTEM::PROMPT-STRING1 in
/usr/share/TeXmacs/plugins/clisp/lisp/texmacsrc.lisp, was defined in
/var/tmp/bach-build/BUILD/clisp-2.31/src/reploop.fas
WARNING:
DEFUN/DEFMACRO: redefining function SYSTEM::PROMPT-STRING2 in
/usr/share/TeXmacs/plugins/clisp/lisp/texmacsrc.lisp, was defined in
/var/tmp/bach-build/BUILD/clisp-2.31/src/reploop.fas
WARNING:
DEFUN/DEFMACRO: redefining function SYSTEM::PROMPT-STRING3 in
/usr/share/TeXmacs/plugins/clisp/lisp/texmacsrc.lisp, was defined in
/var/tmp/bach-build/BUILD/clisp-2.31/src/reploop.fas

---

From: Michael Graffam <[email-masked]>
Date: Sat Nov 29 18:21:02 2003

This is question might be a bit too general, but I really don't know where
else to ask.

Is there an online resource with snippets of simple Lisp code that aims to
teach good Lisp style?

I'm an old C hand, so I tend to do stuff like this:

(defun factorial (n)
	(if (< n 2) 1
	   (* n (factorial (- n 1)))
	)
)

but this is confusing even to me :), and I understand that most everyone
finds it ugly.

I'm committed to learning Lisp and doing it well, but I don't want to
pick up bad habits along the way. On the other hand, I just assume dig
in and get my hands dirty -- table manners be damned.

---

From: Adam Warner <[email-masked]>
Date: Sat Nov 29 19:20:01 2003

> This is question might be a bit too general, but I really don't know where

The Usenet newsgroup comp.lang.lisp.

> Is there an online resource with snippets of simple Lisp code that aims to

This Postscript presentation is outstanding:
<http://www.norvig.com/luv-slides.ps>

Regards,
Adam

---

From: james anderson <[email-masked]>
Date: Sun Nov 30 01:25:02 2003

> Is there an online resource with snippets of simple Lisp code that 

one starting point is: http://www.lisp.org . in particular 
http://www.lisp.org/table/style.htm and 
http://www.lisp.org/table/learn.htm.

on the other hand, read lisp code. when you do that and you will 
develop your own criteria.

> 	   (* n (factorial (- n 1)))
if it fits on one line

(defun factorial (n)
   (if (< n 2) 1 (* n (factorial (- n 1)))))

or depending on the context even

(defun factorial (n) (if (< n 2) 1 (* n (factorial (- n 1)))))

otherwise

(defun factorial (n)
   (if (< n 2)
     1
     (* n (factorial (- n 1)))))

---

From: Sam Steingold <[email-masked]>
Date: Mon Dec 1 11:38:12 2003

> * Michael Graffam <[email-masked]> [2003-11-27 12:54:47 -0500]:
>

CLISP prompt consists of 4 parts.

1. (SYS::PROMPT-STRING1) string.  empty by default.

2. Break.<level> or Step.<level> (optional)

3. (SYS::PROMPT-STRING2) string - whatever *PROMPT* is, see
   <http://clisp.cons.org/impnotes/prompt.html>

4. (SYS::PROMPT-STRING3) string, "> " by default.

Note that only *PROMPT* (part 3) is customizable.

The reason for non-customizable PROMPT-STRING1 and PROMPT-STRING3 is
probably to use different fonts for prompts and to help CLISP running
under Emacs.

E.g., PROMPT-STRING1 might output a control string which will make the
terminal print bold characters and PROMPT-STRING3 will revert to the
original font, so that the prompt is bold and the rest is normal (to
make it easier for the user to distinguish CLISP output from his own
commands).

When CLISP is running under Emacs, its prompt must match
`inferior-lisp-prompt' or a similar variable in ILisp, so
PROMPT-STRING3 prints something that matches it.
Note that the above ELisp variable is semi-obsolete (it is used only
when `comint-use-prompt-regexp-instead-of-fields' is non-nil, and that
is nil by default), so this use of PROMPT-STRING3 is not applicable
these days.

It might make sense to export functions PROMPT-START (instead of
PROMPT-STRING1), PROMPT-BODY (instead of PROMPT-STRING2 and *PROMPT*)
and PROMPT-FINISH (instead of PROMPT-STRING3), and default PROMPT-START
and PROMPT-FINISH to return "".

I hope Bruno will clarify this issue further.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Do not worry about which side your bread is buttered on: you eat BOTH sides.

---

From: Michael Graffam <[email-masked]>
Date: Mon Dec 1 12:20:08 2003

> probably to use different fonts for prompts and to help CLISP running

Interestingly enough, the fairly rigid format of the prompts inhibits
CLISP from running under TeXmacs (though this has been solved, as per
previous messages on this list).

> and PROMPT-FINISH to return "".

Yes. Having a clean way to fully define the prompts would be useful in
communicating with external software.

Though, I think I'll have to mention all this on texmacs-dev because
it provides an argument for making TeXmacs more flexible in this regards,
as per Emacs.

---

From: Sam Steingold <[email-masked]>
Date: Mon Dec 1 20:17:09 2003

> * Michael Graffam <[email-masked]> [2003-12-01 15:19:37 -0500]:
>

Then we will probably need PROMPT-STEP and PROMPT-BREAK parts too.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Linux: Telling Microsoft where to go since 1991.

---

From: Michael Graffam <[email-masked]>
Date: Tue Dec 2 06:25:07 2003

> Then we will probably need PROMPT-STEP and PROMPT-BREAK parts too.

Yeah. Having functions get called at various points in the prompting
is great, it allows a nice way to link into other software. I like
this better than bash's solution. But for software control through pipes,
you need to have control over what is sent, and when.

Obscure typesetting across pipes isn't the only area of application,
either -- controlling other odd software, like text-to-speech or
braille terminals.

In UNIX, never assume stdio is read by a human. :)