Skip to content

Commit 85e3bf6

Browse files
committed
more udpates on guidelines
1 parent 7fb052e commit 85e3bf6

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

templates/ai/guidelines/core/boxlang.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,30 @@ BoxLang is a modern, dynamic JVM language that compiles to Java bytecode. It com
1414
- **Modern class syntax** - Uses `class` instead of `component`
1515
- **Dynamic typing** - Optional type declarations with type inference
1616
- **Full Java interoperability** - Direct access to Java libraries and classes
17-
- **Lambda expressions** - Arrow function syntax `() => result`
17+
- **Closure expressions** - Arrow function syntax `() => result` carries the external state of its definition context
18+
- **Lambda expressions** - Arrow function syntax `() -> result` carries no external state, using only its parameters
1819
- **Streams API** - Functional data processing
1920
- **Low verbosity** - Minimal ceremony, highly readable code
20-
- **Multiple runtimes** - Web servers, CLI, AWS Lambda, Docker
21+
- **Multiple runtimes** - Web servers, CLI, AWS Lambda, Docker, and more
2122

2223
## Class Syntax
2324

2425
### Basic Class Structure
2526

27+
Annotations are supported in Boxlang using the `@` symbol. The `@inject` annotation is used for dependency injection by a framework. The annotation can be applied to classes, properties and functions. They can have no value, or the value within `( )` can be a boolean, integer, string, array or struct.
28+
2629
```boxlang
27-
class UserService {
28-
property name="userDAO" inject;
29-
property name="log" inject="logbox:logger:{this}";
30+
@singleton
31+
@anotherAnnotation( true )
32+
@anotherOne( "value" )
33+
@arrayAnnotation( [ "item1", "item2" ] )
34+
@structAnnotation( { key: "value" } )
35+
class{
36+
@inject
37+
property name="userDAO";
38+
39+
@inject( "logbox:logger:{this}" )
40+
property name="log";
3041
3142
function getAll() {
3243
return userDAO.findAll()
@@ -47,10 +58,12 @@ class UserService {
4758

4859
```boxlang
4960
// Auto-inject by name
50-
property name="userService" inject;
61+
@inject
62+
property name="userService";
5163
5264
// Explicit injection
53-
property name="cache" inject="cachebox:default";
65+
@inject( "cachebox:default" )
66+
property name="cache";
5467
5568
// Typed properties
5669
property name="count" type="numeric";
@@ -63,7 +76,7 @@ property name="status" type="string" default="pending";
6376
### Constructors
6477

6578
```boxlang
66-
class User {
79+
class {
6780
property name="firstName";
6881
property name="lastName";
6982
@@ -82,20 +95,27 @@ class User {
8295

8396
### Accessors
8497

98+
Automatic getters and setters are supported by default. You can enable or disable them at the class level with the `@accessors` annotation, but they are on by default for all properties. You can also define custom getters and setters if you need custom logic.
99+
100+
Implicit invokers are also on by default, allowing you to call getters and setters as if they were properties or functions without the `get`/`set` prefix.
101+
85102
```boxlang
86-
// Enable automatic getters/setters
87-
@accessors true
88-
class User {
103+
class {
89104
property name="firstName";
90105
property name="lastName";
91106
property name="email";
92107
}
93108
94109
// Usage
95110
user = new User()
111+
// Use setters and getters
96112
user.setFirstName( "Luis" )
97113
user.setLastName( "Majano" )
98114
var name = user.getFirstName()
115+
// Use implicit invokers
116+
user.firstName = "Luis"
117+
user.lastName = "Majano"
118+
var name = user.firstName
99119
```
100120

101121
## Lambda Expressions
@@ -189,6 +209,12 @@ var result = stringBuffer.toString()
189209
// Using new operator
190210
var uuid = new java:java.util.UUID.randomUUID()
191211
var dateFormatter = new java:java.text.SimpleDateFormat( "yyyy-MM-dd" )
212+
213+
// Importing Java classes
214+
import java.util.ArrayList
215+
var list = new ArrayList()
216+
list.add( "item1" )
217+
list.add( "item2" )
192218
```
193219

194220
### Java Casting
@@ -199,16 +225,21 @@ var intValue = javaCast( "int", 42 )
199225
var longValue = javaCast( "long", 1000000 )
200226
var boolValue = javaCast( "boolean", true )
201227
228+
// Use the castAs is prefferred.
229+
var intValue = 42 castAs int
230+
var longValue = 1000000 castAs long
231+
var boolValue = true castAs boolean
232+
202233
// Array casting
203-
var javaArray = javaCast( "java.lang.Object[]", [ 1, 2, 3 ] )
234+
var javaArray = [ 1, 2, 3 ] castAs java.lang.Object[]
204235
```
205236

206237
### Using Java Libraries
207238

208239
```boxlang
209240
// Import Java classes
210-
import java:java.util.ArrayList;
211-
import java:java.util.HashMap;
241+
import java:java.util.ArrayList
242+
import java:java.util.HashMap
212243
213244
class DataProcessor {
214245
function processData() {

0 commit comments

Comments
 (0)