From: Jybo.
Subject: a menu in lisp ?
Date: 
Message-ID: <8v1s1k$a26$1@nnrp1.deja.com>
   Hi everybody,

   I'd like to know if it's possible to implement a kind of menu in
lisp, something like this :

1 --> choice 1
2 --> choice 2
3 --> choice 3
What is your choice ?

   If it's possible, what are the fonctions I have to use ?

   Thanks.

   Jybo.


Sent via Deja.com http://www.deja.com/
Before you buy.

From: Rainer Joswig
Subject: Re: a menu in lisp ?
Date: 
Message-ID: <joswig-C2B45E.02263617112000@news.is-europe.net>
In article <············@nnrp1.deja.com>, Jybo. <····@netcourrier.com> 
wrote:

>    Hi everybody,
> 
>    I'd like to know if it's possible to implement a kind of menu in
> lisp, something like this :

Sure.

> 1 --> choice 1
> 2 --> choice 2
> 3 --> choice 3
> What is your choice ?
> 
>    If it's possible, what are the fonctions I have to use ?

Do you want a graphical menu (2d or 3d) or
just a simple textual menu?

A simple textual version using CLIM (Common Lisp Interface Manager):

(defun choose-one (&rest items)
  (clim:accept `(clim:member-sequence ,items)))

A more graphical version:

(defun choose-one (&rest items)
  (clim:accepting-values (*standard-output*)
    (clim:accept `(clim:member-sequence ,items)
                 :view clim:+radio-box-view+
                 :stream *standard-output*)))

-- 
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Kent M Pitman
Subject: Re: a menu in lisp ?
Date: 
Message-ID: <sfwg0kratw4.fsf@world.std.com>
Rainer Joswig <······@corporate-world.lisp.de> writes:

> In article <············@nnrp1.deja.com>, Jybo. <····@netcourrier.com> 
> wrote:
> 
> >    Hi everybody,
> > 
> >    I'd like to know if it's possible to implement a kind of menu in
> > lisp, something like this :
> 
> Sure.
> 
> > 1 --> choice 1
> > 2 --> choice 2
> > 3 --> choice 3
> > What is your choice ?
> > 
> >    If it's possible, what are the fonctions I have to use ?
> 
> Do you want a graphical menu (2d or 3d) or
> just a simple textual menu?
> 
> A simple textual version using CLIM (Common Lisp Interface Manager):
> 
> (defun choose-one (&rest items)
>   (clim:accept `(clim:member-sequence ,items)))
> 
> A more graphical version:
> 
> (defun choose-one (&rest items)
>   (clim:accepting-values (*standard-output*)
>     (clim:accept `(clim:member-sequence ,items)
>                  :view clim:+radio-box-view+
>                  :stream *standard-output*)))

Or without CLIM, something like:

 (DEFUN CHOOSE-FROM (ITEMS)
   ;; Returns two values: (1) the choice and (2) whether the choice is valid.
   ;; In the case that ITEMS is NIL, two NILs are returned, to 
   ;; distinguish from a case where NIL was among the ITEMS and selected,
   ;; in which case NIL, T is returned.
   (COND ((NOT ITEMS) (RETURN-FROM CHOOSE-FROM (VALUES NIL NIL)))
	 ((NOT (REST ITEMS)) 
	  (RETURN-FROM CHOOSE-FROM (VALUES (FIRST ITEMS) T))))
   (LET ((*READ-EVAL* NIL))
     (FLET ((SHOW-MENU ()
	      (LOOP FOR I FROM 1
                    FOR ITEM IN ITEMS
                    DO (FORMAT T "~&~D: ~A~%"))))
       (SHOW-MENU)
       (LOOP WITH N = (LENGTH ITEMS)
             FOR CHOICE = (PROGN (FORMAT T "~&Choice: ")
	    	            (FORCE-OUTPUT)
			    (READ))
             DO (COND ((NOT (INTEGERP CHOICE))
		       (FORMAT T "~&Please type a number.~%"))
		      ((OR (NOT (PLUSP CHOICE)) (> CHOICE N))
		       (FORMAT T "~&Try a number between 1 and ~D." N))
		      (T
		       (RETURN (VALUES
				 (NTH ;; People count from 1, machines from 0
				      (- CHOICE 1)
				      ITEMS)
			       T))))
		(SHOW-MENU)))))

No, I didn't test this code.  But it's probably at least close to right.
Caveat emptor.

Of course, one could just do

 (DEFUN CHOOSE-FROM (ITEMS)
   (LOOP FOR I FROM 1 FOR ITEM IN ITEMS DO (PRINT (LIST I ITEM)))
   (PRINT 'CHOICE)
   (NTH (1- (READ)) ITEMS))

if you prefer less code and less error checking.

No, I didn't test that one either.
From: Kent M Pitman
Subject: Re: a menu in lisp ?
Date: 
Message-ID: <sfw1ywai2rl.fsf@world.std.com>
Kent M Pitman <······@world.std.com> writes:

Thomas Russ spotted this typo in my code, btw:

>      (FLET ((SHOW-MENU ()
>              (LOOP FOR I FROM 1
>                    FOR ITEM IN ITEMS

 ;; Replace:         DO (FORMAT T "~&~D: ~A~%"))))
 ;; With:
                     DO (FORMAT T "~&~D: ~A~%" I ITEM))))
From: Iban Hatchond
Subject: Re: a menu in lisp ?
Date: 
Message-ID: <3A1548AF.102A06EB@emi.u-bordeaux.fr>
And if you don't have CLIM, try the graphical stuff you, can find on the clx
help, or we did it in a first window manager version (that I'll try to post
soon)
http://www.emi.u-bordeaux.fr/~boninfan/TER.

Otherwise, I'm actually working on the Free-CLIM menu, so it may interrest you.
I guess it will be available, in one or two weeks.