Subject: Re: Does learning Lisp changes the way of your coding in other languages?
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 18 Apr 2007 22:14:47 -0500
Newsgroups: comp.lang.lisp
Message-ID: <DvydnUNv5oc6Q7vbnZ2dnUVZ_oSnnZ2d@speakeasy.net>
Brian Adkins  <lojicdotcomNOSPAM@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > Which, after learning a little more CL, should have
| > resulted in just using CL's builtin LOGCOUNT instead...  ;-}  ;-}
| 
| Cool. Although, doesn't that only work for half the values
| (i.e. ones with MSB off) ?
+---------------

What is this "MSB" thing of which you speak?!?  ;-}  ;-}
Unlimited-precision integers don't *have* an
"MSB" per se. If you really, really need a
finite-width integer, then force it to be such:

    (logcount (logand x #.(1- (ash 1 +word-width+))))

E.g.:

    > (defparameter +word-width+ 32)

    +WORD-WIDTH+
    > (let ((x -375))
	(list (logcount x)  ; For negative values, counts zeros instead.
	      (logcount (logand x #.(1- (ash 1 +word-width+))))))

    (6 26)
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607