Skip to content

Instantly share code, notes, and snippets.

@netguy204
Created September 16, 2012 12:41

Revisions

  1. netguy204 created this gist Sep 16, 2012.
    34 changes: 34 additions & 0 deletions call.psl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    deffun vector(x, y, z) { x: x, y: y, z: z } in

    deffun sub(v1, v2)
    vector( -(v1.x, v2.x), -(v1.y, v2.y), -(v1.z, v2.z))
    in

    deffun abs(x)
    if <(x, 0) then -(0, x) else x
    in

    deffun mult(x, y)
    defvar yi = 0 in
    defvar r = 0 in {
    for(yi = 0; <(yi, abs(y)); yi++) {
    r = +(r, x);
    };
    abs(r);
    }
    in

    deffun dotP(v1, v2)
    +(mult(v1.x, v2.x), mult(v1.y, v2.y), mult(v1.z, v2.z));
    in

    deffun dist2(v1, v2)
    defvar td = sub(v1, v2) in {
    dotP(td, td)
    }
    in {
    print(dotP(vector(1,2,3), vector(4,5,6)));
    print(" ");
    print(dist2(vector(1,2,3), vector(4,5,6)));
    "";
    }