From: ········@gmail.com
Subject: running code?
Date: 
Message-ID: <1190451617.706931.192240@y42g2000hsy.googlegroups.com>
How do I get this code to run:

;;; ROMAN1.CL - unordered production system to
;;; convert to Roman numerals.

;;; (C) Copyright 1995 by Steven L. Tanimoto.
;;; This program is described in Chapter 3 ("Productions Systems
;;; and Pattern Matching") of
;;; "The Elements of Artificial Intelligence Using Common Lisp," 2nd
ed.,
;;; published by W. H. Freeman, 41 Madison Ave., New York, NY 10010.
;;; Permission is granted for noncommercial use and modification of
;;; this program, provided that this copyright notice is retained
;;; and followed by a notice of any modifications made to the program.

(defun roman1 ()
  "Roman numeral conversion with an unordered P.S."
  (let ((x nil))
    (loop
      (cond
        ((null x) (format t "Enter number:") (setf x (read)))
        ((and (not (null x)) (> x 39))
         (format t "too big~%") (setf x nil))
        ((and (not (null x)) (< x 40) (> x 9))
         (prin1 'x) (setf x (- x 10)) )
        ((and (not (null x)) (= x 9))
         (prin1 'ix) (setf x 0) )
        ((and (not (null x)) (< x 9) (> x 4))
         (prin1 'v) (setf x (- x 5)) )
        ((and (not (null x)) (= x 4))
         (prin1 'iv) (setf x 0) )
        ((and (not (null x)) (< x 4) (> x 0))
         (prin1 'i) (setf x (1- x)) )
        ((zerop x) (setf x nil) (terpri))
         ) ) ) )


I pasted it into my cmucl and then it said "ROMAN1".

How do I execute/run ROMAN1?

Lisp 9000

From: Rainer Joswig
Subject: Re: running code?
Date: 
Message-ID: <joswig-6D942E.11522822092007@news-europe.giganews.com>
In article <························@y42g2000hsy.googlegroups.com>,
 ·········@gmail.com" <········@gmail.com> wrote:

> How do I get this code to run:
> 
> ;;; ROMAN1.CL - unordered production system to
> ;;; convert to Roman numerals.
> 
> ;;; (C) Copyright 1995 by Steven L. Tanimoto.
> ;;; This program is described in Chapter 3 ("Productions Systems
> ;;; and Pattern Matching") of
> ;;; "The Elements of Artificial Intelligence Using Common Lisp," 2nd
> ed.,
> ;;; published by W. H. Freeman, 41 Madison Ave., New York, NY 10010.
> ;;; Permission is granted for noncommercial use and modification of
> ;;; this program, provided that this copyright notice is retained
> ;;; and followed by a notice of any modifications made to the program.
> 
> (defun roman1 ()
>   "Roman numeral conversion with an unordered P.S."
>   (let ((x nil))
>     (loop
>       (cond
>         ((null x) (format t "Enter number:") (setf x (read)))
>         ((and (not (null x)) (> x 39))
>          (format t "too big~%") (setf x nil))
>         ((and (not (null x)) (< x 40) (> x 9))
>          (prin1 'x) (setf x (- x 10)) )
>         ((and (not (null x)) (= x 9))
>          (prin1 'ix) (setf x 0) )
>         ((and (not (null x)) (< x 9) (> x 4))
>          (prin1 'v) (setf x (- x 5)) )
>         ((and (not (null x)) (= x 4))
>          (prin1 'iv) (setf x 0) )
>         ((and (not (null x)) (< x 4) (> x 0))
>          (prin1 'i) (setf x (1- x)) )
>         ((zerop x) (setf x nil) (terpri))
>          ) ) ) )
> 
> 
> I pasted it into my cmucl and then it said "ROMAN1".
> 
> How do I execute/run ROMAN1?
> 
> Lisp 9000

I think the ROMAN1 function has taken all available parentheses.
Give CMUCL some time to rest and to produce some more in the background.
Five minutes should be fine. In the meantime you can look at
the source and see how you get out of the LOOP later.

Then try:

(roman1)

-- 
http://lispm.dyndns.org
From: ········@gmail.com
Subject: Re: running code?
Date: 
Message-ID: <1190512311.064570.74750@22g2000hsm.googlegroups.com>
On Sep 22, 5:52 am, Rainer Joswig <······@lisp.de> wrote:
> In article <························@y42g2000hsy.googlegroups.com>,
>
>
>
>  ·········@gmail.com" <········@gmail.com> wrote:
> > How do I get this code to run:
>
> > ;;; ROMAN1.CL - unordered production system to
> > ;;; convert to Roman numerals.
>
> > ;;; (C) Copyright 1995 by Steven L. Tanimoto.
> > ;;; This program is described in Chapter 3 ("Productions Systems
> > ;;; and Pattern Matching") of
> > ;;; "The Elements of Artificial Intelligence Using Common Lisp," 2nd
> > ed.,
> > ;;; published by W. H. Freeman, 41 Madison Ave., New York, NY 10010.
> > ;;; Permission is granted for noncommercial use and modification of
> > ;;; this program, provided that this copyright notice is retained
> > ;;; and followed by a notice of any modifications made to the program.
>
> > (defun roman1 ()
> >   "Roman numeral conversion with an unordered P.S."
> >   (let ((x nil))
> >     (loop
> >       (cond
> >         ((null x) (format t "Enter number:") (setf x (read)))
> >         ((and (not (null x)) (> x 39))
> >          (format t "too big~%") (setf x nil))
> >         ((and (not (null x)) (< x 40) (> x 9))
> >          (prin1 'x) (setf x (- x 10)) )
> >         ((and (not (null x)) (= x 9))
> >          (prin1 'ix) (setf x 0) )
> >         ((and (not (null x)) (< x 9) (> x 4))
> >          (prin1 'v) (setf x (- x 5)) )
> >         ((and (not (null x)) (= x 4))
> >          (prin1 'iv) (setf x 0) )
> >         ((and (not (null x)) (< x 4) (> x 0))
> >          (prin1 'i) (setf x (1- x)) )
> >         ((zerop x) (setf x nil) (terpri))
> >          ) ) ) )
>
> > I pasted it into my cmucl and then it said "ROMAN1".
>
> > How do I execute/run ROMAN1?
>
> > Lisp 9000
>
> I think the ROMAN1 function has taken all available parentheses.
> Give CMUCL some time to rest and to produce some more in the background.
> Five minutes should be fine. In the meantime you can look at
> the source and see how you get out of the LOOP later.
>
> Then try:
>
> (roman1)
>
> --http://lispm.dyndns.org

Thanks Rainer.

Lisp 9000
From: Alan Crowe
Subject: Re: running code?
Date: 
Message-ID: <86ir62y408.fsf@cawtech.freeserve.co.uk>
·········@gmail.com" <········@gmail.com> writes:

> How do I get this code to run:
> 
> ;;; ROMAN1.CL - unordered production system to
> ;;; convert to Roman numerals.
> 
> ;;; (C) Copyright 1995 by Steven L. Tanimoto.

Tanimoto clearly shares my joy in writing eccentric
code. You might want to compare his code to my rewrite and
enjoy the surprise that both are ANSI Common Lisp even
though they look so different

CL-USER> (defun roman (x)
           (loop 
            if (< 9 x) do (prin1 'x)(decf x 10)
            if (= 9 x) do (prin1 'ix)(setf x 0)
            if (< 4 x 9) do (prin1 'v)(decf x 5)
            if (= x 4) do (prin1 'iv)(setf x 0)
            if (< 0 x 4) do (prin1 'i)(decf x)
            if (= x 0) do (terpri)(loop-finish)))
ROMAN
CL-USER> (dotimes (i 40)
           (roman i))

I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII
XIII
XIV
XV
XVI
XVII
XVIII
XIX
XX
XXI
XXII
XXIII
XXIV
XXV
XXVI
XXVII
XXVIII
XXIX
XXX
XXXI
XXXII
XXXIII
XXXIV
XXXV
XXXVI
XXXVII
XXXVIII
XXXIX

Alan Crowe
Edinburgh
Scotland
From: Chris Russell
Subject: Re: running code?
Date: 
Message-ID: <1190487881.621070.54850@k79g2000hse.googlegroups.com>
On 22 Sep, 19:00, Alan Crowe <····@cawtech.freeserve.co.uk> wrote:
> ·········@gmail.com" <········@gmail.com> writes:
> > How do I get this code to run:
>
> > ;;; ROMAN1.CL - unordered production system to
> > ;;; convert to Roman numerals.
>
> > ;;; (C) Copyright 1995 by Steven L. Tanimoto.
>
> Tanimoto clearly shares my joy in writing eccentric
> code. You might want to compare his code to my rewrite and
> enjoy the surprise that both are ANSI Common Lisp even
> though they look so different
>
> CL-USER> (defun roman (x)
>            (loop
>             if (< 9 x) do (prin1 'x)(decf x 10)
>             if (= 9 x) do (prin1 'ix)(setf x 0)
>             if (< 4 x 9) do (prin1 'v)(decf x 5)
>             if (= x 4) do (prin1 'iv)(setf x 0)
>             if (< 0 x 4) do (prin1 'i)(decf x)
>             if (= x 0) do (terpri)(loop-finish)))
> ROMAN
Alternatively:

(defun roman(&optional (x(progn (write "Enter number:")(read))))
    (format t ··@R"x))

(defun roman(&optional (x(progn (write "Enter number:")(read))))
  (mapc (lambda (y z)
          (multiple-value-bind (val rem)(truncate x y)
	    (setf x rem)
	    (dotimes (i val)
		(prin1 z)))) '(10 9 5 4 1) '(x ix v iv i)))
From: ········@gmail.com
Subject: Re: running code?
Date: 
Message-ID: <1190512284.302338.9120@r29g2000hsg.googlegroups.com>
On Sep 22, 2:00 pm, Alan Crowe <····@cawtech.freeserve.co.uk> wrote:
> ·········@gmail.com" <········@gmail.com> writes:
> > How do I get this code to run:
>
> > ;;; ROMAN1.CL - unordered production system to
> > ;;; convert to Roman numerals.
>
> > ;;; (C) Copyright 1995 by Steven L. Tanimoto.
>
> Tanimoto clearly shares my joy in writing eccentric
> code. You might want to compare his code to my rewrite and
> enjoy the surprise that both are ANSI Common Lisp even
> though they look so different
>
> CL-USER> (defun roman (x)
>            (loop
>             if (< 9 x) do (prin1 'x)(decf x 10)
>             if (= 9 x) do (prin1 'ix)(setf x 0)
>             if (< 4 x 9) do (prin1 'v)(decf x 5)
>             if (= x 4) do (prin1 'iv)(setf x 0)
>             if (< 0 x 4) do (prin1 'i)(decf x)
>             if (= x 0) do (terpri)(loop-finish)))
> ROMAN
> CL-USER> (dotimes (i 40)
>            (roman i))
>
> I
> II
> III
> IV
> V
> VI
> VII
> VIII
> IX
> X
> XI
> XII
> XIII
> XIV
> XV
> XVI
> XVII
> XVIII
> XIX
> XX
> XXI
> XXII
> XXIII
> XXIV
> XXV
> XXVI
> XXVII
> XXVIII
> XXIX
> XXX
> XXXI
> XXXII
> XXXIII
> XXXIV
> XXXV
> XXXVI
> XXXVII
> XXXVIII
> XXXIX
>
> Alan Crowe
> Edinburgh
> Scotland

Hi Alan,

That was nice.

Lisp 9000
From: Matthias Buelow
Subject: Re: running code?
Date: 
Message-ID: <5ll76kF8gkq2U1@mid.dfncis.de>
········@gmail.com wrote:

> How do I execute/run ROMAN1?

You better don't, or the universe will collapse.. something like the
above is begging on its knees for a recursive solution, which would
instantly de-uglify the whole thing. Each setf in the code above is like
a red-hot needle stuck in my eyeballs... But of course, YMMV. :)