[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: override display() for class
From: |
Steve White |
Subject: |
RE: override display() for class |
Date: |
Fri, 10 Dec 2010 17:50:34 +0100 |
Hi Pascal,
Thanks for your advice!
However this doesn't really address the question.
Perhaps I shouldn't have mentioned display() at all.
The question is, how do I emulate the built-in behavior wherein
typing in an assignment results in the variable name as well as
the value being printed?
For example, if one types
a = 1
Octave prints out the whole expression
a = 1
I want to get this effect when, say assigning a variable to my class.
Something like
a = myclass(1)
currently results in just
<representation of myclass>
I want it to print out something like
a = <representation of myclass>
This seems to me to be an obvious thing to happen....
> Date: Fri, 10 Dec 2010 01:18:38 -0800
> From: address@hidden
> To: address@hidden
> Subject: Re: override display() for class
>
>
> display receives as input the VALUE of an object, it is up to this function
> to suitably produce a text with the fields of the object. To determine the
> NAME of the argument passed to the function, use the "inputname" function?
> So your overloaded function should be
>
> function text = display(myclass)
>
> text = sprintf('%s value is %d', inputname(1), myclass.val)
>
> endfunction
>
> Now, overloading means having the ability to mimic some fundamental
> function, applied to a class you did define. In the name of the "least
> surprise effect", you should try to stay as close as possible to the
> fundamental function behaviour.
>
> Regards
>
> Pascal
> --
> View this message in context:
> http://octave.1599824.n4.nabble.com/override-display-for-class-tp3081116p3081620.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
- override display() for class, Steve White, 2010/12/09
- Re: override display() for class, CdeMills, 2010/12/10
- RE: override display() for class,
Steve White <=
- RE: override display() for class, CdeMills, 2010/12/10
- RE: override display() for class, Steve White, 2010/12/11
- Re: override display() for class, Jaroslav Hajek, 2010/12/12
- RE: override display() for class, Steve White, 2010/12/12
- Re: override display() for class, CdeMills, 2010/12/13
- Re: override display() for class, Ben Abbott, 2010/12/13
- Re: override display() for class, John W. Eaton, 2010/12/13
- Re: override display() for class, bpabbott, 2010/12/13
- Re: override display() for class, John W. Eaton, 2010/12/13
- Re: override display() for class, bpabbott, 2010/12/13