This file contains hidden or 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
| def make_recur(&def_block) | |
| delegate = proc { |*args| | |
| user_proc = def_block.call(delegate) | |
| user_proc.call(*args) | |
| } | |
| end | |
| p make_recur { |myproc| | |
| proc { |n| | |
| (n == 1) ? 1 : n * myproc.call(n-1) |
This file contains hidden or 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
| p (fac = proc { |n| (n == 1) ? 1 : n * fac.call(n-1) }).call(5) | |
| # OUTPUT: 120 |
This file contains hidden or 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
| #include <iostream> | |
| #include <functional> | |
| using namespace std; | |
| int main() | |
| { | |
| function<int(int)> fac = [&] (int n) | |
| { | |
| if (n == 1) |
This file contains hidden or 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
| #include <iostream> | |
| int main() | |
| { | |
| std::cout << someConst << std::endl; | |
| } | |
| const int someConst = 10; |
This file contains hidden or 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
| def main | |
| p SomeConst | |
| end | |
| SomeConst = 10 | |
| main |
This file contains hidden or 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
| static class Program | |
| { | |
| static void Main() | |
| { | |
| System.Console.WriteLine(someConst); | |
| } | |
| const int someConst = 10; | |
| } |
This file contains hidden or 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
| #include <functional> | |
| #include <vector> | |
| #include <string> | |
| #include <iostream> | |
| #include <cassert> | |
| using namespace std; | |
| vector<string> split(const string& sep, const string& in); | |
| string join(const string& sep, const vector<string>& in); |
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| # This is the Card class. | |
| # An instance of it has a suit and value. | |
| class Card | |
| attr_reader :suit, :number | |
| # Card numbers. | |
| NUM_ACE = 14 | |
| NUM_JACK = 11 | |
| NUM_QUEEN = 12 |
This file contains hidden or 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 Object | |
| def is_either?(*ary) | |
| ary.include? self | |
| end | |
| end | |
| value = :a | |
| if value.is_either? :a, :b, :c | |
| puts true |
This file contains hidden or 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
| #include <iostream> | |
| #include <functional> | |
| using namespace std; | |
| class Object | |
| { | |
| friend int main(); | |
| public: | |
| Object(string data) : _data(data) {} |