Nested structs and functions within structs
See original GitHub issueGoal
Allow for nested structs and functions within structs.
Overview
Depends on (#28)
Closures are cool, but to be useful you’d want to return an object/struct with a closure or another struct as a field.
Basically, this syntax should be possible
type lambda Closure = () => i32;
type Struct = {
increment: Closure,
decrement: Closure
};
function getActions(): Struct {
let x: i32 = 0;
const result: Struct = 0;
result = {
increment: (): i32 => {
x += 1;
return x;
},
decrement: (): i32 => {
x -= 1;
return x;
},
getX: (): i32 => { return x; }
};
return result;
}
export function test() : i32 {
const actions: Struct = getActions();
actions.increment();
actions.increment();
actions.decrement();
// should be 1
return actions.getX();
}
This should make the syntax much more expressive and allow for a wide range of applications.
Acceptance Criteria
- Allow nested struct types within other structs
- Allow closure types within structs
- Test everything
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Nested Structure in C with Examples - GeeksforGeeks
A nested structure in C is a structure within structure. One structure can be declared inside another structure in the same way structure...
Read more >Nested Structure in C - Scaler Topics
Nested structures can be passed to functions directly by passing the structure as an argument to the function. ... Here the structure variable...
Read more >Nested Structure in C | C Program | Fresh2refresh
Nested structure in C is nothing but structure within structure. ... This program explains how to use structure within structure in C using...
Read more >What is the purpose of using nested struct's in c programming ...
Grouping information in meaningful structures is useful to write functions that deal with the group independently of whether it is a stand ...
Read more >Nested Structures in C - C Programming Tutorial - OverIQ.com
A structure can be nested inside another structure. In other words, the members of a structure can be of any other type including...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Might I also suggest replacing the ‘type’ keyword for ‘lambda’. For example 'lambda Func = () => i32’
Note: I’m on my phone and I’m unsure how the syntax style formatting works.
Cool, so are you suggesting that we should have a built-in type for
Lambda
instead of a keyword? That could work I think with something like thisor
I personally have not seen this particular use of generics before, but this could work. Would need a type parser change/PR but I like it 👍