theclapp

Search theclapp.blog-city.com

 

Chapter 2, exercises 7 & 8, and 9 (sort of)

posted Monday, 6-Jan-2003
20:05 -- starting 2.7 Java
20:10 -- done
---
// PrintThreeFromCommandLine.java
// chapter 2, exercise 7

import java.util.*;

class PrintThreeFromCommandLine {
public static void main( String[] args ) {
// no error checking
System.out.println( "Arg 1: " + args[ 0 ] );
System.out.println( "Arg 2: " + args[ 1 ] );
System.out.println( "Arg 3: " + args[ 2 ] );
}
}
---


20:11 -- starting 2.7 Lisp
20:13 -- done
---
;;;; chapter 2, ex 7
(defun print-three-from-command-line (args)
(print (first args))
(print (second args))
(print (third args)))
---

This isn't quite as goofy as it looks. Call it as
 (print-three-from-command-line (cdr extensions:*command-line-strings*))
and it'll print the first three command line arguments.

21:20 -- starting 2.8, Java version
21:23 -- done

---
// AllTheColorsOfTheRainbow.java
// chapter 2, ex 8

class AllTheColorsOfTheRainbow {
int anIntegerRepresentingColors;
void changeTheHueOfTheColor(int newHue) {
anIntegerRepresentingColors = newHue;
}

public static void main( String[] args ) {
AllTheColorsOfTheRainbow atcotr = new AllTheColorsOfTheRainbow();
atcotr.changeTheHueOfTheColor( 10 );
}
}
---


21:23 -- starting 2.8, Lisp version
21:29 -- done
---
;;;; chapter 2, ex 8
(defclass all-the-colors-of-the-rainbow ()
((an-integer-representing-colors :type integer :accessor color)))
(defmethod change-the-hue-of-the-color ((r all-the-colors-of-the-rainbow) (hue integer))
(setf (color r) hue))
(defun 2.8.main ()
(let ((atcotr (make-instance 'all-the-colors-of-the-rainbow)))
(change-the-hue-of-the-color atcotr 10)))
---

21:32 -- 2.9 -- not applicable -- involves running javadoc and viewing the output. Skipping (here, at least).

21:39

I downloaded the code and ran javadoc on the specified file, and viewed the output, as required in the exercise. It looks pretty cool. I wonder if anybody's written anything similar for CL. I guess I'll just have to look around. :)

21:56

Lisp.org lists a few here: http://www.alu.org/table/tools.htm#case

links: digg this    del.icio.us    technorati    reddit