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
void main() { | |
// Functor | |
num plus3(num x) => x + 3; | |
print(Just(2).fmap(plus3)); // Just 5 | |
print(Nothing<num>().fmap(plus3)); | |
print([1,2,3].map((x) => x + 2)); // (3, 4, 5) | |
final foo = fmap((x) => x + 3, (x) => x + 2); |
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
Future<void> main() async { | |
// final program = '(define x 42)'; | |
final program = '(begin (define circle-area (lambda (r) (* pi (* r r)))) (circle-area 10))'; | |
print(parse(program)); | |
} | |
dynamic parse(String program) => parseTokens(tokenize(program)); | |
List<String> tokenize(String program) => program | |
.replaceAll('(', ' ( ') |
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
import 'dart:math' as math; | |
Future<void> main() async { | |
final program = '(begin (define circle-area (lambda (r) (* pi (* r r)))) (circle-area 10))'; | |
print(eval(parse(program), standardEnv)); | |
} | |
dynamic parse(String program) => parseTokens(tokenize(program)); | |
List<String> tokenize(String program) => program |
OlderNewer