Comments (7)
If the proposed syntax is allowed to return a value from a function, the compiler must avoid local definition of variables of the same name.
from sarl.
The work on this issue should be done at the same time as the one for the issue #55.
from sarl.
We may introduce invariant conditions also:
agent A1 {
var int i
with invariant: i>0
}
from sarl.
Currently, the with
keyword is already defined. It is used for specifying generic types:
def push(s: A, i: B) with A extends Type1, B extends Type2 {
}
Currently, the generic type definitions could be assimilated to invariants.
from sarl.
Considering the precondition example given by @ngaud. It could be written with the current SARL syntax:
def push(s: String, i: Integer) : String with !Strings::isEmpty(s), i>0 {
// The code
null
}
Of course, the SARL compiler must be updated for detecting XExpression
associated to the with
keyword, and for generating the Java code that corresponds to the pre-condition tests.
I propose to generate the following Java code:
public String push(final String s, final Integer i) {
assert !Strings.isEmpty(s) : "Invalid pre-condition \"!Strings::isEmpty(s)\"'";
assert i > 0 : "Invalid pre-condition \"i>0\"'";
// The code
return null;
}
Regarding the postcondition, we may define a keyword "post ".
def push(s: String, i: Integer) : String with post Strings::isEmpty(it) {
// The code
}
The it
keyword will be mapped to the returned value in the context of the postcondition.
The generated Java code may be:
public String push(final String s, final Integer i) {
String $$returnedValue;
try {
// The code
$$returnedValue = null;
return $$returnedValue;
} finally {
final String it = $$returnedValue;
assert Strings::isEmpty(it) : "Invalid postcondition \"Strings::isEmpty(it)\"";
}
}
from sarl.
Pre and post conditions should also be used for static validation by the SARL compiler.
from sarl.
This issue in now part of the PhD thesis of @tpiotrow.
from sarl.
Related Issues (20)
- Add SRE when exporting a runnable Jar. HOT 1
- Integration tests written in SARL are not generated in the correct Java source folder.
- JVM shared library does not contain JNI_Create JavaVM symbol HOT 3
- Eclipse error on the editor state. HOT 1
- Use MutabilityDetector for implementing the SARL function purity detector.
- Stack overflow in Eclipse IDE.
- Generate a product for MacOS ARM
- Invalid build date in the Bundle property messages.
- Upgrade to Eclipse 2023-09
- Include BDI engine is SARL.
- Fix CodeQL configuration to compile SARL on the CI server.
- Typo error in sarl-maven-plugin
- Invalid function call resolution.
- Link to demos are not working from the website HOT 1
- Kernel logs are not displayed anymore HOT 2
- Create a sample project from welcome page does not work anymore HOT 1
- Invalid markdown rendering in FAQ.
- Damaged product for macOS HOT 3
- Specification and implementation of communication protocols
- ExecutorService vs Thread with task buffer.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sarl.