You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make them a keyword, which can automatically help users add corresponding pragmas, just like func does.
Motivation
In this RFC, it is a sweet syntax sugar, and in the future, it may become a new function type, just like converter and iterator.
When writing asynchronous code, we always type {.async.} over and over again. I wonder if it can reduce our typing burden if it becomes a syntax sugar.
nim uses indentation to express the structural hierarchy of control flow, which reduces many curly braces. If async and closure become keywords, the use of curly braces will be further reduced. I wonder if it can make the code more refreshing.
Description
In simple terms, the async keyword automatically adds {.async.}, and the closure keyword automatically adds {.closure.}.
Since async is not built-in in nim language, when the user uses this keyword, the compiler should search for async symbol in the current namespace. If it is not found, the compiler should terminate the compilation and give an error message.
In nim2.0, we have For loop macro, maybe, in the process of implementing async keyword, we can also have Async macro.
macroasync(stmt: AsyncProc) =result=newTree(nnkAsyncProc) # Create a new Async proc.
Code Examples
# This is an asynchronous functionasyncdoStuff(): int=discard# This is a closure functionclosuredoStuff(): int=discard# This is an asynchronous function pointerlet funptr: async (): int# This is an closure function pointerlet closureptr: closure (): int
Backwards Compatibility
The async macro of the third-party library chronos can pass parameters. When async becomes a keyword, it seems that there is no way to pass parameters
The text was updated successfully, but these errors were encountered:
Abstract
Make them a keyword, which can automatically help users add corresponding pragmas, just like
func
does.Motivation
In this RFC, it is a sweet syntax sugar, and in the future, it may become a new function type, just like
converter
anditerator
.When writing asynchronous code, we always type {.async.} over and over again. I wonder if it can reduce our typing burden if it becomes a syntax sugar.
nim uses indentation to express the structural hierarchy of control flow, which reduces many curly braces. If async and closure become keywords, the use of curly braces will be further reduced. I wonder if it can make the code more refreshing.
Description
In simple terms, the async keyword automatically adds
{.async.}
, and the closure keyword automatically adds{.closure.}
.Since async is not built-in in nim language, when the user uses this keyword, the compiler should search for async symbol in the current namespace. If it is not found, the compiler should terminate the compilation and give an error message.
In nim2.0, we have
For loop macro
, maybe, in the process of implementing async keyword, we can also haveAsync macro
.Code Examples
Backwards Compatibility
The
async
macro of the third-party library chronos can pass parameters. Whenasync
becomes a keyword, it seems that there is no way to pass parametersThe text was updated successfully, but these errors were encountered: