Skip to content

Commit

Permalink
rm BOOL() -> instead use obj.__bool__()
Browse files Browse the repository at this point in the history
- build v0.0.39
  • Loading branch information
mohayonao committed May 26, 2014
1 parent 6920743 commit 75023d8
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.38",
"version": "0.0.39",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
3 changes: 1 addition & 2 deletions src/sc/classlib/Collections/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ SCScript.install(function(sc) {
var mathlib = sc.libs.mathlib;

sc.lang.klass.refine("Array", function(spec, utils) {
var BOOL = utils.BOOL;
var $nil = utils.$nil;
var SCArray = $("Array");

Expand Down Expand Up @@ -548,7 +547,7 @@ SCScript.install(function(sc) {
var i, imax;

for (i = 0, imax = raw.length; i < imax; ++i) {
if (BOOL(raw[i].isSequenceableCollection())) {
if (raw[i].isSequenceableCollection().__bool__()) {
return $.True();
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/sc/classlib/Collections/ArrayedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SCScript.install(function(sc) {
var mathlib = sc.libs.mathlib;

sc.lang.klass.refine("ArrayedCollection", function(spec, utils) {
var BOOL = utils.BOOL;
var $nil = utils.$nil;
var $int_0 = utils.$int_0;
var $int_1 = utils.$int_1;
Expand Down Expand Up @@ -252,7 +251,7 @@ SCScript.install(function(sc) {

$i = $.Integer(i);
while (i < raw.length) {
if (BOOL($func.value(raw[i], $i))) {
if ($func.value(raw[i], $i).__bool__()) {
this.takeAt($i);
} else {
$i = $.Integer(++i);
Expand Down Expand Up @@ -432,7 +431,7 @@ SCScript.install(function(sc) {

this._ThrowIfImmutable();

if (BOOL($aCollection.isCollection())) {
if ($aCollection.isCollection().__bool__()) {
$aCollection.do($.Function(function($item) {
$this._.push($this.__elem__($item));
}));
Expand Down Expand Up @@ -765,7 +764,7 @@ SCScript.install(function(sc) {
spec._sort = function($function) {
this._ThrowIfImmutable();
this._.sort(function($a, $b) {
return BOOL($function.value($a, $b)) ? -1 : 1;
return $function.value($a, $b).__bool__() ? -1 : 1;
});
};
});
Expand Down
49 changes: 24 additions & 25 deletions src/sc/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SCScript.install(function(sc) {
var fn = sc.lang.fn;

sc.lang.klass.refine("Collection", function(spec, utils) {
var BOOL = utils.BOOL;
var $nil = utils.$nil;
var $true = utils.$true;
var $false = utils.$false;
Expand Down Expand Up @@ -54,7 +53,7 @@ SCScript.install(function(sc) {
var $obj;
var size, i;

if (BOOL($size.isSequenceableCollection())) {
if ($size.isSequenceableCollection().__bool__()) {
return this.fillND($size, $function);
}

Expand Down Expand Up @@ -158,7 +157,7 @@ SCScript.install(function(sc) {
return $false;
}
this.do($.Function(function($item) {
if (!BOOL($aCollection.includes($item))) {
if (!$aCollection.includes($item).__bool__()) {
$res = $false;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -247,7 +246,7 @@ SCScript.install(function(sc) {
$removedItems = this.class().new();
$copy = this.copy();
$copy.do($.Function(function($item) {
if (BOOL($function.value($item))) {
if ($function.value($item).__bool__()) {
$this.remove($item);
$removedItems = $removedItems.add($item);
}
Expand Down Expand Up @@ -296,7 +295,7 @@ SCScript.install(function(sc) {
var $res = null;

this.do($.Function(function($item2) {
if (BOOL( $item1 ["=="] ($item2) )) {
if ($item1 ["=="] ($item2).__bool__()) {
$res = $true;
return sc.C.LOOP_BREAK;
}
Expand All @@ -309,7 +308,7 @@ SCScript.install(function(sc) {
var $this = this, $res = null;

$aCollection.do($.Function(function($item) {
if (BOOL($this.includes($item))) {
if ($this.includes($item).__bool__()) {
$res = $true;
return sc.C.LOOP_BREAK;
}
Expand All @@ -322,7 +321,7 @@ SCScript.install(function(sc) {
var $this = this, $res = null;

$aCollection.do($.Function(function($item) {
if (!BOOL($this.includes($item))) {
if (!$this.includes($item).__bool__()) {
$res = $false;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -363,7 +362,7 @@ SCScript.install(function(sc) {

$res = $class.new(this.size());
this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $res.add($elem);
}
}));
Expand All @@ -376,7 +375,7 @@ SCScript.install(function(sc) {

$res = $class.new(this.size());
this.do($.Function(function($elem, $i) {
if (!BOOL($function.value($elem, $i))) {
if (!$function.value($elem, $i).__bool__()) {
$res = $res.add($elem);
}
}));
Expand All @@ -388,7 +387,7 @@ SCScript.install(function(sc) {
var $res = null;

this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $elem;
return sc.C.LOOP_BREAK;
}
Expand All @@ -401,7 +400,7 @@ SCScript.install(function(sc) {
var $res = null;

this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $i;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -453,7 +452,7 @@ SCScript.install(function(sc) {
spec.lastForWhich = function($function) {
var $res = null;
this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $elem;
} else {
return sc.C.LOOP_BREAK;
Expand All @@ -466,7 +465,7 @@ SCScript.install(function(sc) {
spec.lastIndexForWhich = function($function) {
var $res = null;
this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $i;
} else {
return sc.C.LOOP_BREAK;
Expand Down Expand Up @@ -503,7 +502,7 @@ SCScript.install(function(sc) {
spec.count = function($function) {
var sum = 0;
this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
sum++;
}
}));
Expand All @@ -515,7 +514,7 @@ SCScript.install(function(sc) {
var sum = 0;

this.do($.Function(function($elem) {
if (BOOL($elem ["=="] ($obj))) {
if ($elem ["=="] ($obj).__bool__()) {
sum++;
}
}));
Expand All @@ -527,7 +526,7 @@ SCScript.install(function(sc) {
var $res = null;

this.do($.Function(function($elem, $i) {
if (BOOL($function.value($elem, $i))) {
if ($function.value($elem, $i).__bool__()) {
$res = $true;
return sc.C.LOOP_BREAK;
}
Expand All @@ -540,7 +539,7 @@ SCScript.install(function(sc) {
var $res = null;

this.do($.Function(function($elem, $i) {
if (!BOOL($function.value($elem, $i))) {
if (!$function.value($elem, $i).__bool__()) {
$res = $false;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -592,7 +591,7 @@ SCScript.install(function(sc) {

$sum = $int_0;
this.do($.Function(function($elem) {
if (BOOL($elem.isSequenceableCollection())) {
if ($elem.isSequenceableCollection().__bool__()) {
$elem = $elem.at($int_0);
}
$sum = $sum ["+"] ($elem.abs());
Expand Down Expand Up @@ -787,7 +786,7 @@ SCScript.install(function(sc) {

this.do($.Function(function($sublist) {
var sz;
if (BOOL($sublist.isCollection())) {
if ($sublist.isCollection().__bool__()) {
sz = $sublist.maxSizeAtDepth($.Integer(rank - 1));
} else {
sz = 1;
Expand All @@ -805,7 +804,7 @@ SCScript.install(function(sc) {

$res = $max;
this.do($.Function(function($elem) {
if (BOOL($elem.isCollection())) {
if ($elem.isCollection().__bool__()) {
$res = $res.max($elem.maxDepth($max.__inc__()));
}
}));
Expand Down Expand Up @@ -853,7 +852,7 @@ SCScript.install(function(sc) {
spec.invert = fn(function($axis) {
var $index;

if (BOOL(this.isEmpty())) {
if (this.isEmpty().__bool__()) {
return this.species().new();
}
if ($axis !== $nil) {
Expand All @@ -870,7 +869,7 @@ SCScript.install(function(sc) {

$result = this.species().new();
this.do($.Function(function($item) {
if (BOOL($that.includes($item))) {
if ($that.includes($item).__bool__()) {
$result = $result.add($item);
}
}));
Expand All @@ -883,7 +882,7 @@ SCScript.install(function(sc) {

$result = this.copy();
$that.do($.Function(function($item) {
if (!BOOL($result.includes($item))) {
if (!$result.includes($item).__bool__()) {
$result = $result.add($item);
}
}));
Expand All @@ -900,12 +899,12 @@ SCScript.install(function(sc) {

$result = this.species().new();
$this.do($.Function(function($item) {
if (!BOOL($that.includes($item))) {
if (!$that.includes($item).__bool__()) {
$result = $result.add($item);
}
}));
$that.do($.Function(function($item) {
if (!BOOL($this.includes($item))) {
if (!$this.includes($item).__bool__()) {
$result = $result.add($item);
}
}));
Expand Down
21 changes: 10 additions & 11 deletions src/sc/classlib/Collections/Dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SCScript.install(function(sc) {
var fn = sc.lang.fn;

sc.lang.klass.refine("Dictionary", function(spec, utils) {
var BOOL = utils.BOOL;
var $nil = utils.$nil;
var $true = utils.$true;
var $false = utils.$false;
Expand Down Expand Up @@ -68,7 +67,7 @@ SCScript.install(function(sc) {
var ret = null;

this.keysValuesDo($.Function(function($k, $v) {
if (BOOL($k.matchItem($key))) {
if ($k.matchItem($key).__bool__()) {
ret = $v;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -211,7 +210,7 @@ SCScript.install(function(sc) {
var $ret = null;

this.do($.Function(function($item2) {
if (BOOL($item1 ["=="] ($item2))) {
if ($item1 ["=="] ($item2).__bool__()) {
$ret = $true;
return sc.C.LOOP_BREAK;
}
Expand Down Expand Up @@ -335,7 +334,7 @@ SCScript.install(function(sc) {

$res = this.class().new(this.size());
this.keysValuesDo($.Function(function($key, $elem) {
if (BOOL($function.value($elem, $key))) {
if ($function.value($elem, $key).__bool__()) {
$res.put($key, $elem);
}
}));
Expand All @@ -348,7 +347,7 @@ SCScript.install(function(sc) {

$res = this.class().new(this.size());
this.keysValuesDo($.Function(function($key, $elem) {
if (!BOOL($function.value($elem, $key))) {
if (!$function.value($elem, $key).__bool__()) {
$res.put($key, $elem);
}
}));
Expand Down Expand Up @@ -377,7 +376,7 @@ SCScript.install(function(sc) {
$myKeys = this.keys();
$otherKeys = $that.keys();

if (BOOL($myKeys ["=="] ($otherKeys))) {
if ($myKeys ["=="] ($otherKeys).__bool__()) {
$commonKeys = $myKeys;
} else {
$commonKeys = $myKeys.sect($otherKeys);
Expand All @@ -387,7 +386,7 @@ SCScript.install(function(sc) {
$res.put($key, $func.value($this.at($key), $that.at($key), $key));
}));

if (BOOL($fill)) {
if ($fill.__bool__()) {
$myKeys.difference($otherKeys).do($.Function(function($key) {
$res.put($key, $this.at($key));
}));
Expand All @@ -405,7 +404,7 @@ SCScript.install(function(sc) {
var $ret = null;

this.keysValuesArrayDo(this._$array, $.Function(function($key, $val) {
if (BOOL($argValue ["=="] ($val))) {
if ($argValue ["=="] ($val).__bool__()) {
$ret = $key;
return sc.C.LOOP_BREAK;
}
Expand All @@ -432,7 +431,7 @@ SCScript.install(function(sc) {
var $array;
var $size, $index;

if (BOOL(this.isEmpty())) {
if (this.isEmpty().__bool__()) {
return $nil;
}

Expand All @@ -449,7 +448,7 @@ SCScript.install(function(sc) {
spec.order = fn(function($func) {
var $assoc;

if (BOOL(this.isEmpty())) {
if (this.isEmpty().__bool__()) {
return $nil;
}

Expand Down Expand Up @@ -517,7 +516,7 @@ SCScript.install(function(sc) {

for (i = 0; i < imax; i += 2) {
$elem = array[i];
if (BOOL($elem ["=="] ($argKey))) {
if ($elem ["=="] ($argKey).__bool__()) {
return $.Integer(i);
}
}
Expand Down
Loading

0 comments on commit 75023d8

Please sign in to comment.