Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!cmcl2!philabs!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP Newsgroups: net.lang Subject: Re: Proc types Message-ID: <445@dg_rtp.UUCP> Date: Wed, 16-Jul-86 13:40:51 EDT Article-I.D.: dg_rtp.445 Posted: Wed Jul 16 13:40:51 1986 Date-Received: Fri, 18-Jul-86 00:59:46 EDT References: <800016@ccvaxa> <19401@rochester.ARPA> Lines: 54 >> aglew@ccvaxa.UUCP >> So, what I'm looking for in this situation is something like >> VAR p: POINTER TO int(int) FROM { func1, func2, func3 ... } >> or >> TYPE p = POINTER TO int(int) SATISFYING constraint; >> where you might declare that you have satisfied the constraint at the >> procedure body: >> PROCEDURE func1(int a) RETURNS int SATISFIES constraint; The two aren't really equivalent, in that in the first case the enumeration must be known at type construction time, while in the second case it need not. The idea of a contract is sometimes used to satisfy the second notion: Declaring the contract and a procedure that obeys it is like so: PROCEDURE p_type( READ ONLY a1: INTEGER, READ WRITE a2: INTEGER ); PROPERTIES CONTRACT; END PROCEDURE p_type; PROCEDURE p OBEYS CONTRACT; NOTHING; END PROCEDURE p; and you can use it like so: VARIABLE p_ptr: POINTER TO p_type; p_ptr := POINTER(p); p( 1, 2 ); p_ptr@( 1, 2 ); > sher@rochester.UUCP (David Sher) > Thus you could have the pascal like > enumeration from int of { 1 , 5 , 7 , 12 } > or interestingly > enumeration from char * of { "GOOD" , "BAD" , "INDIFFERENT" } > or > enumeration from real of { 1.34273 , 123408.24398 , 23408 } > or > enumeration from int * ( int * x ) of { qsort , slowsort , merge } > Does any language have such a feature. Common Lisp. This is the first of the options Andy talked about above. In common lisp, an enumerated type simply specifies values that objects of the type may take. It can even be heterogenous, somewhat like unions, but more convenient, so that you can declare a single type that can have the value of integers from 5 to 7, procedures p or q, or the complex number sqrt(-1). Assuming you would want such a bizarre type, of course. -- A language that doesn't affect the way you think about programming, is not worth knowing. --- Alan J. Perlis -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw