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

[no subject]



    11-Jun-79  1907        HENRY at MIT-AI (Henry Lieberman)       CASEGO    
    Date: 11 JUN 1979 2209-EDT
    From: HENRY at MIT-AI (Henry Lieberman)
    Subject: CASEGO
    To: GLS at SU-AI

    What you really have in the examples you give to show
    the use of CASEGO is a loop. I think it should be coded
    as such, either by the use of DO or auxiliary functions
    rather than your proposed CASEGO.

    (DEFUN CASEGO-EXAMPLE (THE-FROB)
	   (CASEQ THE-FROB
		  ((BAR) ...)
		  ((FOO))
		  (T (... "I'll assume BAR") (CASEGO-EXAMPLE 'BAR))))

    I think your proposal is like coding a loop using GO, which
    is generally acknowledged to be less winning.

This is true, although what you have written is not semantically
equivalent (though functionally equivalent) in that it re-performs
the dispatch needlessly.  This corresponds to the situation with the
famous Boehm-Jacopini "theorem", which shows that any program can
be made "structured" provided that a number of boolean variables
and redundant tests are introduced.  Also, without LABEL or LABELS
or some such I can't write the above in MacLISP "in place".

A better way around the problem using functions would be just to do
	(CASEQ THE-FROB
	       ((BAR) (BAR-CASE))
	       ((FOO) ...)
	       ...
	       (T (... "assume BAR") (BAR-CASE)))
	...
	(DEFUN BAR-CASE ...)
Again, in MacLISP I can't really write this "in place" and take
advantage of local variables.

I just used the name GO by analogy with the behavior in a PROG.
Actually, I might phrase my request entirely without reference to
GO (because some people dislike GO), and say that I want a construct
CASERETRY such that
	(CASEQ FROB
	       ((FOO) FOO1)
	       ((BAR) BAR1 (CASERETRY HUNOZ))
	       ((BAZ QUUX) BAZQUUX1)
	       (T BARF (CASERETRY 'BAR))
expands into
	(LABELS ((FOO-CASE (LAMBDA () FOO1))
		 (BAR-CASE (LAMBDA () BAR1 (DISPATCH HUNOZ)))
		 (BAZQUUX-CASE (LAMBDA () BAZQUUX1))
		 (DEFAULT-CASE (LAMBDA () BARF (BAR-CASE)))
		 (DISPATCH (LAMBDA (X)
				   (SELECTQ X
					    ((FOO) (FOO-CASE))
					    ((BAR) (BAR-CASE))
					    ((BAZ QUUX) (BAZQUUX-CASE))
					    (T (DEFAULT-CASE))))))
		(DISPATCH FROB))
where SELECTQ represents the more primitive simple-dispatch operation.
Now this uses no GOs, and therefore must be generally acknowledged to be
more winning, right?