Classes fail in baffling manner
- To: mathgroup at smc.vnet.net
- Subject: [mg20355] Classes fail in baffling manner
- From: Joe Strout <joe at strout.net>
- Date: Sat, 16 Oct 1999 00:47:43 -0400
- Organization: The Salk Institute
- Sender: owner-wri-mathgroup at wolfram.com
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 strout.net http://www.strout.net |
`------------------------------------------------------------------'
Check out the Mac Web Directory! http://www.strout.net/macweb.cgi