Settings

Theme

Atypical returns with the (no) return statement

1 points by AtypecastA a year ago · 1 comment · 1 min read


I figuered out branch prediction is something out of predictability of a real software engineer working on top of a compiler in a higher level language... And I remembered Bill Gates writing self modifing code in the early MS-DOS days ...

Is it worthwile to introduce the (no) return statement in C++, Java, JavaScript and Kotlin with the following semantics:

(no) return; // pulls the top stack frame

(no) return all; // proceeds right after a call into recursion

(no) return 5; // pulls al frames such as the next return will jump to the fifth frame

(no) return -7; // pulls seven stack frames

Thanks a lot, community!

I enjoy ever visit and gained a lot of insight into my profession and beyond from all of you. Thank you very much.

<typecast>

gus_massa a year ago

I'm not sure what you want, but Racket/Scheme (and perhaps Clojure) have continuations that can be used for something similar [1]. Perhaps you need continuation marks and advanced macrology, that I'm afraid of.

> (no) return all; // proceeds right after a call into recursion

What about f -> g -> f -> g -> f -> g -> f -> g -> f ?

And f -> g -> f -> g -> f -> X -> f -> g -> f -> g -> f ?

[1] https://docs.racket-lang.org/guide/conts.html

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection