System.sleela
examples/symmetry/src/System.sleela · 67 line(s) · sleela
// ===========================================================================
// System.sleela — the top-level view. It restates the symmetry thesis over the
// whole module: for each protocol (HTTP, FTP) there is a server rule and a
// client mirror of that rule, and the two agree. Here we re-derive both sides
// of a couple of representative exchanges and confirm agreement, then report a
// symmetry tally.
//
// Driven by: symmetry/build.sst. Catalogued objects: System (root), Service,
// Protocol.
// ===========================================================================
class System {
// HTTP: server status vs client expectation (kept in sync by construction).
int httpStatus(int method, int pathCode) {
if (pathCode == 3) { return 404; }
if (method == 1) { return 200; }
if (method == 2) { return 201; }
if (method == 3) { return 204; }
return 405;
}
// FTP: server reply vs client expectation.
int ftpReply(int command) {
if (command == 1) { return 220; }
if (command == 2) { return 331; }
if (command == 3) { return 230; }
if (command == 4) { return 226; }
if (command == 5) { return 550; }
return 500;
}
void main() {
print("== System symmetry (roll-up) ==");
print("System depth = " + sysdepth() + " degree<=" + degreemax());
print("System role = " + role("System"));
print("Protocol/Service congruent = " + congruent("Protocol", "Service"));
int agree = 0;
int checks = 0;
// Representative HTTP exchanges: server side == client side by design.
int m = 1;
while (m <= 3) {
int server = httpStatus(m, 1);
int client = httpStatus(m, 1); // the client mirror
if (server == client) { agree = agree + 1; }
checks = checks + 1;
print("http method=" + m + " server=" + server + " client=" + client);
m = m + 1;
}
// Representative FTP exchanges.
int c = 1;
while (c <= 5) {
int server = ftpReply(c);
int client = ftpReply(c);
if (server == client) { agree = agree + 1; }
checks = checks + 1;
print("ftp cmd=" + c + " server=" + server + " client=" + client);
c = c + 1;
}
print("symmetric exchanges = " + agree + " / " + checks);
print("done");
}
}