Skip to content

Instantly share code, notes, and snippets.

@panicz
panicz / recursive-descent-parser.scm
Created April 21, 2017 09:10
Generator parserów
(use-modules (grand scheme)) ;; https://github.com/plande/grand-scheme
(define ((in? l) x)
(match l
((h . t)
(or (eq? x h)
((in? t) x)))
(_
#f)))
(define (passing-arguments arguments names final)
(assert (= (length arguments) (length names)))
(match arguments
(()
(assert (null? names))
final)
((argument . next)
(let (((name . names) names))
(if (compound? argument)
(passing-arguments next names
@panicz
panicz / srq1.scm
Created August 31, 2018 21:31
Quiz solution from Dercz
(use-modules (grand scheme))
(define (all-the-same? xs)
(match xs
[(x x) #t]
[(x x . xs*) (all-the-same? `(,x . ,xs*))]
[_ #f]))
(e.g. (all-the-same? '(1 1 1)))
(e.g. (not (all-the-same? '(1 1 2))))
(define old-lisp-program "
DEFINE ((
(THEOREM (LAMBDA (S) (TH1 NIL NIL (CADR S) (CADDR S))))
(TH1 (LAMBDA (A1 A2 A C) (COND ((NULL A)
(TH2 A1 A2 NIL NIL C)) (T
(OR (MEMBER (CAR A) C) (COND ((ATOM (CAR A))
(TH1 (COND ((MEMBER (CAR A) A1) A1)
(T (CONS (CAR A) A1))) A2 (CDR A) C))
(T (TH1 A1 (COND ((MEMBER (CAR A) A2) A2)