Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7ef1228dde
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 65 lines (44 sloc) 1.494 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
module: objinst
synopsis: implementation of "Object Instantiation" benchmark
author: Peter Hinely
copyright: public domain


define sealed domain make (subclass(<toggle>));
define sealed domain initialize (<toggle>);


define class <toggle> (<object>)
  slot value :: <boolean>, required-init-keyword: start-state:;
end class;


define class <nth-toggle> (<toggle>)
  slot counter :: <integer> = 0;
  slot counter-maxiumum :: <integer>, required-init-keyword: counter-maxiumum:;
end class;


define method activate (t :: <toggle>) => t :: <toggle>;
  t.value := ~t.value;
  t;
end method;


define method activate (t :: <nth-toggle>) => t :: <toggle>;
  t.counter := t.counter + 1;
  if (t.counter >= t.counter-maxiumum)
    t.value := ~t.value;
    t.counter := 0;
  end;
  t;
end method;

    
define function main ()
  let arg = string-to-integer(element(application-arguments(), 0, default: "1"));

  let toggle = make(<toggle>, start-state: #t);

  for (i from 1 to 5)
    format-out("%s\n", if (activate(toggle).value) "true" else "false" end);
  end;

  for (i from 1 to arg)
    toggle := make(<toggle>, start-state: #t);
  end;

  format-out("\n");

  let nth-toggle = make(<nth-toggle>, start-state: #t, counter-maxiumum: 3);

  for (i from 1 to 8)
    format-out("%s\n", if (activate(nth-toggle).value) "true" else "false" end);
  end;

  for (i from 1 to arg)
    nth-toggle := make(<nth-toggle>, start-state: #t, counter-maxiumum: 3);
  end;
end function main;


main();
Something went wrong with that request. Please try again.