On Sep 15, 6:02 am, Stan Schymanski <schym...@gmail.com> wrote:
> Would it be possible to formalise
> this somehow, so that I could then type the name of the variable
> further down in the document followed by a question mark to see that
> information again?

One way of establishing this feature is by having "custom docstrings"
on objects. I don't think this will ever be a default feature because
normally the docstring lives on the class, not the object and moving
it would make objects heavier. Many sage types don't have writable
attributes for that efficiency reasons:

sage: x=var('x')
sage: x.__doc__="hello world"
AttributeError: 'sage.symbolic.expression.Expression' object attribute
'__doc__' is read-only

I am doubtful how feasible it is to have custom object docstrings
adhere to the sage and python conventions
There is no fundamental obstruction in python against it though:

-------
class doccable(object):
    def __init__(self,s):
        self.__doc__=s
------
sage: a=doccable("I'm object a")
sage: b=doccable("I'm object b")
sage: a?
[...]
Docstring:
    I'm object a
sage: b?
[...]
Docstring:
    I'm object b

I think in nearly all cases the feature is already available via
subclassing:

-----
class symvar(sage.symbolic.expression.Expression):
    pass
-----
sage: xs=symvar(SR,x)
sage: xs.__doc__="My custom docstring"
sage: xs?
[...]
Docstring:
    My custom docstring
[...]

The rest is a matter of tuning the symvar subclass definition so that
you can conveniently set the docstring def with something like

sage: x = symvar('x',doc="I am x")

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to