lisp - What's the equivalent of constructors in CLOS? -


how express following java code in lisp?

class foo {     private string s;      public foo(string s) {         this.s = s;     } }  class bar extends foo {     public bar(int i) {         super(integer.tostring(i));     } } 

in lisp, make-instance or initialize-instance equivalent of constructor? if yes, how call super class constructor(s)?

use call-next-method within method call next one.

typically use standard method combination facility , write :before, :after or :around method initialize-instance.

one way:

(defclass foo ()   ((s :type string :initarg :s)))  (defclass bar (foo) ())  (defmethod initialize-instance :around ((b bar) &key i)   (call-next-method b :s (princ-to-string i))) 

example:

cl-user 17 > (make-instance 'bar :i 10) #<bar 402000b95b>  cl-user 18 > (describe *)  #<bar 4130439703> bar s      "10" 

note i've called call-next-method without changing argument dispatches on. changed &key initarg parameter.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -