On 15/12/16 08:16, Jori Mäntysalo wrote:
On Wed, 14 Dec 2016, Peleg Michaeli wrote:

OK then, I'll simply add aliases in the docstrings (however, note that
there are places in sage with such aliases, such as `am =
adjacency_matrix`).

Yes, there are. And I think they should be mostly deprecated and later
deleted. /Except something like ZZ which is very common and have quite
long "real" name.)

Btw, is there an easy way for a user to add own aliases? So that it
would go to the right place in hierarchy.


I had a short discussion about aliases in Sage Days 79. It might be appropriate for general Python programming to have an alias() function for adding aliases of functions and methods.

The usage should be something like:
  new_alias = alias("new_alias", orig_function)

It should copy the docstring of orig_function and prepend to it "new_alias is an alias of orig_function\n". For better documentation it should also add to orig_function the existence of such aliases. One way to implement it is to add an attribute orig_function._aliases to be the list of aliases. Then, the docstring of orig_function will have an ALIASES section (dynamically created) in its documentation if _aliases exist and is not empty.

It gets trickier to implement for methods in Cython classes and Python classes that only use __slots__, because we need to dynamically add attributes.

For class methods, having such an alias() function helps with inheritance, not just with citations. Suppose we have

class A(object):
    def foo(self):
        print "A.foo"
    also_foo = foo

class B(A):
    def foo(self):
        print "B.foo"

Then we get different behavior of foo() and also_foo() in B:
sage: b = B()
sage: b.foo()
B.foo
sage: b.also_foo() # Surprise!
A.foo

BTW, tab completion is not enough to discover aliases, because not all aliases are prefixes. See for example the short docstring of gaussian_binomial which is an alias for q_binomial.

Regards,
TB

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to