Computer Science Canada CLOS: Translations from Java and Ruby |
Author: | wtd [ Sun Jan 29, 2006 4:56 pm ] | ||||||||||||||||||||||||||||||
Post subject: | CLOS: Translations from Java and Ruby | ||||||||||||||||||||||||||||||
CLOS: Translations from Java and Ruby Let's look at the most basic classes we can, just to establish a baseline. Java
Ruby
CLOS
This tutorial presumes familiarity with either Java or Ruby as they seem to be popular here, so I won't go into any detail explaining those code samples. I do not, however, expect you to be familiar with CLOS, so that deserves some explanation. The "defclass" macro clearly introduces a class called "foo". The first set of parens would encompass any parent classes, if there were any. The second would contain any slots, which we'll see as the tutorial progresses. Instance variables, contruction and slots Let's store some information. Java
Ruby
CLOS
So, what have we accomplished? We've created "bar" within the Foo class for storing information. We've specified that it should have a default value of 42. Now, here's the thing... with CLOS we didn't have to write any methods to manipulate the data. We just specified that the slot's initial value should be 42. We didn't write the "constructor". We just provided information about the slot. Regardless of what you think about the syntax, there's a deep and profound beauty to this concept. Let's write a method Java
Ruby
CLOS
More to come Keep checking back for updates. ![]() |