declarations




On Mon, 4 May 2009, Robert Dodier wrote:

< On Mon, May 4, 2009 at 12:10 PM, Leo Butler <l.butler at ed.ac.uk> wrote:
< 
< > (%i4) declare(FOO,feature)
< > (%o4) done
< > (%i5)
< > myfn():=block([BAR],declare(BAR,FOO),print(featurep(BAR,FOO)),BAR:"2",
< >            print(featurep(BAR,FOO)),declare(BAR,FOO),
< >            print(featurep(BAR,FOO),featurep(BAR,string)),done)
< > (%i6) myfn()
< > true
< > false
< > false false
< > (%o6) done
< >
< > As you can see, I declare BAR to be a FOO, and maxima knows this. When I
< > assign a value to BAR, maxima forgets my previous declaration and even
< > if I repeat this declaration, maxima ignores it.
< >
< > (Note, too, that featurep is unable to determine that BAR is also a
< > string).
< 
< featurep is an ordinary function, which evaluates its arguments.
< After you assign a value to BAR, featurep sees the value, not
< the symbol BAR. Maybe you want featurep('BAR, FOO) ??
< 
< featurep has accreted various bits over the years, but it is not
< a general type-checking function (not yet anyway).
< Maybe you can explain what you're trying to do and we'll be
< able to figure out a way to achieve it.
 
Robert, thanks for your answer. I can see that I should have been able
to figure it out.

What I am doing is this: 
I am trying to mimic perl's implementation of objects as blessed hashes.
In my case, I define a feature, semi_simple_lie_algebra, and functions
(`methods') that operate on objects that are declared to have this
feature. 

I think that this is essentially how perl uses `bless' to implement its
version of object orientation.

Perhaps you have a suggestion for a better way to do this?

Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.