math.id
@gmail.com writes:
> how do I delimit an object (a compound list of things)?
> car and cdr can break into any object system that's built by list of
> lists.
> How do I delimit or raise some sort of boundary between "atomic"
> object?
> I thought of returning an function reference for the boundary, but
> what if I need objects that has function references within?
> Any system that I can think of requiring "sacrafies" of one type or
> another.
> How do I break out this lock-jem.
People have used procedures for a kind of object-oriented programming:
you set up a private environment and create a procedure that provides
the only way to access that environment. I suppose the newer edition
of SICP still has the bank account example which does this.
A simple example is a counter object:
(define (make-counter)
(let ((x 0))
(lambda (message)
(case message
((read) x)
((step) (set! x (+ x 1)))
(else (error "?" message)))))) ;; but error is not R5RS!
(define c (make-counter))
(c 'step)
(c 'step)
(c 'read) => 2
There's no way to do anything else to x. It's private to c.
This is related to the origins of Scheme. Steele and Sussman were
trying to make sense of a system where "actors" passed messages to
each other, and they realized they could model it with just procedures
and procedure calls.
Implementations may have actual object systems, of course.
To the other question about types, the answer is something that didn't
quite make R5RS, or maybe it was R4RS: a mechanism for creating new
record types that are disjoint from the existing types. Check your
implementation for make-record-type or similar. Some may call them
structures.