MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Classes fail in baffling manner

  • To: mathgroup at
  • Subject: [mg20358] Re: [mg20355] Classes fail in baffling manner
  • From: "Andrzej Kozlowski" <andrzej at>
  • Date: Sun, 17 Oct 1999 03:01:46 -0400
  • Sender: owner-wri-mathgroup at

There is something wrong either with the package you are using or with the
way you have loaded it. Here is what happens when I try it (I am using the
package Classes.m which comes with Roman Maeder's book Mathematica
Programmer II). This is version 1.2 of the package, revised in 1996.

<< MathProg`Classes`

"Class[class, superclass, variables, methods] defines a new class as a \
subclass of superclass. Class[object] gives the class of an object."

Class[ Stimulus, Object,
       {mXStart, mYStart},
        {new,      (new[super]; mXStart = #1; mYStart = #2) &},
        {balance,  mXStart &},
        {deposit,  Function[mXStart += #1]},
        {withdraw, Function[mXStart -= #1]},
        {mYStarter,    mYStart &}

a1 = new[Stimulus, 100, "Roman E. Maeder"]


As you can see everything work as it should. It is very difficult to
speculate about what might be going wrong in your case without more
information. What you should do is start a fresh session, load in the
Classes package, try again defining your Stimulus class and if it does not
work again evaluate Contexts[] and $Packages. It might perhaps then be
possible to understand what is going on.

Andrzej Kozlowski
Toyama International University

>From: Joe Strout <joe at>
To: mathgroup at
>To: mathgroup at
>Subject: [mg20358] [mg20355] Classes fail in baffling manner
>Date: Sat, Oct 16, 1999, 13:47

> I am completely stumped.  This is the most bizzare result I've gotten
> trying to learn a new language in a long time -- it's almost making me
> start to like Lisp!
> I'm trying to define a class.  It kept working once, then failing the
> next time in odd ways, so I started with the Accounts.nb, and very
> gradually began to simply rename things in order to make it look more
> like my example.  I got this far:
> Classes`Class[ Stimulus, Object,
>        {mXStart, mYStart},
>        {
>         {new,      (new[super]; mXStart = #1; mYStart = #2)&},
>         {balance,  mXStart&},
>         {deposit,  Function[mXStart += #1]},
>         {withdraw, Function[mXStart -= #1]},
>         {mYStarter,    mYStart&}
>        }
> ]
> Where I've renamed "bal" to "mXStart" (that worked), and then replaced
> "Account" with "Stimulus" -- which doesn't work.  It accepts the
> definition, but as soon as I try to create an object, I get:
> a1 = new[Stimulus, 100, "Roman E. Maeder"]
>    Take::"take": "Cannot take positions -6 through -1 in Hold[
>       mXStart$67, mYStart$67."
> I haven't been able to guess what this might mean.  But it clearly
> didn't work, because when I try to call a method, I get results like:
> (input) balance[a1]
> (output) mXStart$64
> If I replace "Stimulus" with "Account" again, it all works again.  I've
> tried doing Remove["Stimulus"] and Remove["Classes`Stimulus"] to ensure
> that this isn't messing things up, but this same weird behavior occurs
> every time.
> Somebody please give me a clue!  I am about ready to chuck Mathematica
> out the window.
> Clueless,
> -- Joe
> --
> ,------------------------------------------------------------------.
> |    Joseph J. Strout           Biocomputing -- The Salk Institute |
> |    joe at                 |
> `------------------------------------------------------------------'
> Check out the Mac Web Directory!

  • Prev by Date: Re: Composing a stiffness matrix
  • Next by Date: Re: OOP in Mathematica -- please help a newbie
  • Previous by thread: Classes fail in baffling manner
  • Next by thread: Mathematica 3.0 - 4.0 discrepancies.