Quickies

[categories] [index] [all (552)] [latest]

PostScript
  1. /objMethods 
    <<
        /addOne { 
            /_self exch def
            _self/ivar1 _self/ivar1 get 1 add put 
        }
    >> def
    
    /call {
        1 index /_methods get 
        exch get exec
    } def
    
    /d1 
    <<
        /ivar1 1
        /ivar2 2
        /_methods objMethods
    >> def
    
    /d2 
    <<
        /ivar1 10
        /ivar2 20
        /_methods objMethods
    >> def
    
    % Use object 1
    d1/ivar1 get ==
    d1/addOne call
    d1/ivar1 get ==
    
    % Use object 2
    d2/ivar1 get ==
    d2/addOne call
    d2/ivar1 get ==
    

    prints:

    1
    2
    10
    11