Re: Add method to one object only?
Thanks. In my case I wanted the object itself to create the new method, so I did like this: (push This '(newMsg> () (prinl "Yes!"))) /Jon > On 10. Jun, 2016, at 13:07, Alexander Burgerwrote: > > On Fri, Jun 10, 2016 at 11:50:07AM +0200, Alexander Burger wrote: >> (push Obj (cons 'msg> '((X) (bar >> >> or >> >> (push Obj '(msg> (X) (bar))) > > Two notes: > > 1. If the symbol 'msg>' is not yet defined as a message in another > context (e.g. with (dm msg> ...)), then you can do that on the fly > with: > > (setq msg> meth) > > 2. Instead of 'push'ing the method into the value as above, you may > sometimes pass it already when creating the object: > > (setq Obj > (new '((msg> (N) (+ (: a) N)) +Cls) >'a 7 >'s "abc" ) ) > > (msg> Obj 1) > -> 8 > > ♪♫ Alex
Re: Add method to one object only?
On Fri, Jun 10, 2016 at 11:50:07AM +0200, Alexander Burger wrote: >(push Obj (cons 'msg> '((X) (bar > > or > >(push Obj '(msg> (X) (bar))) Two notes: 1. If the symbol 'msg>' is not yet defined as a message in another context (e.g. with (dm msg> ...)), then you can do that on the fly with: (setq msg> meth) 2. Instead of 'push'ing the method into the value as above, you may sometimes pass it already when creating the object: (setq Obj (new '((msg> (N) (+ (: a) N)) +Cls) 'a 7 's "abc" ) ) (msg> Obj 1) -> 8 ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Add method to one object only?
Thanks, Alex! That was nice and easy. /Jon > On 10. Jun, 2016, at 11:50, Alexander Burgerwrote: > > Hi Jon, > >> If one has a few objects of the same class +C, would it be possible to >> add a new method to just one of these objects, without all the others >> also getting that new method? > > You can add a method to an object (or also a class) by adding a cons > pair (msg> . fun) to its value. > > (push Obj (cons 'msg> '((X) (bar > > or > > (push Obj '(msg> (X) (bar))) > > Internally, there is no formal difference between classes and objects. > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Add method to one object only?
Hi, If one has a few objects of the same class +C, would it be possible to add a new method to just one of these objects, without all the others also getting that new method? /Jon-- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe