GDScript: First-class functions roadmap
Closed this issue ยท 8 comments
NOTE: All changes for 3.1 were implemented. Changes marked for 3.2 were postponed to 4.0 and will need a review, since it needs more details. I'll leave the original post for reference and link the new roadmap when ready.
Considering the long-standing requsts to support lambdas and first-class functions, and how that needs to break compatibility, here's the roadmap to the next Godot versions to enable the feature.
Related issues/pull requests:
- godotengine/godot#2684
- godotengine/godot#2704
- godotengine/godot#12170
- godotengine/godot#15486
- godotengine/godot#16090
Godot 3.1 (next release)
- Add a system for GDScript warnings. (godotengine/godot#18271)
- Deprecate using variables and functions with the same name.
- This will generate a warning if used, giving time for people using this feature to fix the code.
- Optional typing (godotengine/godot#10630, godotengine/godot#19264)
Godot 3.2 (release after the next)
- Make functions and class variables to live in the same namespace.
- This will break compatibility for people using variables and functions with the same name. Though they should be solved after the warnings in the previous version.
- Allow variables to contain references to functions.
- This means variables can also be used as functions:
var rot = $Sprite.rotate; rot(PI)
- This means variables can also be used as functions:
- Add syntax for lambda functions.
- Add type-hint syntax for functions.
This enables a few consequential features (may or may not be added):
- Allow
connect()
to receive a function reference instead of a string. - Add
map()
,reduce()
,filter()
functions to Array, all receiving a function as parameter.
And Finalizers???
@jonbonazza it's not on the plans and not related to this topic. You can open a feature proposal ticket with what you have in mind.
hi, just wondering if things like "Go To Definition" and "Find All References" are possible for variable and function inspections?
@vnen how is this coming up!? ;)
Is this still planned for 3.2?
Just found this issue. First class functions are moved to 4.0 AFAIU. https://twitter.com/reduzio/status/1137410475145216000 Or is it more complicated than that @vnen @akien-mga?
What happened is that I pretty much didn't have time to work on this for 3.2. There's also some implementation details discussed after this that would require changes to Variant, so it was preferred to be left for 4.0. The changes listed here will likely be implemented to 4.0 along with other stuff, so this roadmap need to be reviewed anyway.
I'll leave this here for history and add a note explaining the progress. Soon I will work on another proposal.
Hey,
Sorry for the necro-bump but I don't find any news about First class functions (I don't want to open a new ticket regarding that feature).
I wonder, will it be part of Godot 4.0? (including Array filter/reduce/map)