Prev: API questions
Next: land of lisp
From: Tamas K Papp on 18 May 2010 06:04 Is there a standard way to test if two types are equal? For example, in ECL, > (upgraded-array-element-type '(signed-byte 64)) SI:INTEGER64 but it turns out that the two are just synonyms. Currently, I am testing for that using (defun type= (type1 type2) "Test if two types are equal (ie subtypes of each other)." (and (subtypep type1 type2) (subtypep type2 type1))) > (type= 'SI:INTEGER64 '(signed-byte 64)) T T but I am wondering if there is something in the HS I missed. Thanks, Tamas
From: Frode V. Fjeld on 18 May 2010 06:08 Tamas K Papp <tkpapp(a)gmail.com> writes: > (defun type= (type1 type2) > "Test if two types are equal (ie subtypes of each other)." > (and (subtypep type1 type2) > (subtypep type2 type1))) > but I am wondering if there is something in the HS I missed. No, I believe your TYPE= is the standard trick for this. -- Frode V. Fjeld
From: Thomas F. Burdick on 19 May 2010 04:02 On May 18, 12:04 pm, Tamas K Papp <tkp...(a)gmail.com> wrote: > Is there a standard way to test if two types are equal? > > For example, in ECL, > > > (upgraded-array-element-type '(signed-byte 64)) > > SI:INTEGER64 > > but it turns out that the two are just synonyms. Currently, I am > testing for that using > > (defun type= (type1 type2) > "Test if two types are equal (ie subtypes of each other)." > (and (subtypep type1 type2) > (subtypep type2 type1))) (defun type= (type1 type2) (multiple-value-bind (sub1? oops1) (subtypep type1 type2) (multiple-value-bind (sub2? oops2) (subtypep type2 type1) (cond ((or oops1 oops2) (error "No idea if (TYPE= ~S ~S), it certainly sucks that this is allowed." type1 type2)) ((and sub1? sub2?) t) (t nil)))))
From: Norbert_Paul on 19 May 2010 05:17 Thomas F. Burdick wrote: > (defun type= (type1 type2) > (multiple-value-bind (sub1? oops1) (subtypep type1 type2) > (multiple-value-bind (sub2? oops2) (subtypep type2 type1) > (cond > ((or oops1 oops2) > (error "No idea if (TYPE= ~S ~S), it certainly sucks that > this is allowed." > type1 type2)) > ((and sub1? sub2?) t) > (t nil))))) If that sucks you could mimic it: (defun type= (type1 type2) (multiple-value-bind (sub1? oops1) (subtypep type1 type2) (multiple-value-bind (sub2? oops2) (subtypep type2 type1) (cond ((and sub1? sub2?) (values T T)) ; definitely yes ((and oops1 oops2) (values nil T)) ; definitely no ( T (values nil nil)))))) ; maybe - maybe not AFAIK there are good reasons for the secondary value. Norbert
|
Pages: 1 Prev: API questions Next: land of lisp |