[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another take on hackers and painters
Date: Thu, 22 May 2003 18:27:30 -0500 (CDT)
From: Jacob Matthews <jacobm@cs.uchicago.edu>
To: Michael Vanier <mvanier@cs.caltech.edu>
Cc: paul@prescod.net, "" <ll1-discuss@ai.mit.edu>
Subject: Re: another take on hackers and painters
On Thu, 22 May 2003, Michael Vanier wrote:
> Of course, this isn't autoconversion, but something like this could be used
> for autoconversion.
Indeed. Here's a complete autoconverting + implemented in PLT Scheme:
(define real+ +)
(define (+ . args)
(define (?->num x)
(cond
((string? x) (or (string->number x)
(error '+ "expected a number string, got non-number
string ~s" x)))
((number? x) x)
(else (error '+ "expected number or string, got ~s" x))))
(apply real+ (map ?->num args)))
Or, even better, and simpler:
(define real+ +)
(define (+ . args)
(define (?->num x)
(cond
((string? x) 1)
((number? x) x)
(else 0)))
(apply real+ (map ?->num args)))
And powerful: one can easily count the number of strings
in a list x of strings and other (non-number) items by saying
(apply + x)
--Guy
(with tongue firmly in cheek)