<html><head></head><body><div class="ydp3ebf1d7byahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div></div>
<div dir="ltr" data-setdir="false">Huh. Interesting. That works, thanks very much. I wouldn't have thought of that. Of course now I have to go figure out why this works...</div><div dir="ltr" data-setdir="false"><br></div><div><br></div>
</div><div id="ydp7f434514yahoo_quoted_2059251684" class="ydp7f434514yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Thursday, October 24, 2019, 4:07:11 PM GMT+8, Daniel Kochmański <daniel@turtleware.eu> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div dir="ltr">or, alternatively, just use class-of instead of type-of.<br clear="none"><div class="ydp7f434514yqt1646026050" id="ydp7f434514yqtfd97907"><br clear="none">Daniel Kochmański writes:<br clear="none"><br clear="none">> Hmm, maybe something in this spirit?<br clear="none">><br clear="none">> (let ((type (type-of x)))<br clear="none">> (flet ((maximize-type (new-number)<br clear="none">> (let ((new-type (type-of new-number)))<br clear="none">> (cond ((subtypep new-type type)<br clear="none">> t)<br clear="none">> ((subtypep type new-type)<br clear="none">> (setf type new-type)<br clear="none">> t)))))<br clear="none">> (assert (every #'maximize-type coefficients))))<br clear="none">><br clear="none">> Daniel<br clear="none">><br clear="none">> Steven Nunez writes:<br clear="none">><br clear="none">>> Okay, having a specialised representation for positive integers makes sense as a further specialisation of INTEGER. I wish this was documented somewhere, a 1 minute google search did not turn up anything.<br clear="none">>> I still have the problem of ensuring that the parameters to a function, a sequence and a number, are all of the same type so I can dispatch on specialised (typed declared) versions of loop. At the moment I have:<br clear="none">>> (assert (and (plusp (length coefficients))<br clear="none">>> (every (lambda (elt)<br clear="none">>> (typep elt (type-of x)))<br clear="none">>> coefficients)))<br clear="none">>> which works fine for single-float and double-float, but fails if any of the coefficients are negative because their type-of is FIXNUM whilst the X or other coefficients may be (INTEGER 0 4611686018427387903)<br clear="none">>> Any ideas?<br clear="none">>><br clear="none">>><br clear="none">>><br clear="none">>><br clear="none">>><br clear="none">>> On Thursday, October 24, 2019, 3:24:56 PM GMT+8, Daniel Kochmański <<a shape="rect" href="mailto:daniel@turtleware.eu" rel="nofollow" target="_blank">daniel@turtleware.eu</a>> wrote: <br clear="none">>> <br clear="none">>> <br clear="none">>>> CCL (1.11) has most-positive-fixnum of 1152921504606846975SBCL (1.5.6) has 4611686018427387903<br clear="none">>>><br clear="none">>>> However:<br clear="none">>>> CL-USER> (subtypep 'fixnum 'integer)<br clear="none">>>> T<br clear="none">>>> T<br clear="none">>>> CL-USER><br clear="none">>>><br clear="none">>>> so FIXNUM is a subtype of INTEGER, and it should be the type returned if the implementation is following the CltL2 guidelines if I'm understanding the type system correctly.<br clear="none">>><br clear="none">>> CLtL2 has been superseded by ANSI specification so it is not<br clear="none">>> bounding. Anyway, more specific type here is<br clear="none">>><br clear="none">>> (integer 0 #.most-positive-fixnum)<br clear="none">>><br clear="none">>> Try (subtypep (integer 0 #.most-positive-fixnum) 'fixnum) and it will<br clear="none">>> yield true as well.<br clear="none">>><br clear="none">>> The reason why you have result 'fixnum for negative and '(integer 0<br clear="none">>> #.most-positive-fixnum) for positive integers is probably because CCL<br clear="none">>> (and other implementations in fact) have a specialized representation<br clear="none">>> for unsinged fixnums (similar to i.e 'unsigned int' in C).<br clear="none">>><br clear="none">>> Daniel<br clear="none"><br clear="none"><br clear="none">-- <br clear="none">Daniel Kochmański ;; aka jackdaniel | Przemyśl, Poland<br clear="none">TurtleWare - Daniel Kochmański | www.turtleware.eu<br clear="none"><br clear="none">"Be the change that you wish to see in the world." - Mahatma Gandhi</div></div></div>
</div>
</div></body></html>