Skip to content

Conversation

@vsxd
Copy link
Contributor

@vsxd vsxd commented Jul 22, 2018

There is a piece of important code and the accompanying descriptive text is not translated.
This commit fixed it.

There is a piece of important code and the accompanying descriptive text is not translated. This commit fixed is.
@vsxd
Copy link
Contributor Author

vsxd commented Jul 22, 2018

原文中的代码,及其上下文:

Next, we use these type tags to index a dictionary that stores the different ways of adding numbers. The keys of the dictionary are tuples of type tags, and the values are type-specific addition functions. >>> def add(z1, z2): types = (type_tag(z1), type_tag(z2)) return add.implementations[types](z1, z2) This definition of add does not have any functionality itself; it relies entirely on a dictionary called > add.implementations to implement addition. We can populate that dictionary as follows. >>> add.implementations = {} >>> add.implementations[('com', 'com')] = add_complex >>> add.implementations[('com', 'rat')] = add_complex_and_rational >>> add.implementations[('rat', 'com')] = lambda x, y: add_complex_and_rational(y, x) >>> add.implementations[('rat', 'rat')] = add_rational This dictionary-based approach to dispatching is additive, because add.implementations and type_tag.tags can always be extended. Any new numeric type can "install" itself into the existing system by adding new entries to these dictionaries. 
@wizardforcel wizardforcel merged commit d7f1f87 into wizardforcel:master Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants