Python from Wise Guy's Viewpoint

prunesquallor at comcast.net prunesquallor at comcast.net
Sat Oct 25 13:19:54 EDT 2003


"Marshall Spight" <mspight at dnai.com> writes:

> <prunesquallor at comcast.net> wrote in message news:ptgle760.fsf at comcast.net...
>> Dirk Thierbach <dthierbach at gmx.de> writes:
>>
>> My point is that type systems can reject valid programs.
>
> Agreed. But: does it matter? One thing that would help
> in figuring out if it matters or not would be seeing a
> small, useful program that cannot be proven typesafe.

(defun lookup (item table if-found if-missing)
  (cond ((null table) (funcall if-missing))
        ((eq item (entry-key (first-entry table)))
         (funcall if-found (entry-value (first-entry table))))
        (t (lookup item (remaining-entries table)
                   if-found
                   if-missing))))

(defun lookup-default (item local-table default-table if-found if-not-found)
  (lookup item local-table 
          if-found
          (lambda () 
            (lookup item default-table if-found if-not-found))))

(defun transform-list (list local-table default-table if-ok if-fail)
  (if (null list)
      (funcall if-ok '())
      (lookup-default (car list) local-table default-table
        (lambda (result)
          (transform-list (cdr list) local-table default-table
            (lambda (remainder)
              (funcall if-ok (cons result remainder)))
            if-fail))
        (lambda () (funcall if-fail (car list))))))

I know that simple static type checkers will be lost with this.
I do not know if the smarter ones will.




More information about the Python-list mailing list