[Edu-sig] Quadrays again... cross-training in two langauges

Kirby Urner kurner at oreillyschool.com
Mon Aug 10 22:11:00 CEST 2015


On Mon, Aug 10, 2015 at 12:58 PM, Kirby Urner <kurner at oreillyschool.com>
wrote:

>
>
> On Mon, Aug 10, 2015 at 12:02 PM, Mark Engelberg <mark.engelberg at gmail.com
> > wrote:
>
>>
>>
>>> The idea of an interface has migrated to that of a "protocol" which
>>> provides a ready namespace for a "record".
>>>
>>
>> A protocol is more than just an "interface by a different name" or an
>> "interface+namespace".
>>
>
> For those not familiar with Java, it's single inheritance, so we don't
> have the happy solution of injecting new functionality by adding more base
> classes.
>
> In Java, a class is said to "extend" a base class whereas an interface, a
> set of promised methods, is something a class "implements".
>
> Whereas on my extend only one class at a time, said class may implement
> many interfaces.
>
> I see Clojure taps that ability too:
>
> http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/extend
>
>
>
>>
>> To understand the significance of a protocol, you need to first
>> understand the "expression problem".  The expression problem asks you to
>> consider a set of polymorphic functions over multiple datatypes.  Without
>> controlling or being able to recompile the original source code, can you
>> easily extend these functions to a new datatype, and can you easily create
>> a new polymorphic function across those datatypes?
>>
>
> I like to relate these concepts back to basic math and the different
> number types we start with, as concentric subsets:  N < Z < Q < R < C.
>
> Then a protocol or interface is "the operations" such as - / + * < > and
> so on.  What common control panel of operations works across these sets?
>
> Clojure, like Java, is not supportive of operator overloading right?  I
> can't go like:
>
> (defprotocol VectorOps
>   (__add__ [this other])
>   (__sub__ [this other])
>   (len [this])
>   (__neg__ [this])
>   (norm [this]))
>
> ... and then use (+ A B) to add two vectors, or (- A) to negate one.
>
> I think the basics of Polymorphism may be communicated without introducing
> the wrinkle of not having original source code.  Not wanting to change it
> might be easier for a math student to understand.
>
> Not having the original source code sounds like a social problem, an
> institutional issue, vs. a truly theoretical issue, and that's confusing to
> newbies.
>
> The + and - operators make sense in a Group, where - is both negation and
> for adding a negative inverse.
>
> Add * and / to the mix and we've got a field.
>
> Lots of datatypes participate in group and field relationships, including
> numbers module N, which we may imagine as a specific type of number.
>
>
Sorry for typos.

... numbers *modulo* N -- given "module" is a Python word, this could be
confusing.

Here's some source I code I wrote for that type of Number awhile back:

http://www.4dsolutions.net/ocn/python/groups.py

Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20150810/7fe6ac24/attachment.html>


More information about the Edu-sig mailing list