Functions, Procedures and Packages# Introduction Functions and Procedures Functions function function func f := func< x₁, ..., xₙ, ... : parameters | expression >; Example: Recursion Example: Parameters Example: Underscore Example: Variadic Procedures procedure procedure proc p := proc< x₁, ..., xₙ, ... : parameters | expression >; Example: Procedures The forward Declaration forward Example: forward Packages Introduction Intrinsics intrinsic Example: intrinsic Resolving Calls to Intrinsics Example: Intrinsic Lookup Attaching and Detaching Package Files Attach(F): MonStgElt Detach(F): MonStgElt freeze; Related Files Importing Constants import "filename": ident_list; Example: import Argument Checking require condition: print_args; requirerange v, L, U; requirege v, L; Example: require The Number of Results NumberOfResults() → RngIntElt, [ BoolElt ] Nresults() → RngIntElt, [ BoolElt ] Example: Nresults Package Specification Files AttachSpec(S): MonStgElt DetachSpec(S): MonStgElt Example: spec User Startup Specification Files Example: Startup Spec Attributes Predefined System Attributes User-defined Attributes AddAttribute(C, F): Cat, MonStgElt → ; declare attributes C: F₁,...,Fₙ; Accessing Attributes S`fieldname: Str, Fieldname → Elt S`` N: Str, Str → Elt assigned S`fieldname: Str, Fieldname → BoolElt assigned S`` N: Str, Str → BoolElt S`fieldname := expression; S`` N := expression; delete S`fieldname; delete S`` N; GetAttributes(C): Cat → [ MonStgElt ] ListAttributes(C): Cat User-defined Verbose Flags declare verbose F, m; Examples Example: System Attributes Example: Interactive User Attributes Example: Package User Attributes User-Defined Types Declaring User-Defined Types declare type T; declare type T: P₁, ..., Pₙ; declare type T[E]; declare type T[E]: P₁, ..., Pₙ; Creating an Object New(T): Type → T Clone(X): Any → Any Special Intrinsics Provided by the User Examples Example: My Rat Example: User Types2