Bienvenido a DrScheme, versión 372 [3m]. Lenguaje: Muy Grande (incluye MrEd y Avanzado). > (define i-stack% (interface () push! pop! is-empty?)) > (define i-nombrable% (interface () get-nombre set-nombre)) > (define stack% (class* object% (i-stack% i-nombrable%) (init-field (name 'stack)) (field (stack null)) (define/public (push! v) (set! stack (cons v stack))) (define/public (pop!) (let ((v (car stack))) (set! stack (cdr stack)) v)) (define/public (is-empty?) (null? stack)) (define/public (print-name) (display name) (newline)) (super-new))) . class*: interface-required method missing: set-nombre for class: stack% for interface: i-nombrable% > (define stack% (class* object% (i-stack% i-nombrable%) (init-field (name 'stack)) (field (stack null)) (define/public (push! v) (set! stack (cons v stack))) (define/public (pop!) (let ((v (car stack))) (set! stack (cdr stack)) v)) (define/public (is-empty?) (null? stack)) (define/public (print-name) (display name) (newline)) (define/public (get-nombre) name) (define/public (set-nombre nuevo-nombre) (set! name nuevo-nombre)) (super-new))) > (define s1 (new stack%)) > (define s2 (new stack% (name 'pila))) > (send s2 get-nombre) pila > (send s1 get-nombre) stack > (send s1 push! 'hola) > (send s1 push! 12) > (send s1 pop!) 12 > (send s1 pop!) hola > (send s1 pop!) . car: expects argument of type ; given () > (define fancy-stack% (class stack% (inherit-field name) (define/override (push! v) (super push! (cons 'fancy v))) (super-new))) > (define sf (new fancy-stack%)) > (send sf push! 'hola) > (send sf push! 13) > (send sf pop!) (fancy . 13) > (send sf pop!) (fancy . hola) > (send sf pop!) . car: expects argument of type ; given () > (define double-stack% (class stack% (inherit push!) (define/public (double-push! v) (push! v) (push! v)) (super-new (name 'double-stack)))) > (define ds (new double-stack%)) > (send ds double-push! 'hola) > (send ds get-nombre) double-stack > (send ds pop!) hola > (send ds pop!) hola > (send ds pop!) . car: expects argument of type ; given () > (define safe-stack% (class stack% (inherit is-empty?) (define/override (pop!) (if (is-empty?) #f (super pop!))) (super-new))) > (define s4 (new safe-stack%)) > (send s4 push! 'hola) > (send s4 pop!) hola > (send s4 pop!) #f > (define safe-stack% (class stack% (define/override (pop!) (if (super is-empty?) #f (super pop!))) (super-new))) super: identifier for super call does not have an override, override-final, overment, or inherit/super declaration in: is-empty? > (define safe-stack% (class stack% (define/override (pop!) (if (send this is-empty?) #f (super pop!))) (super-new))) > (define s5 (new safe-stack%)) > (send s5 push! 'hola) > (send s5 pop!) hola > (send s5 pop!) #f > (define i-extended-stack% (interface (i-stack%) size)) > (define extended-stack% (class* object% (i-extended-stack%) (inherit-field stack) (define/public (size) (length stack)) (super-new))) . class*: superclass does not provide field: stack for class: extended-stack% > (define extended-stack% (class* object% (i-extended-stack%) (stack null) (define/public (size) (length stack)) (super-new))) . class*: interface-required method missing: is-empty? for class: extended-stack% for interface: i-extended-stack% > (define extended-stack% (class* safe-stack% (i-extended-stack%) (inherit-field stack) (define/public (size) (length stack)) (super-new))) > (define name-mutator (class-field-mutator stack% name)) (define name-selector (class-field-accessor stack% name)) > name-mutator # > (name-mutator s1 'pepito) > (name-selector s1) pepito > (send s1 get-nombre) pepito > (field-names s1) (stack name) > (class s1) . class*: superclass expression returned a non-class: #(struct:object:stack% ...) for class: ...eshow/tool.ss:350:8>:191:2 > (is-a? s1 stack%) #t > (is-a? s1 fancy-stack%) #f > (is-a? s3 fancy-stack%) . reference to undefined identifier: s3 > (define contador% (let ((total 0)) (class object% (init-field (c 0)) (define/public (inc) (set! c (+ 1 c)) (set! total (+ 1 total)) c) (define/public (get-total) total) (super-new)))) > contador% # > total . reference to undefined identifier: total > (define c1 (new contador%)) (define c2 (new contador%)) (define c3 (new contador%)) > (send c1 inc) (send c1 inc) (send c1 inc) (send c2 inc) (send c2 inc) (send c3 inc) 1 2 3 1 2 1 > (send c3 total) . send: no such method: total for class: contador% > (send c3 get-total) 6 > (send c2 get-total) 6 >