[gambit-list] How to distinguish procedures from procedures?

Jörg F. Wittenberger Joerg.Wittenberger at softeyes.net
Fri Mar 27 07:06:29 EDT 2020


A few questions regarding procedures:

There are several classes of objects passing the `procedure?` predicate.

- Is there a full list?

- How expensive are those at startup initialization and call time?
  (A rough ordering would do.  Just to avoid expensive ones when there's
  the option.)

- I tend to use the following receipe to control the global exports
  with gambit (currently nailed in practice to 0.9.2 for use with
  lambdanative).  Does imply any runtime overhead vs. no use of `let`
  and resorting to gambits namespace facility?

      (define my-exported-proc #f)

      (let (...)
        (define (my-private-proc ...) ...)
        (define (my-to-be-exported ...) ...)
        (set! my-exported-proc my-to-be-exported))

- The real question of mine: How could I create additional runtime
  predicates for procedures with minimal overhead?  Any way to attach
  tags to procedures?  (Let's rule out the trivial solution to collect
  procedures which should pass the predicate in a data structure and
  look it up.)

  I need something where this fiction make sense (upper case be "dunno

;; ATTACH-TAG! is compiletime, maybe even only compiletime.
(define-macro (bless! proc tag) `(ATTACH-TAG! ,proc ',tag))

(define (make-blessed tag)
 (lambda (obj)
   (and (procedure? obj) (eq? (GET-TAG obj) tag))))

(define ispure? (make-blessed 'pure))

(bless! + 'pure)

;;; at runtime:

(ispure? +)  ; => #t
(ispure? -)  ; => #f  ;; yeah, we forgot to bless is  :-/

Thanks so much


More information about the Gambit-list mailing list