[comp.lang.icon] Idol gotcha: mixing procedures and methods

talmage@luvthang.UUCP (David W. Talmage) (06/01/91)

Boy, do I feel dumb!  Here's a "gotcha" for those of us who work with
Idol, Clint Jeffery's neato object-oriented language derived from Icon.

In Idol, you can have both procedures and methods in a class
definition.  Procedures become part of the global name space while
methods stay local to the objects of their class.  Because procedures
are in the global space, they have no concept of the variable "self",
which all methods may use to access the instance variables of their
class.  Procedures which try to dereference self invoke a run-time
error: "record expected".

This sample should illustrate the problem:

class DoNuthin(theFrobotz, theZimZam)
method asString()
  return "theFrobotz= " || self.theFrobotz || " theZimZam= " || self.theZimZam 
end

procedure printThem()
  write( self.theFrobotz )
  write( self.theZimZam )
end

initially
  printThem()
end

procedure main()
local aDoNuthin

  aDoNuthin := DoNuthin( "David", "Talmage" )
  write( aDoNuthin$asString() )

end

I don't want to tell you how long it took me to figure that one out.

-----------------------------------------------------------------------------
David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
"I need fifty dollars to make you hollar.  I get paid to run this luvthang."

cjeffery@CS.ARIZONA.EDU ("Clinton Jeffery") (06/04/91)

<<This is a reply to David Talmage's note on mixing procedures and methods
  in Idol.  Regular Icon readers will not miss anything if they skip it.>>

Procedures inside class declarations are regular Icon procedures and do not
have any implicit "self" object on which to operate.  Idol used to flag this
with an error to prevent the kind of confusion Mr. Talmage experienced.  But
it is quite useful to allow normal Icon code (such as helping procedures)
to be included within a class declaration.  Idol does not take the view
that every piece of code should be a method, any more than it views
every piece of data as an object.  Saying "procedure" when you mean
"method" will indeed cause the kind of problems Mr. Talmage described.