Language Design: Combining Gotos and Functions

Posted by sub on Stack Overflow See other posts from Stack Overflow or by sub
Published on 2010-04-09T15:10:09Z Indexed on 2010/04/09 15:13 UTC
Read the original article Hit count: 563

I'm designing and currently rethinking a low-level interpreted programming language with similarities to assembler.

I very soon came across the functions/loops/gotos decision problem and thought that while loops like while and for would be too high-level and unfitting, gotos would be too low level, unmaintainable and generally evil again. Functions like you know them from most languages that have return values and arguments aren't fitting in the language's concept either.

So I tried to figure out something between a function and a goto which is capable of

  • Recursion
  • Efficient loops

After some thinking I came up with the idea of subroutines:

  • They have a beginning and an end like a function
  • They have a name but no arguments like a goto
  • You can go into one with jump and go out of it again before its end with return (doesn't give back any result, only stops the subroutine)
  • Handled just like normal code -> Global scope like goto

So I wanted to know:

  • Is the idea above good? What are the (dis)advantages?
  • Would there be a better combination of function and goto or even a completely new idea?

© Stack Overflow or respective owner

Related posts about language-design

Related posts about interpreter