ETSI's Bug Tracker |
Anonymous | Login | Signup for local Mantis account | 30-04-2024 12:36 IST |
Main | My View | View Issues | Change Log | Roadmap | Monitor project |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||||||
0008188 | Ext Pack: Behaviour Types (ES 202 785) | New Feature | public | 11-01-2023 12:57 | 26-01-2024 16:28 | ||||||||
Reporter | Matthias Simon | ||||||||||||
Assigned To | Gusztáv Adamis | ||||||||||||
Priority | normal | Severity | minor | Reproducibility | have not tried | ||||||||
Status | assigned | Resolution | open | ||||||||||
Platform | OS | OS Version | |||||||||||
Product Version | |||||||||||||
Target Version | Fixed in Version | ||||||||||||
Summary | 0008188: Support for function literals | ||||||||||||
Description | A function literal, also known as lambda function or anonymous function, is a function definition without name. Example: var fn := function (integer x) return boolean { return x mod 2 == 0 } apply(fn(23)); | ||||||||||||
Tags | No tags attached. | ||||||||||||
Clause Reference(s) | n/a | ||||||||||||
Source (company - Author) | Nokia - Matthias Simon | ||||||||||||
Attached Files | |||||||||||||
Notes | |
(0016522) Jens Grabowski (manager) 05-09-2023 11:06 |
TTF discussion: More elaborated example needed. |
(0016549) Matthias Simon (developer) 08-11-2023 12:35 |
Function literals are evaluated lazily and capture their context. This makes implementation of deferred functions feasible. For example: type function CancelFunc(); testcase Example() runs on MTC { // start fixtures var cancel := SetupDatabase(); // do some testing // handle graceful shutdown cancel(); } function SetupDatabase() return CancelFunc { var db := DatabaseComponent.create; db.start(listen()); return function() { db.stop; // Captures db and allows to call methods, locally } } Another use-case is parametrizing callbacks: module Service { type component Component { /* ... */ } function Start(in ExitFunc ef := withSuccess) return Component { var c := Component.create; c.start(mainLoop(ef)); return c; } private function mainLoop(ExitFunc ef) runs on Component { p.receive(ProcessState:{started := ?}); log("Service is up and running"); var ExitCode ec; p.receive(ProcessState:{exited := ?}) -> value ec; f(ec); } type function ExitFunc(ExitCode ec) runs on Component; type enumerated ExitCode { SUCCESS(0), ERROR(1..127), SIGTERM(-15), SIGKILL(-9), } group helpers { function withSuccess(in ExitCode ec) runs on Component { if (ec != SUCCESS) { setverdict(fail, "want=0, got=" & ec); stop; } } function withError(in ExitCode ec) runs on Component { if (ec != ERROR) { setverdict(fail, "want!=0, got=" & ec); stop; } } function withSignal(in ExitCode sig) return ExitFunc { return function(in ExitCode ec) runs on Component { if (ec != sig) { setverdict(fail, "want=" & sig, got=" & ec); stop; } } } function withTimeout(in float duration) return ExitFunc { return function(in ExitCode ec) runs on Component { // ... } } } module Example { testcase SunnyDay() { var service1 := Service.Start(); var service2 := Service.Start(Service.withError); // do some API testing... all components.done; } testcase ResilianceTest_ServiceCrashes() { var service1 := Service.Start(Service.withSignal(Service.SIGTERM)); var service2 := Service.Start(Service.withTimeout(60.0)); // do some API testing... all components.done; } } |
(0016569) Gusztáv Adamis (developer) 09-11-2023 20:52 |
The problems in examples can be solved with the existing TTCN-3 instructions. |
(0016610) Olivier Genoud (administrator) 26-01-2024 16:28 |
We assume/expect that this CR will not become part of the core language but will become part of an extension or be added to an extension (e.g. OO extension). |
Issue History | |||
Date Modified | Username | Field | Change |
11-01-2023 12:57 | Matthias Simon | New Issue | |
05-09-2023 11:06 | Jens Grabowski | Note Added: 0016522 | |
05-09-2023 11:07 | Jens Grabowski | Assigned To | => Matthias Simon |
05-09-2023 11:07 | Jens Grabowski | Status | new => assigned |
08-11-2023 12:35 | Matthias Simon | Note Added: 0016549 | |
08-11-2023 13:54 | Jens Grabowski | Assigned To | Matthias Simon => Jens Grabowski |
08-11-2023 13:54 | Jens Grabowski | Assigned To | Jens Grabowski => Matthias Simon |
08-11-2023 13:54 | Jens Grabowski | Assigned To | Matthias Simon => Gusztáv Adamis |
09-11-2023 20:52 | Gusztáv Adamis | Note Added: 0016569 | |
26-01-2024 16:28 | Olivier Genoud | Note Added: 0016610 |
MantisBT 1.2.14 [^] Copyright © 2000 - 2024 MantisBT Team |