module: Dylan2-test define method sqr(x) x * x end; define method sqrt(x) block(return) for (i :: from 1 to x) if (sqr(i) > x) return(i - 1) end end end end; define class () slot x, required-init-keyword: x:; slot y, required-init-keyword: y:; end; define class () slot x, required-init-keyword: x:; slot y, required-init-keyword: y:; slot z, required-init-keyword: z:; end; define method translate(p, xx) let p = clone(p); p.x := p.x + xx; p end; define method clone(p :: ) make(, x: p.x, y: p.y) end; define method clone(p :: ) make(, x: p.x, y: p.y, z: p.z) end; define method my-add(p1 :: , p2 :: ) make(, x: p1.x + p2.x, y: p1.y + p2.y) end; define method my-add(p1 :: , p2 :: ) make(, x: p1.x + p2.x, y: p1.y + p2.y, z: p1.z + p2.z) end; define method to-string(p :: ) concatenate("[", integer-to-string(p.x), ", ", integer-to-string(p.y), "]") end; define method to-string(p :: ) concatenate("[", integer-to-string(p.x), ", ", integer-to-string(p.y), ", ", integer-to-string(p.z), "]") end; define method my-length(p :: ) sqrt(sqr(p.x) + sqr(p.y)) end; define method my-length(p :: ) sqrt(sqr(p.x) + sqr(p.y) + sqr(p.z)) end; define method test(p) list(my-length(p), to-string(translate(p, 1))) end; define method twice(p) my-add(p, p) end; define method main (_argv0, #rest _noise) let p2d = make(, x: 3, y: 4); let p3d = make(, x: 1, y: 2, z: 2); let l = list(p2d, p3d); print(list(test(p2d), test(p3d), map(my-length, l))); // after translate, we still have a Point3d print(translate(p3d, 1).z); print(map(to-string, pair(twice(p2d), pair(twice(p3d), map(twice, l))))); // print(my-add(p2d, p3d)); // print(my-add(p3d, p2d)); // after twice, we still have a Point3d print(twice(p3d).z); end; // Local Variables: // mode: dylan // End: