From: Ken A. <kan...@bb...> - 2004-06-21 21:15:39
|
I thought i'd see what's its like to use Tims new #{}# syntax, by converting dclass/record.scm to use it rather than the capabilites of dclass/dclass.scm. This converts a simple record, struct, defstruct into a Java bean. So for example, after loading record2.scm into JScheme, the 7 LOC (show (macroexpand '(define-record plan.Word (fields (name String) (nSpam 0) (nHam 0) (probability -1.0) (deviance -1.0))))) produces the 51 LOC of Java below. (Not bad for about a 150 line macro). Tim, one problem i had was that the semantics of #{}# was not the same as {}. This forced me to use the procedure asaf (see the code) 7 times when i wouldn't have need it it using {}. I think we should make the semantics of #{}# the same as {}. k Here's the Java expansion: package plan; public class Word implements java.io.Serializable { private String name; private int nSpam = 0; private int nHam = 0; private double probability = -1.0; private double deviance = -1.0; public Word(String name, int nSpam, int nHam, double probability, double deviance) { this.name = name; this.nSpam = nSpam; this.nHam = nHam; this.probability = probability; this.deviance = deviance; } public Word(String name) { this.name = name; } public String getName() { return this.name; } public int getNSpam() { return this.nSpam; } public int getNHam() { return this.nHam; } public double getProbability() { return this.probability; } public double getDeviance() { return this.deviance; } public void setName(String value) { this.name = value; } public void setNSpam(int value) { this.nSpam = value; } public void setNHam(int value) { this.nHam = value; } public void setProbability(double value) { this.probability = value; } public void setDeviance(double value) { this.deviance = value; } public String toString() { return "(plan.Word. " + this.name+ " " + this.nSpam+ " " + this.nHam+ " " + this.probability+ " " + this.deviance + ")"; } } |