Translating Smalltalk to C


An Example

In this example I want to show how you can use the CCodeGenerator class to generate C code from a Smalltalk implementation.
Implement a subclass of Object called Person with an instance variable name.

Object subclass: #Person
    instanceVariableNames: 'name '
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Test'

Create a method category called accessing with the following access methods:

name
    "returns the name of the receiver object"

    ^name
name: aName
    "sets the name of the receiver object"
   
    name := aName

You should also create a category called testing with the following method:

test
    "prints the receivers name on the Transcript"

    Transcript show: self name printString