I'm writing a simple network simulator where the network-link and the
network-interface classes need to reference each other.
;;; file: network-interface.lisp ;;;;;;;;;;;;;;;;;;;;
(defclass network-interface (buffer)
((link
:type network-link)))
;;; end of file: network-interface.lisp ;;;;;;;;;;;;;
;;; file: network-link.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass network-link (buffer)
((endpoint-A
:type network-interface)
(endpoint-B
:type network-interface)))
;;; end of file: network-link.lisp ;;;;;;;;;;;;;;;;;;
How to solve the circular dependency?
I'm not sure about these possible solutions:
1) a simple "forward declaration", but not sure if redefining classes is safe
(newbie alert!)
;;; file: network-interface.lisp ;;;;;;;;;;;;;;;;;;;;
(defclass network-link (buffer)
nil)
(defclass network-interface (buffer)
((link
:type network-link)))
;;; end of file: network-interface.lisp ;;;;;;;;;;;;;
2) removing the reference from the classes, using a "connector" object that
keeps track of the connected objects (e.g. a simple adjacency list
graph representation).
3) suggestions welcome
I'd prefer the first solution because it's simple and allows type check, but I don't
know if it's safe.
Regards,
Giacomo Ritucci
Giacomo Ritucci wrote:
> I'm writing a simple network simulator where the network-link and the
> network-interface classes need to reference each other.
>
>
> ;;; file: network-interface.lisp ;;;;;;;;;;;;;;;;;;;;
>
> (defclass network-interface (buffer)
> ((link
> :type network-link)))
>
> ;;; end of file: network-interface.lisp ;;;;;;;;;;;;;
>
>
> ;;; file: network-link.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;
>
> (defclass network-link (buffer)
> ((endpoint-A
> :type network-interface)
> (endpoint-B
> :type network-interface)))
>
> ;;; end of file: network-link.lisp ;;;;;;;;;;;;;;;;;;
>
>
> How to solve the circular dependency?
>
> I'm not sure about these possible solutions:
>
> 1) a simple "forward declaration", but not sure if redefining classes is safe
> (newbie alert!)
>
> ;;; file: network-interface.lisp ;;;;;;;;;;;;;;;;;;;;
>
> (defclass network-link (buffer)
> nil)
>
> (defclass network-interface (buffer)
> ((link
> :type network-link)))
>
> ;;; end of file: network-interface.lisp ;;;;;;;;;;;;;
>
> 2) removing the reference from the classes, using a "connector" object that
> keeps track of the connected objects (e.g. a simple adjacency list
> graph representation).
>
> 3) suggestions welcome
>
>
> I'd prefer the first solution because it's simple and allows type check, but I don't
> know if it's safe.
Redefining classes is safe, but I would rather recommend to omit the
type declarations. They don't buy you a lot anyway.
BTW, your type declarations are probably wrong. Most of the time you
want something like (or null network-link).
Pascal
--
ELS'09: http://www.european-lisp-symposium.org/
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
Pascal Costanza <ยทยท@p-cos.net> wrote:
> Redefining classes is safe, but I would rather recommend to omit the
> type declarations. They don't buy you a lot anyway.
>
> BTW, your type declarations are probably wrong. Most of the time you
> want something like (or null network-link).
Thanks.
Giacomo