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
#!/usr/bin/env perl | |
use Marpa::R2; | |
use warnings; | |
use strict; | |
my $basic_math_grammar = | |
Marpa::R2::Scanless::G->new({ | |
action_object => 'BasicMath', | |
default_action => '::first', | |
source => \(<<'END_OF_RULES'), |
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
(define (return v) (lambda (s ks kf) (ks v s))) | |
(define fail (lambda (s ks kf) (kf))) | |
; >>= | |
(define (bind a f) | |
(lambda (s ks kf) | |
(a s | |
(lambda (av s1) ((f av) s1 ks kf)) | |
kf))) |
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
;; outlet: https://github.com/jlongster/outlet | |
(define-macro (case c . variants) | |
`(cond | |
,@(map (lambda (exp) | |
(if (== (car exp) 'else) | |
exp | |
`((list-find ',(car exp) ,c) | |
,@(cdr exp)))) | |
variants))) |
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
;default | |
(define (fact lst) | |
(if (null? (cdr lst)) | |
(car lst) | |
(begin | |
(print lst) | |
(* (car lst) (fact (cdr lst)))))) | |
;CPS | |
(define (fact/cps lst cont) | |
(cond |
NewerOlder