return =

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

return =

Bob Myers
To continue the "stupid idea of the day" series, I have often felt the need to indicate a return value other than as part of a `return` statement.

Perhaps this is my BASIC background--the dialect I used all those years ago allowed an assignment to the function name to pre-specify a return value, which would then be used whenever the function finally finished.

My initial suggestion is to use the `return =` syntax, which is a syntax error right now so it should not conflict with anything.

Trivial examples:

```js
function double(a) {
  const b = return = [];
  for (elt of a) b.push(elt*2);
}
```

```js
function bar() {
  const val = someCalculation();
  report(return = val);
}
```

Not to belabor the point, but of course there is no new functionality here; it's just a matter of conciseness. However, it could also perhaps be used to allow the use of arrow functions when you want to do something without returning its value but maintain the concise body form:

```js
const a = () => doThing(return = a);
```

Bob

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: return =

Peter Jaszkowiak
Wow that's fanatically disgusting. Please no.

On Mon, Sep 3, 2018, 12:27 Bob Myers <[hidden email]> wrote:
To continue the "stupid idea of the day" series, I have often felt the need to indicate a return value other than as part of a `return` statement.

Perhaps this is my BASIC background--the dialect I used all those years ago allowed an assignment to the function name to pre-specify a return value, which would then be used whenever the function finally finished.

My initial suggestion is to use the `return =` syntax, which is a syntax error right now so it should not conflict with anything.

Trivial examples:

```js
function double(a) {
  const b = return = [];
  for (elt of a) b.push(elt*2);
}
```

```js
function bar() {
  const val = someCalculation();
  report(return = val);
}
```

Not to belabor the point, but of course there is no new functionality here; it's just a matter of conciseness. However, it could also perhaps be used to allow the use of arrow functions when you want to do something without returning its value but maintain the concise body form:

```js
const a = () => doThing(return = a);
```

Bob
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: return =

Isiah Meadows-2
There is literally only one language I've seen that has anything like
this, and it's Verilog, a hardware description language. (It's also of
questionable utility, and it's restricted to just simulator-only
constructs.) That's not an endorsement, more like the opposite of one.

-----

Isiah Meadows
[hidden email]
www.isiahmeadows.com

On Mon, Sep 3, 2018 at 2:29 PM Peter Jaszkowiak <[hidden email]> wrote:

>
> Wow that's fanatically disgusting. Please no.
>
> On Mon, Sep 3, 2018, 12:27 Bob Myers <[hidden email]> wrote:
>>
>> To continue the "stupid idea of the day" series, I have often felt the need to indicate a return value other than as part of a `return` statement.
>>
>> Perhaps this is my BASIC background--the dialect I used all those years ago allowed an assignment to the function name to pre-specify a return value, which would then be used whenever the function finally finished.
>>
>> My initial suggestion is to use the `return =` syntax, which is a syntax error right now so it should not conflict with anything.
>>
>> Trivial examples:
>>
>> ```js
>> function double(a) {
>>   const b = return = [];
>>   for (elt of a) b.push(elt*2);
>> }
>> ```
>>
>> ```js
>> function bar() {
>>   const val = someCalculation();
>>   report(return = val);
>> }
>> ```
>>
>> Not to belabor the point, but of course there is no new functionality here; it's just a matter of conciseness. However, it could also perhaps be used to allow the use of arrow functions when you want to do something without returning its value but maintain the concise body form:
>>
>> ```js
>> const a = () => doThing(return = a);
>> ```
>>
>> Bob
>> _______________________________________________
>> es-discuss mailing list
>> [hidden email]
>> https://mail.mozilla.org/listinfo/es-discuss
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: return =

Waldemar Horwat
On 09/03/2018 11:32 AM, Isiah Meadows wrote:
> There is literally only one language I've seen that has anything like
> this, and it's Verilog, a hardware description language. (It's also of
> questionable utility, and it's restricted to just simulator-only
> constructs.) That's not an endorsement, more like the opposite of one.

Pascal works that way too.  You use an assignment statement to assign to the name of the function to set a function's return value.

     Waldemar
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss