vb调用lisp中vlx函数,我如何在Lisp中调用另一个函数;

My program is supposed to convert a given temperature from Fahrenheit to Centigrade or the other way around. It takes in a list containing a number and a letter. The letter is the temperature and the letter is the unit we are in. Then I call the appropriate function either F-to-C or C-to-F. How do I call the functions with the given list that was first checked in my temperature-conversion function. Here is my code.

(defun temperature-conversion (lst)

(cond

((member 'F lst) (F-to-C))

((member 'C lst) (C-to-F))

(t (print "You didn't enter a valid unit for conversion"))

)

)

(defun F-to-C ()

;;(print "hello")

(print (temperature-conversion(lst)))

)

(defun C-to-F ()

(print "goodbye"))

;;(print (temperature-conversion '(900 f)))

(setf data1 '(900 f))

解决方案

You have infinite recursion: temperature-conversion calls F-to-C which calls temperature-conversion again.

I would do this:

(defun c2f (c) (+ 32 (/ (* 9 c) 5)))

(defun f2c (f) (/ (* 5 (- f 32)) 9))

(defun temperature-conversion (spec)

(ecase (second spec)

(C (c2f (first spec)))

(F (f2c (first spec)))))

(temperature-conversion '(32 f))

==> 0

(temperature-conversion '(100 c))

==> 212

(temperature-conversion '(100))

*** - The value of (SECOND SPEC) must be one of C, F

The value is: NIL

The following restarts are available:

ABORT :R1 Abort main loop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值