Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Common Lisp program error

This is the code:

 (defun my-random (max &optional least)
    (setf max (+ max 1))
    (if (null least)
        (random max)
        (if (numberp least)
            (if (numberp max)
                (let ((x (random (- max least))))
                    (+ x least))
                (format t "~%在my-random函数中发现错误: 第一个输入值不是一个数字!~%"))
            (format t "~%在my-random函数中发现错误: 第二个输入值不是一个数字!~%"))))

;my-random 100 1

(defun prozentual (probability command)
    (if (numberp probability)
        (if (listp command)
            (if (> 101 probability)
                (if (> probability (my-random 101 1))
                    command)
                (format t "~%在prozentual函数中发现错误: 概率不得多于100!~%))
            (format t "~%在prozentual函数中发现错误: 第二个参数不是一个命令!~%))
        (format t "~%在prozentual函数中发现错误: 第一个参数不是一个数字!~%)))

;prozentual 100 (format t "as")

This is the Clozure Common Lisp Version 1.6 runs on the results:
? (load "mika.cl")
> Error: Reader error: Illegal symbol syntax.
> While executing: CCL::%PARSE-TOKEN, in process listener(1).
> Type :POP to abort, :R for a list of available restarts.
> Type :? for other options.
1 > (my-random 101 1)
61
1 > (my-random 101 100)
100
1 > (my-random 101 100)
100
1 > (my-random 101 100)
100
1 > (my-random 101 100)
100

Now "prozentual" function can not be used ..

like image 613
46897asd Avatar asked Dec 10 '25 21:12

46897asd


1 Answers

YOu're missing the doublequotes at the end of the format strings.

(defun prozentual (probability command)
    (if (numberp probability)
        (if (listp command)
            (if (> 101 probability)
                (if (> probability (my-random 101 1))
                    command)
                (format t "~%在prozentual函数中发现错误: 概率不得多于100!~%"))
            (format t "~%在prozentual函数中发现错误: 第二个参数不是一个命令!~%"))
        (format t "~%在prozentual函数中发现错误: 第一个参数不是一个数字!~%")))
like image 59
Barmar Avatar answered Dec 13 '25 14:12

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!