From kragen@dnaco.net Sun Sep 13 14:13:34 1998
Date: Sun, 13 Sep 1998 14:13:33 -0400 (EDT)
From: Kragen <kragen@dnaco.net>
Reply-To: Kragen <kragen@dnaco.net>
To: Jim Weirich <jweirich@one.net>
cc: clug-user@clug.org
Subject: Re: Pure Lisp (Pure OO)
In-Reply-To: <13818.61278.497180.130457@localhost.localdomain>
Message-ID: <Pine.SUN.3.96.980913132650.16247B-100000@picard.dnaco.net>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Keywords:
X-UID: 1875
Status: O
X-Status: 

On Sat, 12 Sep 1998, Jim Weirich wrote:
> >>>>> "Jim" == Jim Weirich <jweirich@one.net> writes:
> 
>     Jim> reason that its not "pure OO" is sloppy thinking.  (I hear no
>     Jim> one advocating programming in "pure Lisp"[1]).
>     Jim> 
>     Jim> [1] Using only car, cdr, cons, atom and null.
> 
> Note: These are the only "functions" allowed.
> 
> >>>>> "Kragen" == Kragen  <kragen@pobox.com> writes:
> 
>     Kragen> You can't program with only car, cdr, cons, atom, and
>     Kragen> null.  All you can do is write expressions that express
>     Kragen> very simple functions of lists.  In particular,
> 
>     Kragen> - you can't find what atoms are bound to;
> 
> The process of evaluting an atom will reveal what it is bound to.

But car, cdr, cons, atom, and null provide no method for doing this.

>     Kragen> - you can't defun;
> 
> Actually, you could bind lambda functions to variables.

Not without the ability to bind and the ability to create a lambda
expression.

> Pure lisp means programming using only the five listed functions.
> Syntactical features such as defun (or define), cond and quote are
> allowed.  All three of these are not normal lisp functions (they don't
> evaluate their arguments), but are considered "special forms".

I think define (or defun, or setq) is more than just a syntactical
feature.  And it's quite possible (although quite awkward) to use a
non-special-form defun to write routines without even quote -- you just
have to have an extra atom bound to each atom you want to include in
your programs.

Are you saying we should allow any "syntactical feature", like the
ORACLE function, which is passed a lambda-expression and which calls it
with an argument that will cause it to return T, if such an argument
exists, and returns T if there was one and NIL if no such argument
exists?  :)

cond, defun, eval, etc., significantly increase the computing power
(not to mention expressive power) of "pure Lisp".  Even
non-special-form versions of them significantly increase the computing
power of "pure Lisp", although they don't quite bring them to the point
of a Turing machine (since you can't conditionally recurse in finite
time without a special-form 'cond').

> In particular, notice that there are no numbers in pure lisp.  You
> have to use list structures to represent numbers.

Yes.  The lispos list got into discussing a "minimal set" of primitives
to implement on a new architecture to get Lisp running on it.  I
pointed out that a theoretical minimal set was much smaller than any
practical minimal set, and that a practical minimal set depended on
what the target architecture was capable of, what things you were
planning on using the Lisp system for, etc.

As evidence, I posted the following definitions.

Date: Wed, 18 Mar 1998 12:40:38 -0500 (EST)

The theoretical point of view is not very useful.  Here's an
example of why:

If you have lambda, cons, car, cdr, some conditional (cond, if, what
have you) and null?, (oh, and some way of defining a function -- I'll use the
Scheme `define', with a single cell for either function or value) you
can implement arithmetic:

; Base-1 arithmetic with the lambda calculus.  Uses only cons, car, cdr,
; if, null? and define.  Uses quote for the restricted purpose of quoting
; the empty list.
; Kragen Sitaker, 1998-03-18

(define nil '())

(define #f (null? (cons nil nil)))
(define #t (null? nil))
(define zero nil)

(define incr (lambda (x) (cons nil x)))
(define decr (lambda (x) (cdr x)))
(define zero? (lambda (x) (null? x))

(define plus 
	(lambda (a b) 
		(if (zero? a) b
			(plus (decr a) (incr b)))))

; doesn't work if b>a; applies cdr to ().  The result of this
; depends on your Lisp/Scheme system.  It's OK in Lisp (returns nil,
; which means the result is zero if b>a; Scheme forbids it.  Most
; Scheme implementations will probably do the same as Lisp.
; SIOD does.
(define minus
	(lambda (a b)
		(if (zero? b) a
			(minus (decr a) (decr b)))))
(define arith-equal?
	(lambda (a b)
		(if (zero? a) (zero? b) 
			(if (zero? b) #f
				(arith-equal? (decr a) (decr b))))))

(define not (lambda (a) (if a #f #t))

(define arith-greater?
	(lambda (a b)
		(if (zero? a) #f
			(if (zero? b) (not (zero? a))
				(arith-greater? (decr a) (decr b))))))

(define arith-less?
	(lambda (a b) (arith-greater? b a))

(define multiply
	(lambda (a b) 
		(if (zero? a) zero
			(plus b (multiply (decr a) b)))))

Kragen

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The sages do not believe that making no mistakes is a blessing. They believe, 
rather, that the great virtue of man lies in his ability to correct his 
mistakes and continually make a new man of himself.  -- Wang Yang-Ming



