🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #429

Order-insensitve argument dispatching

#429
From: Colin Campbell
Date: Thu, 14 Feb 1991 22:58
27 lines
1350 bytes
I want to write methods with order-insensitive arguments.  Example:
geometric intersection of points, lines, planes, etc.   I want to be
able to call

	(geometric-intersection object-1 object-2)

where the args may be of type LINE and PLANE or PLANE and LINE, for instance.

What I do now is this:

(defgeneric geometric-intersection ((object-1 t) (object-2) &optional recursive-p)
   (if recursive-p
       (error "Can't intersect ~a and ~a" object-2 object-1)
       (geometric-intersection object-2 object-1 t)))

i.e.  if I find a method, I use it, otherwise I reverse the order of
the arguments and try again.

Does anybody have a better way to do this?

-- 
Colin Campbell
Evans & Sutherland
Salt Lake City, UT 84108
(801) 582-5847

ccampbel@dsd.es.com
Technical Details
Message-ID: <1991Feb14.225833.4914@dsd.es.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!uunet!orca!bullwinkle!ccampbel

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!uunet!orca!bullwinkle!ccampbel
From: ccampbel@bambam.dsd.es.com (Colin Campbell)
Newsgroups: comp.lang.clos
Subject: Order-insensitve argument dispatching
Message-ID: <1991Feb14.225833.4914@dsd.es.com>
Date: 14 Feb 91 22:58:33 GMT
Sender: usenet@dsd.es.com
Reply-To: ccampbel@bambam.dsd.es.com (Colin Campbell)
Organization: Evans & Sutherland Computer Corp., Salt Lake City, UT
Lines: 27
Nntp-Posting-Host: 130.187.91.214