ympbyc / LittleSmallscript

JavaScript with Smalltalk's syntax

Home Page:http://ympbyc.github.io/LittleSmallscript/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"^ expression" should return the velue of the expression as the method's return value.

ympbyc opened this issue · comments

This is a proposal for implementing the behaviour of ^.
In smalltalk, ^ allows you to "early return".

SomeClass method: [
  (1 < 2) ifTrue: [^ 'one is less than two'].
  'one is greater than two'
] dot: #oneTwo

could be compiled into

SomeClass.prototype.oneTwo = function () {
  var _this = this, _ret = undefined;
  _ret = (1 < 2) ? (function () {return 'one is less than two'})() : void 0;
  if (_ret !== undefined) return _ret;
  return 'one is greater than two'
};

or preferably

SomeClass.prototype.oneTwo = function () {
  var _this = this;
  if (1 < 2) 
     return (function () {return 'one is less than two'})();
  return 'one is greater than two'
};

I am not planning to implement this. Re-open if anyone wants this.