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
ModuleIterator - モジュールの要素を繰り返し実行
使い方
module() export ModuleIterator, ...; ... end module;
説明
ModuleIterator ルーチンにより、module または object はモジュール (またはオブジェクト) 内に含まれる要素を繰り返すために使用可能なインターフェースを出力します。
モジュールが ModuleIterator ルーチンを定義する場合、そのモジュールは for-in ループのコンテナとして、および seq、add および mul のコールとして使用できます。
ModuleIterator のコールは、2 つのプロシージャを出力します。
(hasNext,getNext) := ModuleIterator( obj );
hasNext 関数は、残っている要素があるかどうかに応じて true または false を出力します。
getNext 関数は、アクセスする次の関数を出力します。
これらのルーチンを使用するための基本的なパターンは、以下のとおりです。
while hasNext() do e := getNext(); # Do something with e. od;
hasNext が true を出力する場合は、getNext のコールは常に安全です。hasNext のコールが false を出力する場合は、getNext のコールのリターン値は未指定です。
互換性
ModuleIterator コマンドは Maple 16 で導入されました。
Maple 16 における変更点についての詳細は、Maple 16 の新機能 を参照してください。
例
すべての素数の処理を繰り返すモジュールを作成します。
Primes := module() export ModuleIterator := proc() local i; i := 1; ( proc() i := nextprime( i ); true; end, proc() i; end ) end; end;
素数は無限にあるため、独自の終了条件を指定する必要があります。
for i in Primes do if ( i > 100 ) then break; end; print( i ); end;
コンテナオブジェクトと ModuleIterator は Maple 組み込み構造のように使用できます。
module IterObj() option object; local _list; export setValue::static := proc( obj::IterObj, l::list ) obj:-_list := l end; export ModuleIterator::static := proc( obj::IterObj ) local i, l; i := 1; l := obj:-_list; ( proc() i <= numelems( l ) end, proc() local e; e := l[i]; i := i+1; e; end ); end; end:
io := Object( IterObj ):
setValue( io, [1,2,3] ):
( hasNext, getNext ) := ModuleIterator( io );
while hasNext() do e := getNext(); od;
for i in io do i; od;
add( i, i in io );
mul( i, i in io );
seq( i^2, i in io );
関連項目
add, for, module, mul, Object, Object,create, Object,methods, Object,overview, procedure, seq
Download Help Document