我一直在教计算机科学很长一段时间。最常教的语言是C#,C++,Java,Python等。我在每学期添加其他语言的示例,如Perl,Ruby等,以便学生可以看到跨语言的共同点。我一直在Common Lisp上尝试我的手,不得不承认,近40年来我第一次用语言撞墙。在ideone.com上运行Common Lisp?
Common Lisp让我难以找到一个简单的示例程序来编译和运行。我需要在ideone.com上运行代码,以便学生可以自行尝试,并对发生的情况进行更改。我将不胜感激任何帮助,我可以得到这一整个一周的斗争是关于我可以采取的一切。
下面是代码:
(defclass employee() ;;class definition header
((empid :accessor employee-empid;;member variable accessible and preset
:initform 230
:initarg :empid)
(name :accessor employee-name;;member variable accessible and preset
:intform 'bill
:intarg :name)
(pay :accessor employee-pay;;member variable accessible and preset
:initform 10
:initarg :pay)))
(defmethod infofun ((p employee));;member method to allow two member vars to be changed
(print "The Worker: " : (employee-name p))
(setf (employee-pay p))
(setf (employee-empid p)))
(setq w1(make-instance 'employee :empid 100 :name 'worker1 :pay 47));;instance of class for w1
(setq w2(make-instance 'employee :empid 102 :name 'worker1 :pay 57));;instance of class for w2
(setq w3(make-instance 'employee :empid 103 :name 'worker1 :pay 67));;instance of class for w3
(describe w1);;get general info from List about the instance w1
(describe w2)
(describe w3)
(infofun w1);;run the member function, change the member vars
(infofun w2)
(infofun w3)
(setf (employee-pay w1) 147);;change a member var by code
(describe w1);;look at w1 again and note the values
(infofun w1);;change w1 again
(describe w1);;look at w1 one more time and check the new values
我希望有人能帮助我与此有关。
感谢
博士牛逼
您需要检查INFOFUN:1)什么是允许的参数打印功能。 b)单个冒号肯定是错误的c)如果你调用SETF它期望两个参数。你只提供一个。 –
另外:如果您发布问题,您还应该提供错误消息。 –
由于运行时发生故障,因此没有错误消息。就像我期望的那样没有输出。我一直坚信,问题是在infofun函数中,但我无法让它正常工作...... –