From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!134.222.94.5!npeer.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Primitives for "stings" References: <3bd20c4b.167275@news.online.no> <87sncdssx6.fsf@orion.bln.pmsf.de> <3bd2c087.428654@news.online.no> Mail-Copies-To: never From: Erik Naggum Message-ID: <3212705349358958@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 54 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Mon, 22 Oct 2001 02:09:12 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: nreader3.kpnqwest.net 1003716552 193.71.66.49 (Mon, 22 Oct 2001 04:09:12 MET DST) NNTP-Posting-Date: Mon, 22 Oct 2001 04:09:12 MET DST Xref: archiver1.google.com comp.lang.lisp:18337 * Kent M Pitman | It's one of those newbie "intuitions" that we who understand the issues | are all-too-quick to stomp on before thining "gee, maybe this isn't such | an awful idea". But then again, it ISN'T how you do things in CL, so | newbies do need to straightened out about the realities at some point. (defun qar (string) "Return the first element of string." (char string 0)) (defun qdr (string) "Return the rest of string, or nil if exhausted." (multiple-value-bind (displaced-to index-offset) (array-displacement string) (let ((length (1- (length string)))) (if displaced-to (if (plusp length) (adjust-array string length :displaced-to displaced-to :displaced-index-offset (1+ index-offset)) nil) (make-array length :element-type (array-element-type string) :adjustable t :displaced-to string :displaced-index-offset 1))))) I believe this is how they do "pointers" in C++ STL Strings, too¹, so it should not frighten those who would have abhorred an insane overhead had they looked under the hood. And years from now, somebody will look at this code and not understand why it was a joke in 2001, when Guarana or whatever the next C-(for-caffeine)-related programming language will be called, needs a new way to waste _all_ the computrons the hardware folks have given them. And the _real_ irony here is that using a string as an array with an offset is no slower than stepping a pointer on most new architectures. Even back in the PDP-11 days, they had addressing modes that allowed array indexing at _very_ low cost. Of course, given that every single machine cycle back then cost human sweat and pain, the fathers of C found a way to optimize the language accordingly, and non-quiche-eating, "real" C programmers abhor "the Pascal way" of using strings as arrays to this day, when it actually hurts the prediction logic in modern processors because the hardware people cannot fathom why software people still hand- optimize their low-level C code for a PDP-11 despite not having seen one. /// -- Norway is now run by a priest from the fundamentalist Christian People's Party, the fifth largest party representing one eighth of the electorate. -- The purpose of computing is insight, not numbers. -- Richard Hamming ------- ¹ No, not really.