Jump to content

Talk:Return statement

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

I don't really like the use of <X> as syntax for a metasyntactic variable in C++ as it is ambiguous with the template syntax (and with the relational operators). Alternatives? Wouter Lievens 22:06, 13 Jun 2005 (UTC)

Lisp return

[edit]

Doesn't just 'value' also return the value? —Preceding unsigned comment added by 82.169.240.67 (talk) 15:12, 11 October 2008 (UTC)[reply]

Return vs GOTO

[edit]

Added a 'citation needed' as return statements can potentially return control to *any* client code. Also, GOTOs are commonly used with labels, which are single positions within the code. I guess this citation might be hard to find, and perhaps what we really need is a reference to work looking into the effects of return statements. Law of Demeter might a good starting point for that. 124.121.159.141 (talk) 06:25, 20 August 2009 (UTC)[reply]

Scala has no Return

[edit]

Is there a discussion about Scala's "no return statement" choice? Also in shell, the last statement will be the return value. Why? It can easily break if, say a log is added to the end of this subroutine. —Preceding unsigned comment added by 59.37.15.34 (talk) 06:33, 14 September 2009 (UTC)[reply]

Perl

[edit]

If value(s) omitted: returns undef or empty list (depending on context)

If return statement omitted: returns last statement value

PITA for you

[edit]

Coroutines are significantly more involved to implement than subroutines, and thus yield statements are less common than return statements, but they are found in a number of languages.

I read the other day that the greatest trick of the C language was convincing everyone it didn't have a runtime.

"The greatest trick that C ever pulled was convince the world that it does not have a runtime".

C has no standard ABI in principle, but in practice, this rarely matters: You do what your OS-vendor does.

Interesting, it's that same damn mind trick all over again.

By the time your vendor defines the entire function call ABI—which is 90% marshalling and stack management conventions—sure, implementing the return statement pretty much falls in your lap.

I just finished lecture 3 of Philip Guo's CPython Internals, and coroutines are really not that tricky once you decide to give every function execution frame it's own value stack.

But your OS is never going to give you this for free, because an OS isn't going to allocate an integer automatic as a first class PyObject out there somewhere in the magic heap (the most obvious way to support more than a single active grow/shrink boundary).

So you don't get to use all the free stuff from the invisible C runtime and OS-reified system language ABI, and I guess from some perspective, that's kind of a PITA.

Lua takes pains to split the difference, and that is indeed tricky to pull off.

See Chapter 6.

The problem here is not with the yield statement, it's with wanting to have the best of both worlds at the same time.

And guess what? Concurrent multitasking of ambition without adding molasses leads to brain ache.

The mantra in C++ is that you don't pay for what you don't use.

Wow, that only took 33 years. Look, Ma, no molasses! (But no grandchildren, either.) — MaxEnt 13:47, 14 September 2017 (UTC)[reply]

The meaning of the rightmost column in the table and the vertical alignment of text in that column

[edit]

@Peter Flass::

The rightmost column in the table has the heading "If value omitted, Return"; that column is for the definition (if any) of the behavior of a return statement that supplies no value if the function is defined as returning a value.

Is that not sufficient to indicate that it refers only to the behavior of return statements without a value, even if it doesn't happen to be vertically lined up with an example of such a return statement?

Note that:

  1. the first row of the table lists several languages where the return value need not be surrounded by parentheses and, as a result, no explicit example of a return statement without a return value was given (unlike PL/I, where clarification that a return statement without a value is just `return;`, rather than `return();`, is presumably necessary);
  2. that row also lists behaviors in several languages, so there are more lines of behaviors than there would be lines of examples of return statements even if an explicit example of a return statement without a value had been given. Guy Harris (talk) 19:07, 12 December 2020 (UTC)[reply]