Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
:: - the :: operator
Calling Sequence
x :: T
Parameters
x
-
any expression
T
a type specification
Description
The operator serves several purposes in Maple, all related to types.
When used in a procedure parameter declaration, the left-hand side of the operator specifies the parameter name, and the right-hand side specifies the expected type of the argument.
The return type of a procedure can be declared by following the procedure's parameter declaration sequence by . In this context, serves as an assertion that the procedure returns a value of the specified type, T. If assertions are enabled, returning a value not matching the type will raise an exception.
When used as the left-hand side of an assignment statement or as the first argument to the assign function, asserts that the value being assigned to x is of type T.
A local variable can be declared with a type by using the operator. Within the procedure in which the variable is declared, any assignment made to it are treated as if the left-hand side of the assignment were written using the declaration.
In the condition of an if or while statement, serves as a type testing operator. In this context, is equivalent to .
The operator also acts as a type test when used as an argument to any of the Boolean operators, and, or, not, xor, implies, or the function.
In any other context, evaluates its arguments, but does not itself evaluate any further. Thus, it can be used as a data structure or part of a larger data structure. Although it is not required, it is customary to use as a data structure only when the right-hand side represents a type or a type-like concept. For example, see RealRange.
An expression using the operator is of type .
Thread Safety
The :: operator is thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
Examples
A common use of :: is to declare the type of procedure parameters.
f := proc( x::integer ) x^2 end proc:
Error, invalid input: f expects its 1st argument, x, to be of type integer, but received 3.4
The :: operator can assert the return type of a procedure.
f := proc( x::integer ) :: odd; x^2 end proc:
Error, (in f) assertion failed: f expects its return value to be of type odd, but computed 16
Using :: on the left-hand side of an assignment or declaring a local variable with :: asserts that the value being assigned is of the specified type.
Error, (in myassign) assertion failed in assignment, expected integer, got 3.4
f := proc( x ) local y::integer; y := x end proc:
Error, (in myassign) assertion failed in assignment, expected integer, got 4.5
In the condition of an if (or while) statement, the :: operator is equivalent to using the type function.
f := proc( x ) if x::integer then print("an integer") else print("not an integer") end if end proc:
The :: operator is inert if used out of context.
Expressions involving the :: operator are of type `::`.
See Also
boolean, evalb, if, parameter, procedure, while
Download Help Document