[BACK]Return to trip1.k CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097 / debug

Annotation of OpenXM/src/k097/debug/trip1.k, Revision 1.1.1.1

1.1       maekawa     1:
                      2:
                      3: /* test of class definition.  1997, 3/31, 4/1 */
                      4: /* a = Complex.new0(1,1);
                      5:    b = a+a;
                      6:    b.show();
                      7:    b.foo();
                      8: */
                      9: class Object extends PrimitiveObject {
                     10:    ;
                     11: }
                     12:
                     13: def void show() {
                     14:     local this2;
                     15:     this2 = this;
                     16:     Print(this2);
                     17: }
                     18:
                     19: sm1(" /ectag { dup isClass not { pop -1 } { lc } ifelse } def ");
                     20: def k00ecTag(a) { sm1(a," ectag /FunctionValue set "); }
                     21: def IsObject() {
                     22:   local this2;
                     23:   this2 = this;
                     24:   if (!IsArray(this2)) return(false);
                     25:   if (Length(this2) < 1) return(false);
                     26:   this2 = this2[0];
                     27:   if (k00ecTag(this2) == k00ecTag(Object[0])) return(true);
                     28:   else return(false);
                     29: }
                     30:
                     31: /* ------------------------------------- */
                     32: class Complex extends Object {
                     33:   local re,im;
                     34:   def new0(a,b) {
                     35:      local this2;
                     36:      this2 = this;
                     37:      return([this2[0],a,b]);
                     38:   }
                     39:   def void show() {
                     40:      local this2;
                     41:      this2 = this;
                     42:      Print("["); Print(this2[1]); Print("]+i["); Print(this2[2]);
                     43:      Print("]");
                     44:   }
                     45:   def void foo() {
                     46:      show();
                     47:      super.show();
                     48:   }
                     49:   def operator add(b) {
                     50:      local this2,ans;
                     51:      this2 = this;
                     52:      ans = Complex.new0(0,0);
                     53:      if (!this2.IsObject()) {
                     54:         Println("The first argument must be in Complex.");
                     55:         sm1(" error ");
                     56:      }
                     57:      if (!b.IsObject()) {
                     58:         Println("The second argument must be in Complex.");
                     59:         sm1(" error ");
                     60:      }
                     61:      ans[1] = this2[1]+b[1];
                     62:      ans[2] = this2[2]+b[2];
                     63:      return(ans);
                     64:   }
                     65:   def operator mul(b) {
                     66:      local x1,x2,x3,x4,this2,ans;
                     67:      this2 = this;
                     68:      ans = Complex.new0(0,0);
                     69:      x1 = this2[1]; x2 = this2[2];
                     70:      if (isComplex(b)) {
                     71:        y1 = b[1]; y2 = b[2];
                     72:        ans[1] = x1*y1-x2*y2;
                     73:        ans[2] = x1*y2+x2*y1;
                     74:        return(ans);
                     75:      }
                     76:      ans[1] = x1*b;
                     77:      ans[2] = x2*b;
                     78:      return(ans);
                     79:   }
                     80: }
                     81:
                     82: /* これがメンバ関数ではこまる. */
                     83: def isComplex(this2) {
                     84:    if (! this2.IsObject()) return(false);
                     85:    if (this2[0] == Complex[0]) return(true);
                     86:    else return(false);
                     87: }
                     88:
                     89: class Integer extends Object {
                     90:    local ii;
                     91:    def new0(i) {
                     92:       local this2;
                     93:       this2 = this;
                     94:       return([this2[0],i]);
                     95:    }
                     96:    one = Integer.new0(1);
                     97:    def operator sub(b) {
                     98:      local this2,ans;
                     99:      this2 = this;
                    100:      ans = Integer.new0(0);
                    101:      ans[1] = this2[1]-b[1];
                    102:      return(ans);
                    103:    }
                    104:   def operator mul(b) {
                    105:      local this2, ans;
                    106:      this2 = this;
                    107:      ans = Integer.new0(0);
                    108:      ans[1] = this2[1]*b[1];
                    109:      return(ans);
                    110:   }
                    111:   def isEqual(b) {
                    112:     local this2;
                    113:     this2 = this;
                    114:     if (this2[1] == b[1]) return(true);
                    115:     else return(false);
                    116:   }
                    117:   def factorial() {
                    118:     local this2,tmp;
                    119:     this2 = this;
                    120:     if (this.isEqual(one)) return( one );
                    121:     tmp = this2 - one;
                    122:     return( (tmp.factorial())* this2 );
                    123:   }
                    124: }
                    125:
                    126:
                    127:
                    128:
                    129:
                    130:
                    131:
                    132:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>