TodePond / DreamBerd

perfect programming language
https://dreamberd.computer
Other
11.15k stars 344 forks source link

nowait keyword is inverse await #141

Open xen1024 opened 1 year ago

xen1024 commented 1 year ago

nowait is inverse await

Just like await click(); await ..; await .. but nowait nowait nowait.

Use await as default mode and nowait for no wait statements to understand better and lint that instruction will not wait. Very useful for teaching beginners about asynchronous processes and multithreading because repeat, repeat, repeat!

!nowait code
nowait print("Hello!")! 
reqest(http)! // wait for response
nowait print("World!")!
nowait return!

Possible modifications.

const var file = nowait open(path)! // no wait open file, like NodeJS fs.openSync(path) but looks better 
nowait_once pool(file)! // first time no wait then await
nowait nowait nowait close(file); // no wait 3 times then await
stohrendorf commented 1 year ago

Hm... given that await waits for the calculation of future values, what if you can nowait to retrieve past values?

xen1024 commented 1 year ago

Hm... given that await waits for the calculation of future values, what if you can nowait to retrieve past values?

Sounds good, this will provide the flexibility of "nowait". Predicting answers from the future will also improve usability.

// Past
const var response = nowait(-1) request(http)! // no wait and return last response
nowait(2) request(http)! // no wait and return previous response by index 2
nowait(2h) request(http)! // no wait and return previous response 2 hours ago
nowait(365d) request(http)! // no wait and return previous response 365 days ago
nowait(7+2i) request(http)! // no wait and return previous response from a complex number
// Future
nowait(+2s) request(http)! // no wait and return predicting the future in 2 seconds
nowait(10q) request(http)! // no wait and return predicting the future using 10 qubits