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

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

[MIT-Scheme-devel] Min/Max Error when Trying to Delv


From: lcedlightning
Subject: [MIT-Scheme-devel] Min/Max Error when Trying to Delv
Date: Sat, 5 Dec 2009 11:59:32 -0800 (PST)

Hi all,

I wrote the following function:

(define pairmin
        (lambda(x)
                (delv! (max (car x) (list-ref x 1)) x)))

and it works just right. It examines the first two elements of a list and
destroys the larger one. A function call with a variable (define x(list 1 2
3 4 5)) as the argument to this function would return (1 3 4 5).

I am having a really strange result when trying to execute the following
code:

(define pairmax
        (lambda(x)
                (delv! (min (car x) (list-ref x 1)) x)))

This is exactly the same as pairmin but instead deletes the smaller of the
two numbers. So this function called with x as the argument should result in
(2 3 4 5). Note that both of these functions use delv! instead of delv, so
the list itself is modified.

Here is an image straight from the interpreter:

http://old.nabble.com/file/p26658709/Picture%2B10.png 

>From here, you can see that x is at stack position 11. When pairmin is
called, the memory at stack position 11 is modified. When pairmax is called,
stack position 12 is modified (a list copy is pushed onto the stack). Why is
this happening when the functions are exactly the same? I think I have
isolated the problem to be simply a difference between min and max, but
maybe I'm wrong. Can somebody help me? I need pairmax to work destructively
like pairmin works.

Thank you so much for your time and your assistance.

-- 
View this message in context: 
http://old.nabble.com/Min-Max-Error-when-Trying-to-Delv-tp26658709p26658709.html
Sent from the Gnu - MIT Scheme - Dev mailing list archive at Nabble.com.





reply via email to

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