News for hackers. Stuff that matters.
Re:Ask HN: How does the return statement of a function work? by duped on Monday April 10, 2023 @12:06PM (#35513912)
> So values that are returned need not be primitive values like basic ints, floats, strings, etc? They can be complicated structure values also?

It depends on the language and the rules about what structures can hold.

For example, say your function doesn't return a value, but returns another function, and that function refers to variables in the first (this is called a "closure" or "lambda", the variable is "captured" or "closed over" by the returned function).

In some languages this is OK and normal to do, in others there's no guarantee that the original variable exists anymore and the behavior is "undefined", and in others it is forbidden.

The way that it is implemented also depends on the language.

There are no comments on this comment yet.