theclapp

Search theclapp.blog-city.com

 

Chapter 4, exercise 1

posted Friday, 10-Jan-2003
13:44 -- starting 4.1, Java version
13:47 -- done
---
// ch04_ex01.java

import java.util.*;

class ch04_ex01 {
ch04_ex01() {
System.out.println( "Creating a ch04_ex01" );
}

public static void main( String[] args ) {
ch04_ex01 o = new ch04_ex01();
}
}
---

14:48 -- Starting 4.1, Lisp version
15:16 -- done

---
;;; chapter 4, exercise 1
;;; Not entirely applicable to Common Lisp, since it has no "constructors", as
;;; such, but I'll give it a try. See
;;; http://groups.google.com/groups?threadm=uv6adjq6dfx.fsf%40tenebrae.ai.mit.edu
;;; for a discussion on why you shouldn't just define a "make-ch04-ex01-class"
;;; function.

(defclass ch04-ex01-class ())
(defmethod initialize-instance :after ((obj ch04-ex01-class) &rest initargs)
(declare (ignore initargs))
(format t "Creating a ch04-ex01-class~%"))
(let ((obj (make-instance 'ch04-ex01-class)))
(declare (ignore obj))
(format t "finished creating a ch04-ex01-class~%"))
---

Test:

* (let ((obj (make-instance 'ch04-ex01-class)))
(declare (ignore obj))
(format t "finished creating a ch04-ex01-class~%"))
Creating a ch04-ex01-class
finished creating a ch04-ex01-class
NIL

links: digg this    del.icio.us    technorati    reddit