Compiling
crystal build main.cr
will change Settings declaration in main.cr from
class Settings| macro collect_alias_method(method, type) | |
| def {{method}} | |
| res = [] of {{type}} | |
| {{method}} do |e| | |
| res << e | |
| end | |
| res | |
| end | |
| end |
| require 'date' | |
| target = ARGV[1] || "." | |
| files = %x(git grep -n 'TODO*' #{target}) | |
| lines = [] | |
| length_author = 0 | |
| length_file = 0 |
Compiling
crystal build main.cr
will change Settings declaration in main.cr from
class Settings| .crystal |
This intent to show how Ruby practice can be addapted to Crystal. With a total different under the hood implementation, but keeping some of the greatest aspects.
The focus thou is not to stand on how a fsm should be modeled, or defined by a dsl, BUT how some common Ruby practices might be rethinked to take advantage of Crystal.
As an intermediate step, I sometimes like to think in a more plain type/classes design to have a nice compile time experience, but using macros in crystal to reach that from a nice dsl.
NB: There is consideration to name the examples a language way and not the language way .
I hereby claim:
To claim this, I am signing this object:
| {"tables":[{"name":"Trackers","guid":"bb1c463d-b35f-4fb0-a18b-78fab5f25963","kind":"local","fields":[{"name":"Phone","guid":"abf4aca1-502c-43f6-acad-0f88c33340fc","valid_values":""}],"protocol":["query","update","insert"]}],"message_triggers":[{"name":"track","enabled":true,"message":{"from":"+1-(234)-567-8912","pieces":[{"kind":"text","text":"track","guid":"815fa0f2-cfd7-4863-94d8-92fdb1430cdd"}],"pattern":"(?i-mx:\\A\\s*track\\s*\\Z)"},"kind":"message_trigger","actions":[{"kind":"create_entity","table":"bb1c463d-b35f-4fb0-a18b-78fab5f25963","field":"abf4aca1-502c-43f6-acad-0f88c33340fc","pill":{"kind":"placeholder","guid":"phone_number"}},{"kind":"send_message","message":[{"kind":"text","guid":"you are been tracked"}],"recipient":{"kind":"placeholder","guid":"phone_number"}}]},{"name":"all","enabled":true,"message":{"from":"+1-(234)-567-8912","pieces":[{"kind":"text","text":"all","guid":"0e2be89a-85dc-4eaf-b988-38f88ff0c9aa"},{"kind":"placeholder","text":"lorem ipsum","guid":"f02701b4-d99f-446b-aa90-39291f7 |
| #include "anillo.h" | |
| #include "aed2_tests.h" | |
| template<typename T> | |
| string to_s(const Anillo<T>* a) { | |
| ostringstream os; | |
| os << *a; | |
| return os.str(); | |
| } |
| #ifndef AED2_TESTS_ | |
| #define AED2_TESTS_ | |
| #include <iostream> | |
| #include <sstream> | |
| using namespace std; | |
| string mt_bool_to_s(bool b) { return b ? "true" : "false"; } | |
| #define MT_MAKE_ERROR(lhs, rhs, line) { ostringstream os;os << "error en linea " << (line) << endl;os << " se esperaba: " << (rhs) << endl;os << " se obtuvo: " << (lhs);throw os.str(); } | |
| void mt_assert(bool lhs, bool rhs, int line) { if (lhs != rhs) { MT_MAKE_ERROR(mt_bool_to_s(lhs), mt_bool_to_s(rhs), line) } } |
INTRODUCTION TO PROGRAMMING FOR THE VISUAL ARTS WITH P5.JS
Assignment 1: Port an Image to Code