[wg11] Declarations inside algorithms
Alan R Williams
alanrw at cs.man.ac.uk
Wed Dec 8 07:13:14 EST 2004
Hello everyone,
I've a few questions about what should happen if an entity, for example, is
declared inside a function/procedure/rule.
(A)
SCHEMA s;
FUNCTION f : STRING;
ENTITY e_in_f;
END_ENTITY;
LOCAL
v : e_in_f := e_in_f ();
END_LOCAL;
RETURN (TYPEOF (v));
END_FUNCTION;
END_SCHEMA;
What should a call of f return? The description of TYPEOF only covers types
declared inside a schema.
(B)
Similarly for
SCHEMA s;
ENTITY e_outside_f;
END_ENTITY;
FUNCTION f : STRING;
ENTITY e_in_f
SUBTYPE OF (e_outside_f);
END_ENTITY;
LOCAL
v : e_in_f := e_outside_f() || e_in_f ();
END_LOCAL;
RETURN (TYPEOF (v));
END_FUNCTION;
END_SCHEMA;
what should f return?
(C)
SCHEMA s;
ENTITY identification;
s : STRING;
END_ENTITY;
ENTITY identified_object;
id_number : INTEGER;
DERIVE
id : identification := derive_numeric_identification (id_number);
END_ENTITY;
FUNCTION derive_numeric_identification (n : INTEGER) : identification;
ENTITY numeric_identification
SUBTYPE OF (identification);
x : INTEGER;
DERIVE
SELF\identification.s : STRING := FORMAT (x, '010I');
END_ENTITY;
RETURN (identification (?) || numeric_identification (n));
END_FUNCTION;
END_SCHEMA;
Yes it's an awful model :-)
Anyway, what does it mean to return an instance of a subtype
(numeric_identification) whose declaration is local to a function?
Is it invalid?
Does it somehow strip away the subtype-ness of the instance?
Thanks in advance,
Alan
Alan Williams, Room IT301, Department of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
Tel: +44 161 275 6270 Fax: +44 161 275 6280
More information about the wg11
mailing list