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 characters
(ql:quickload :optima) | |
(defpackage :monad | |
(:use :common-lisp :optima) | |
(:export :bind :just :none :do-monad)) | |
(in-package :monad) | |
;; return | |
(defgeneric unit-m (type x)) | |
;; >>= |
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 characters
class CFizzBuzz{ | |
public static function main(){ | |
fizzbuzz(); | |
} | |
macro public static function fizzbuzz(){ | |
var fizzbuzzText : String = "\n"; | |
for( i in 1...100 ){ | |
fizzbuzzText += if( i % 15 == 0 ){ | |
"FizzBuzz "; |
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 characters
var Switch = function(expr){ | |
this.successed = false; | |
this.case = function(cond, proc){ | |
if( !this.successed && cond === expr){ | |
this.successed = true; | |
proc(); | |
} | |
return this; | |
} | |
} |
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 characters
function cond(){ | |
for(var i in arguments ){ | |
if( arguments[i][0] ){ | |
arguments[i][1](); | |
break; | |
} | |
} | |
} | |
var x = -1; |
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 characters
var Switch = function(expr){ | |
return new YetSucceed(expr); | |
} | |
var Succeed = { case : function(cond,proc){ return this; } }; | |
var YetSucceed = function(expr){}; | |
YetSucceed.prototype.case = function(cond, proc){ | |
if(cond){ | |
proc(); |
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 characters
var Switch = function(expr){ | |
return new YetSucceed(expr); | |
} | |
var Succeed = { case : function(cond,proc){ return this; } }; | |
var YetSucceed = function(expr){ this.expr = expr; }; | |
YetSucceed.prototype.case = function(cond, proc){ | |
if(cond() === this.expr){ | |
proc(); |
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 characters
(function () | |
{ | |
function partial(fun) | |
{ | |
var _slice = [].slice, | |
args = _slice.call(arguments); | |
args.shift(); | |
return function () | |
{ | |
return fun.apply(this, args.concat(_slice.call(arguments))); |
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 characters
(function (global) | |
{ | |
var expr = function (n) | |
{ | |
var utilities = { | |
"+": function (a) { return function(b){ return a + b; } }, | |
"-": function (a) { return function(b){ return a - b; } }, | |
"*": function (a) { return function(b){ return a * b; } }, | |
"/": function (a) { return function(b){ return a / b; } } |
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 characters
(function (global) | |
{ | |
var expr = function (n) | |
{ | |
var utilities = { | |
"+": function (a, b) { return a + b; }, | |
"-": function (a, b) { return a - b; }, | |
"*": function (a, b) { return a * b; }, | |
"/": function (a, b) { return a / b; } |
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 characters
require "./rpn" | |
describe "rpn" do | |
it "" do | |
expect(expr(4).("+").(3).("*").(2).("-").(1).("=")). | |
to eq(->(){ | |
comp1 = 3 * 2; | |
comp2 = 3 + comp1; | |
comp3 = comp2 - 1; | |
return comp3 }.call) |
OlderNewer