Google Groups Home
Help | Sign in
Message from discussion merits of Lisp vs Python
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Rob Warnock  
View profile
 More options Dec 18 2006, 6:08 am
Newsgroups: comp.lang.lisp, comp.lang.python
From: r...@rpw3.org (Rob Warnock)
Date: Mon, 18 Dec 2006 05:08:20 -0600
Local: Mon, Dec 18 2006 6:08 am
Subject: Re: merits of Lisp vs Python
<xsco...@gmail.com> wrote:

+---------------
| Paul Rubin wrote:

| > [...]  There are programs you can write in C but not in Lisp,
| > like device drivers that poke specific machine addresses.
|
| I should assume you meant Common Lisp, but there isn't really any
| reason you couldn't
|      (poke destination (peek source))
| in some version of Lisp that was meant for writing device drivers
| (perhaps under a Lisp machine or something).
+---------------

I do this kind of thing *every day* in CMUCL!! It's my primary
user-mode hardware debugging tool. Here's a typical utility function:

    ;;; Used for things like polling for a "done" flag.
    ;;; BUG: Assumes contents of ADDR will change within fixnum polls.
    (defun spin-until-change (addr)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (loop with v0 of-type (unsigned-byte 32) = (r32 addr)
            with counts fixnum = 0
            while (= v0 (r32 addr))
         do (setf counts (the fixnum (1+ counts)))
         finally (return counts)))

+---------------
| SIOD actually has (%%% memref address) for peek.
+---------------

CMUCL has SYSTEM:SAP-REF-{8,16,32} and SETFs of same. The R32
above is just my convenience wrapper around SYSTEM:SAP-REF-32:

    (declaim (inline r32))

    (defun r32 (addr)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (system:sap-ref-32 (system:int-sap addr) 0))

    (defun w32 (addr &rest values)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (loop for i fixnum from 0 by 4
            and v of-type (unsigned-byte 32) in values
        do (setf (system:sap-ref-32 (system:int-sap addr) i) v))
      (values))

Most other Common Lisp implementations surely have something similar.

-Rob

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google