[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] procedure identity


As I'm sure you're aware, there is a strong correspondence between procedures and records. Closures can be implemented as records holding state variables and code, and records can be implemented as special procedures. It would make sense to me that the rules for procedures and records would be the same. So it would be convenient if the result of

(eq? (lambda (x) x) (lambda (x) x))

were the same as

(define-record-type my-record make-my-record my-record?)

(eq? (make-my-record) (make-my-record))

It makes the most sense to me if both of these expressions return #f.

A similar question would arise if an implementation provided immutable records - can immutable records with the same fields be "eq?"?. Perhaps if there were a notion of an "immutable procedure", the answer could be that mutable records and procedures have identity, and immutable ones do not.

Noah Lavine

On Tue, Jun 4, 2013 at 7:20 PM, Per Bothner <per@x> wrote:
I like the concept of procedure location tags and procedure identity.
It enable a simple and sane semantics, and it enables useful
features such as associating properties with procedures.

The problem is I would like to allow the following to return true
(as it does in Kawa):

(define (maybe-negate negp)
   (if negp (lambda (x) (- x))
       (lambda (x) x)))
(eq? (maybe-negate #t) (maybe-negate #t))
;; Likewise for eqv?

I.e. the compiler can realize the two lambda
expressions don't depend on closed state, and
so it can move them to top-level and pre-allocate them.

Conceptually we have two kinds of procedures:
(1) Immutable "methods" without object identity.
(While the method is immutable, it may capture
mutable state, of course.)
(2) Mutable procedure objects, with object identity,
and a possibly-mutable set of named properties.

Perhaps the "large" language can support procedure
properties.  In that case procedure eqv? can be
defined in terms of the underlying method *and*
the properties.
        --Per Bothner
per@x   http://per.bothner.com/

Scheme-reports mailing list

Scheme-reports mailing list