我一直在教計算機科學很長一段時間。最常教的語言是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函數中,但我無法讓它正常工作...... –