;; test why when usual-integrations is in effect, rebinding list->vector seems
;; to cause a procedure lookup in BINARY-SEARCH in extras.scm
;; compile: csc -t usual.scm
;; by zb

;; result: LET is a win for external procedures not covered by usual-integrations.
;; LET is a lose for usual-integrations, as it disables certain optimizations.
;; The latter is the case with binary-search and is probably a holdover
;; from pre-usual-integrations days.

;(declare (not usual-integrations list->vector))

;; findings: both calls to list->vector are looked up with C_retrieve_proc
;; the effective call is C_cons(C_retrieve_proc(x)(C_list(3,1,2,3))
;;                              C_retrieve_proc(x)(C_list(3,4,5,6)))
;; the global binding is only looked up once via C_intern and
;; stored in the closure.  adding -O2 has no effect.
;;
;; with (not usual-integrations list->vector), a C_retrieve() is done only once
;; when foo is mutated with the closure, and thereafter a single C_retrieve_proc
;; for every call of list->vector.
(define foo
  (let ((list->vector list->vector))
    (lambda ()
      (cons (list->vector '(1 2 3))
            (list->vector '(4 5 6))))))

;; findings: with usual-integrations, the list->vector is done at compile time,
;; so the call is [pseudocode] C_cons(C_vector(3,1,2,3), C_vector(3,4,5,6))
;;
;; with (not usual-integrations list->vector), a C_retrieve() and a C_retrieve_proc
;; are done on every call.
(define bar
  (lambda ()
    (cons (list->vector '(1 2 3))
          (list->vector '(4 5 6)))))