Re: class definition dependencies

From: Brian Denheyer <briand_at_deldotd.com>
Date: Tue, 23 Feb 1999 21:48:10 -0800 (PST)

>>>>> "Ian" == Ian Wild <ian.wild_at_eurocontrol.be> writes:

    Ian> Try this:

    Ian> ;;; File A
    Ian> (provide "A")
    Ian> (require "B")

    Ian> (define...


    Ian> ;;; File B
    Ian> (provide "B")
    Ian> (require "A")

    Ian> (define ...


Nice try. See below for an example which doesn't work. If you look at
what you've done its bound to fail. Let's start by including B. The
definition of the method in file B requires the class definition in A.
A is loaded, but A is going to need B which hasn't been loaded
yet. Poof.

Unfortunately, I think that I was right the first time and that
"mix-ins" on the methods like that are going to require the methods
all go into one file or the other, or better yet into some 3rd file.
If you have a method which works on different classes like that,
sometimes its not so obvious which file(s) it should go in.

Thanks

Brian

Welcome to the STk interpreter version 3.99.4 [Linux-2.X-ix86]
Copyright (C) 1993-1999 Erick Gallesio - I3S - CNRS / ESSI <eg_at_unice.fr>
*** Error at line 10 of file ./class-a.scm:
    find-class: class <class-b> not found
Current eval stack:
__________________
  0 (error "find-class: class ~S not found" name)
  1 (cons (apply fn (map car l)) (apply map* fn (map cdr l)))
  2 (cons (apply fn (map car l)) (apply map* fn (map cdr l)))
  3 (make (if (null? kind-of-method) <method> (car kind-of-method)) :specializers (map* (lambda (x) (if (symbol? x) (%find-class x env) x)) specializers) :procedure (make-closure (quasiquote (lambda (next-method (unquote-splicing formals)) (unquote-splicing body))) env))
  4 (let ((method (make (if (null? kind-of-method) <method> (car kind-of-method)) :specializers (map* (lambda (x) (if (symbol? x) (%find-class x env) x)) specializers) :procedure (make-closure (quasiquote (lambda (next-method (unquote-splicing formals)) (unquote-splicing body))) env)))) (if name (add-method (lookup-symbol name env) method)) method)
  5 (begin (ensure-method (quote foo) (quote (a b)) (quote (<class-a> <class-b>)) (quote ((describe a) (describe b))) (the-environment)) (make-undefined))
...
STk>

main.scm
--------
(require "class-b")
(require "class-a")

(define a (make <class-a>))
(define b (make <class-b>))

(foo a b)
(foo b a)

class-a.scm
----------
(provide "class-a")
(require "class-b")

(define-class <class-a> ()
  ((slot1 :accessor slot1)))

(define-method foo
  ((a <class-a>) (b <class-b>))
  (describe a)
  (describe b))

class-b.scm
-----------
(provide "class-b")
(require "class-a")

(define-class <class-b> ()
  ((slot1 :accessor slot1)))

(define-method foo
  ((b <class-b>) (a <class-a>))
  (describe a)
  (describe b))
Received on Wed Feb 24 1999 - 06:49:38 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST