Last active
August 29, 2015 14:02
Revisions
-
spamwax revised this gist
Jun 10, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Solution to eloquentjavascript exercise second 2nd edition // Chapter 8 // http://eloquentjavascript.net/2nd_edition/preview/08_error.html // Retry function MultiplicatorUnitFailure() {} -
spamwax revised this gist
Jun 4, 2014 . 1 changed file with 37 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,4 +39,40 @@ function reliableMultiply2(a, b) { console.log(reliableMultiply1(8, 8)); console.log(reliableMultiply1(6, 6)); // --------------------------------------- // The locked box function withBoxUnlocked(body) { box.unlock(); try { body(); } catch (e) { // do nothing } finally { box.lock(); } } // Bonus function withBoxUnlocked(body) { var state = box.locked; box.unlock(); try { body(); } catch (e) { // do nothing } finally { if (state) { box.lock(); } } } withBoxUnlocked(function() { box.content.push("gold piece"); }); withBoxUnlocked(function() { throw new Error("Pirates on the horizon! Abort!"); }); console.log(box.locked); // → true -
spamwax revised this gist
Jun 4, 2014 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ // Solution to eloquentjavascript exercise second 2nd edition // Chapter 6 // http://eloquentjavascript.net/2nd_edition/preview/08_error.html // Retry function MultiplicatorUnitFailure() {} function primitiveMultiply(a, b) { @@ -33,4 +37,6 @@ function reliableMultiply2(a, b) { } console.log(reliableMultiply1(8, 8)); console.log(reliableMultiply1(6, 6)); // --------------------------------------- // -
spamwax created this gist
Jun 4, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ function MultiplicatorUnitFailure() {} function primitiveMultiply(a, b) { if (Math.random() < 0.5) return a * b; else throw new MultiplicatorUnitFailure(); } function reliableMultiply1(a, b) { try { return primitiveMultiply(a, b); } catch (e) { if (e instanceof MultiplicatorUnitFailure) { return reliableMultiply(a, b); } else { throw e; } } } function reliableMultiply2(a, b) { for (;;) { try { return primitiveMultiply(a, b); } catch (e) { if (e instanceof MultiplicatorUnitFailure) { continue; } else throw e; } } } console.log(reliableMultiply1(8, 8)); console.log(reliableMultiply1(6, 6));