unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#15533: optimizing away noticeable effects
@ 2013-10-05 19:27 Ian Price
  2013-10-05 20:28 ` Mark H Weaver
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Price @ 2013-10-05 19:27 UTC (permalink / raw)
  To: 15533


I was peeved today to come across a bug that manifested itself when I
removed a pk from a particular value in my code.

Time to play "spot the difference"

scheme@(guile-user)> ,optimize (define (foo f arg)
  (let* ((l '())
         (m (if (pair? arg)
                (begin
                  (set! l (cdr arg))
                  (car arg))
                arg)))
    (lambda () (apply f m l))))
$14 = (define (foo f arg)
  (let ((m (if (pair? arg)
             (begin (begin (cdr arg) (if #f #f)) (car arg))
             arg)))
    (lambda () (f m))))

scheme@(guile-user)> ,optimize (define (foo2 f arg)
  (let* ((l '())
         (m (if (pair? arg)
                (begin
                  (set! l (cdr arg))
                  (car arg))
                arg)))
    (lambda () (apply f m (pk l)))))
$15 = (define (foo2 f arg)
  (let* ((l '())
         (m (if (pair? arg)
              (begin (set! l (cdr arg)) (car arg))
              arg)))
    (lambda () (apply f m (pk l)))))

and if you actually define those procedures and run them

scheme@(guile-user)> ((foo list '(a b c)))
$16 = (a)
scheme@(guile-user)> ((foo2 list '(a b c)))

;;; ((b c))
$17 = (a b c)

I'm currently on the lua branch, which means branches from master at
6871327742d3e1a0966aa8fed04c911311c12c2a (Aug 31). I'll try on a more
recent master or stable when I have time.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"






^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-01-07  4:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-05 19:27 bug#15533: optimizing away noticeable effects Ian Price
2013-10-05 20:28 ` Mark H Weaver
2013-10-05 20:45   ` Mark H Weaver
2013-10-06  6:39     ` Mark H Weaver
2013-10-06  7:36       ` Mark H Weaver
2013-10-07 16:55         ` Ian Price
2013-10-08 17:13           ` Ian Price
2013-10-23 10:16             ` Ian Price
2014-01-07  4:38               ` Ian Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).