私は長い間コンピュータ科学を教えてきました。最もよく教える言語は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をチェックする必要があります。a)印刷機能に引数許可されています。 b)単一のコロンが間違っているc)SETFを呼び出すと、2つの引数が必要です。あなたは1つしか提供しません。 –
:あなたが問題を投稿した場合は、エラーメッセージも提供する必要があります。 –
エラーは実行時に発生するため、エラーメッセージはありません。私は期待どおりの出力がありません。私は問題がinfofun関数にあると確信していますが、私はそれを働かせることができません... –