Predicates in this group are used to create classes and objects, and to manipulate them after creation.
class, new, new_class/4, new_object/3
[]
for no parent. member
, static
, or constructor
, indicating an ordinary member predicate, a static predicate, or an object constructor. member
or constructor
, then the first argument of Clause will be passed the Self
object when the predicate is called. className
and prototype
are reserved and cannot be used as member names for declared variable or predicate members. var name1, ..., nameN name(Args) { ... } static name(Args) { ... } new(Args) { ... }
name1
, ..., nameN
set to unbound variables, and prototype
set to the class object. One of the constructor predicates is then called to initialize the object. Self
object as a hidden first argument. Static predicates do not have any hidden arguments.instantiation_error
- Name, Parent, Vars, or Clauses is a variable. type_error(atom, Name)
- Name is not an atom. type_error(atom, Parent)
- Parent is not an atom. type_error(atom, Var)
- Var is a member of Vars but it is not an atom. type_error(atom_list, Vars)
- Vars is not a valid list of atoms. type_error(clause_list, Clauses)
- Clauses is not a valid list of clauses. type_error(member_name, MemberName)
- MemberName is className
or prototype
. permission_error(create, class, Name)
- Name already exists as a class. permission_error(modify, static_procedure, Pred)
- attempting to define a predicate Pred that is already defined. existence_error(class, Parent)
- Parent does not exist as a class, and Parent is not []
.class vehicle { var owner, wheels transferOwnership(NewOwner) { Self.owner := NewOwner; } } class passenger_car : vehicle { var make, model new(Make, Model) { Self.wheels = 4; Self.make = Make; Self.model = Model; } } class company { var name var fleet new(Name) { Self.name = Name; Self.fleet = []; } add_vehicle(Vehicle) { Self.fleet := [Vehicle|Self.fleet]; } remove_vehicle(Vehicle) { remove(Vehicle, Self.fleet, List); Self.fleet := List; } } class truck : vehicle { var company new(Company, Wheels) { Self.company = Company; Self.owner = Company.name; Self.wheels = Wheels; Company.add_vehicle(Self); } transferOwnership(Company) { Self.company.remove_vehicle(Self); Self.company := Company; vehicle::transferOwnership(Self, Company.name); Company.add_vehicle(Self); } } class semi_trailer : truck { new(Company) { truck::new(Self, Company, 16); } } new passenger_car(P, "MegaCarz", "FastKar 2000"); P.owner = "Fred"; P.transferOwnership("Mary"); new company(C1, "Package Delivery, Inc."); new company(C2, "Deliver Packages, Inc."); new semi_trailer(S, C1); S.transferOwnership(C2);
instantiation_error
- Name or ArgList is a variable, or the tail of ArgList is not []
. type_error(atom, Name)
- Name is not an atom. type_error(variable, Var)
- Var is not a variable. type_error(list, ArgList)
- ArgList is not a list. existence_error(class, Name)
- Name does not exist as a class. existence_error(procedure, Pred)
- Pred is the name of the constructor predicate that new attempted to call but the constructor does not exist.class foo { new(X, Y) { ... } } class bar { } new foo(F, 1.5, f(X)) new bar(B) new_object(foo, F, [1.5, f(X)]) new_object(bar, B, [])