at:tutorial:appendix
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| at:tutorial:appendix [2008/07/10 17:29] – added tvcutsem | at:tutorial:appendix [2024/10/03 22:19] (current) – fixing path to exceptions module elisag | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Appendix: Libraries ====== | ====== Appendix: Libraries ====== | ||
| - | In the appendix, we explain useful libraries available to the AmbientTalk/ | + | In the appendix, we explain useful libraries available to the AmbientTalk/ |
| + | |||
| + | The Ambientalk standard library ('' | ||
| ===== Unit Testing Framework ===== | ===== Unit Testing Framework ===== | ||
| Line 27: | Line 29: | ||
| This will execute all '' | This will execute all '' | ||
| - | Like in JUnit and SUnit, it is possible to define two methods named '' | + | Like in JUnit and SUnit, it is possible to define two methods named '' |
| ==== Assertions ==== | ==== Assertions ==== | ||
| Line 82: | Line 84: | ||
| It is also possible to use '' | It is also possible to use '' | ||
| + | |||
| + | <note tip> | ||
| + | See the [[distribution# | ||
| + | </ | ||
| ==== Test Suites ==== | ==== Test Suites ==== | ||
| Line 347: | Line 353: | ||
| ===== Custom Exceptions ===== | ===== Custom Exceptions ===== | ||
| - | The module ''/ | + | The module ''/ |
| < | < | ||
| Line 386: | Line 392: | ||
| ===== Language Extensions ===== | ===== Language Extensions ===== | ||
| - | The files in the '' | + | The files in the '' |
| - | ==== Futures and Multifutures ==== | ||
| - | === Futures === | + | |
| + | |||
| + | =====Futures | ||
| + | |||
| + | ==== Futures ==== | ||
| The module ''/ | The module ''/ | ||
| Line 413: | Line 422: | ||
| </ | </ | ||
| - | Finally, the futures module also provides some auxiliary functions, of which '' | + | The '' |
| + | |||
| + | === Auxilary functions in the futures module ==== | ||
| + | |||
| + | The futures module also provides some auxiliary functions, of which '' | ||
| < | < | ||
| - | when: (group: [ a<-m(), b<-n() ]) becomes: { |values| | + | when: (group: [ a<-m()@FutureMessage, b<-n()@FutureMessage |
| def [aResult, bResult] := values; | def [aResult, bResult] := values; | ||
| ... | ... | ||
| Line 422: | Line 435: | ||
| </ | </ | ||
| - | === Multifutures === | + | Another useful auxilary function is '' |
| + | |||
| + | < | ||
| + | future: { |return| | ||
| + | // some computation | ||
| + | return(val) | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This is actually equivalent to the slightly more verbose code: | ||
| + | |||
| + | < | ||
| + | def [fut,res] := makeFuture(); | ||
| + | try: { // some computation | ||
| + | res.resolve(val); | ||
| + | } catch: Exception using: { |e| res.ruin(e) } | ||
| + | fut; | ||
| + | </ | ||
| + | |||
| + | ==== Multifutures | ||
| The module ''/ | The module ''/ | ||
| Line 463: | Line 495: | ||
| When the message sent to a multireference is annotated with @Due(t), the timeout is applied to the implicit multifuture, | When the message sent to a multireference is annotated with @Due(t), the timeout is applied to the implicit multifuture, | ||
| - | ==== Dynamic Variables ==== | + | |
| + | ===== Leased Object References ===== | ||
| + | |||
| + | The module ''/ | ||
| + | |||
| + | < | ||
| + | The implementation of leased object references actually consists of two files: ''/ | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | Variations of these constructs are also provided to allow developers to specify the renewal time interval in renew-on-call leased references and the name(s) of the method(s) which trigger expiration of a single-call leased reference. | ||
| + | |||
| + | The '' | ||
| + | |||
| + | < | ||
| + | renew: leasedRef for: interval; // renews a lease | ||
| + | revoke: leasedRef; // revokes a lease | ||
| + | leaseTimeLeft: | ||
| + | when: lease expired: {...}; // trigger a closure when the lease expires | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | |||
| + | Finally, the '' | ||
| + | |||
| + | |||
| + | |||
| + | ===== TOTAM ===== | ||
| + | |||
| + | The module ''/ | ||
| + | |||
| + | Please have a look to [[: | ||
| + | |||
| + | ===== Dynamic Variables | ||
| The module ''/ | The module ''/ | ||
| Line 490: | Line 559: | ||
| You can find more usage examples of dynamic variables in the unit test included in the file '' | You can find more usage examples of dynamic variables in the unit test included in the file '' | ||
| - | ==== Ambient References ==== | + | ===== Ambient References |
| Ambient references are defined in the module ''/ | Ambient references are defined in the module ''/ | ||
| Line 504: | Line 573: | ||
| Ambient references ship with two so-called " | Ambient references ship with two so-called " | ||
| - | ==== Structural Types ==== | + | ===== Structural Types ===== |
| The module ''/ | The module ''/ | ||
| Line 541: | Line 610: | ||
| More usage examples of structural types can be found in the unit test defined in the file '' | More usage examples of structural types can be found in the unit test defined in the file '' | ||
| - | ==== Traits ==== | + | ===== Traits |
| The module ''/ | The module ''/ | ||
| Line 574: | Line 643: | ||
| The files in the '' | The files in the '' | ||
| + | |||
| ==== Timing Utilities ==== | ==== Timing Utilities ==== | ||
| Line 597: | Line 667: | ||
| The timer module also defines a function '' | The timer module also defines a function '' | ||
| - | The timer module defines | + | Finally, there is a variant |
| + | |||
| + | < | ||
| + | def testAsyncNearbyPlayerReply(){ | ||
| + | def nearbyPlayers := // search 2 nearby player orjbects; | ||
| + | // wait a bit so that there are the 2 members. | ||
| + | when: 2.seconds elapsedWithFuture: | ||
| + | self.assertEquals(2, | ||
| + | } | ||
| + | }; | ||
| + | </ | ||
| ==== Logging Framework ==== | ==== Logging Framework ==== | ||
| Line 618: | Line 699: | ||
| ==== Object Inspector ==== | ==== Object Inspector ==== | ||
| - | The module ''/ | + | The module ''/ |
| < | < | ||
| - | import /.at.support.inspector; | + | import /.demo.inspector; |
| inspect(o); | inspect(o); | ||
| </ | </ | ||
| Line 628: | Line 709: | ||
| ==== Symbiosis Utilities ==== | ==== Symbiosis Utilities ==== | ||
| + | |||
| + | The module ''/ | ||
| + | |||
| + | < | ||
| + | long(anAmbientTalkNumber) -> aJavaLong | ||
| + | short(anAmbientTalkNumber) -> aJavaShort | ||
| + | float(anAmbientTalkFraction) -> aJavaFloat | ||
| + | byte(anAmbientTalkNumber) -> aJavaByte | ||
| + | </ | ||
| + | |||
| + | The module also defines the following function: | ||
| + | < | ||
| + | cast: obj into: Interface | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| ==== Miscellaneous ==== | ==== Miscellaneous ==== | ||
| + | |||
| + | The module ''/ | ||
| + | |||
| + | === Random Numbers === | ||
| + | |||
| + | The utility module defines functions for easily generating random numbers. Its implementation uses the random number generators from the underlying JVM. The following functions are the most useful: | ||
| + | |||
| + | < | ||
| + | // generate a random integer in the interval [min, max[ | ||
| + | def randomNumberBetween(min, | ||
| + | // generate a random fraction in the interval [min, max[ | ||
| + | def randomFractionBetween(min, | ||
| + | </ | ||
| + | |||
| + | === Custom Object Serialization === | ||
| + | |||
| + | The method '' | ||
| + | |||
| + | < | ||
| + | //inside a mirror | ||
| + | def instancevar := ...; | ||
| + | def pass() { | ||
| + | uponArrivalBecome: | ||
| + | // return object to become here | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The function plays a role similar to '' | ||
at/tutorial/appendix.1215703785.txt.gz · Last modified: (external edit)
