Why does Dynamic Typing really matter?!?

Scott David Daniels Scott.Daniels at Acm.Org
Thu Feb 6 15:43:23 EST 2003


Jason Smith wrote:
 > ... I want need is an solution to a problem that would not be
 > possible to replicate in a statically typed language...
 >
 > Can anyone pt me in the right direction or provide a small example?
 >
 > Thanks
 > Jason.

While I wouldn't claim this is truly useful,
I would think self-apply would be tough in a statically
typed language (from what I recall of type theory).

def self_apply(x):
     return x(x)

Show me a static typing for that (or for the args it takes).
------

On an only slightly more useful note:

def identity(whatever):
     return whatever

class cell(object):
     __slots__ = ['car', 'cdr']

     def __init__(self, a, b):
         self.car = a
         self.cdr = b

     def __repr__(self):
         return 'cell(%s, %s)' % (self.car, self.cdr)

     def free(self):
         global _freelist

         self.cdr = _freelist
         self.car = identity
         _freelist = self

def _allocate(whatever):
     return cell(_allocate, whatever)

_freelist = _allocate(None)

def cell_alloc(a, b):
     global _freelist
     result = _freelist
     _freelist = _freelist.car(_freelist.cdr)
     result.car = a
     result.cdr = b
     return result


Deriving a static typing for _freelist might drive you nuts.

-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list