(define-record egg-info
    name author desc)

  (define (show-egg-info egg)
    (define (symbol-value sym)
      (##sys#slot sym 0))
    (define (getter field-name)
      (symbol-value
       (string->symbol
        (format #f "egg-info-~a"
                field-name))))
    (let ((fields '(name author desc)))
      (for-each
       (lambda (f)
         (format #t "~a: ~a~%"
                 f
                 ((getter f) egg)))
       fields)))

  (show-egg-info (make-egg-info
                  "F-operator"
                  "Kon Lovett"
                  "Shift/Reset Control Operators"))

What you're looking for is record inspection (aka introspection). That has been standardized in R6RS, but Chicken doesn't have it AFAIK.

The right points of comparison in Common Lisp are:

* slot-value
* slot-boundp
* slot-exists-p

Symbol-value is not a good point of comparison, as it has to do with packages, not records. Neither Scheme not CL programmers tend to solve problems by poking around the symbol table. It's a last resort.

Your best bet in Scheme as it stands, is to use a hash table or association list instead of a record type. Or wrap a hash table in a record.

I think it is a very common idiom in languages from Lisp family. So it is important to know
how to check symbol is bound and get its value.

It's not idiomatic at all. It's useful mainly for tools that support interactive development, e.g. via REPL or Emacs.

Reply via email to