mit-scheme-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MIT-Scheme-users] queries related to list operations


From: Taylor Campbell
Subject: Re: [MIT-Scheme-users] queries related to list operations
Date: Fri, 3 Mar 2006 21:18:25 +0000
User-agent: IMAIL/1.21; Edwin/3.116; MIT-Scheme/7.7.90.+

   Date: Fri, 24 Feb 2006 14:05:23 +0530
   From: "Amey Karkare" <address@hidden>

   (1) When I say, at interpreter prompt:

      (define lst (cons 1 (cons 2 '()))

    I can see the Prim_cons function getting called, and memory being
    allocated for list '(1 2). But I cannot find out what happens when I say -

      (define lst '(1 2))

    How and where is the memory for list '(1 2) is allocated?

The list is allocated when the input expression is read in the first
place, long before it is evaluated.  The reader is what calls CONS.

   (2) When I call

       (car '(1 2 3 4))

       I see a call to Prim_car. However, I am unable to understand why
       the call to  function "list?->length" in "runtime/list.scm" which
       invokes car/cdr does NOT result in  Prim_car / Prim_cdr being
       called? Also, if I load "runtime/list.scm" in scheme interpreter
       and then call "length" - now the calls to Prim_car/Prim_cdr are
       there.

The list operations are usually compiled, and compiled code does not
go through microcode primitives for many operations such as CAR & CDR
-- instead it just accesses memory directly.  This is *much* faster
than jumping to some foreign C routine, which involves a lot of
machinery just to go from compiled code to the interpreter, even
ignoring the branch to a different part of code altogether.  Of
course, when you load list.scm interpreted, such calls will go through
the microcode primitives.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]