You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
907 B
Racket
28 lines
907 B
Racket
#lang br/quicklang
|
|
(require sugar/list)
|
|
|
|
(define (read-syntax path port)
|
|
(define triads (slice-at (map string-split (string-split (port->string port) "\n")) 3))
|
|
(define new-triples
|
|
(slice-at (flatten (for/list ([triad (in-list triads)])
|
|
(apply map list triad))) 3))
|
|
(strip-bindings
|
|
#`(module mod "lang-b.rkt"
|
|
#,@(for*/list ([triple (in-list new-triples)])
|
|
`(triangle ,@triple)))))
|
|
(provide read-syntax)
|
|
|
|
(define-macro (mb . TRIANGLES)
|
|
#'(#%module-begin
|
|
(length (filter valid-triangle? (list . TRIANGLES)))))
|
|
(provide (rename-out [mb #%module-begin]))
|
|
|
|
(define-macro (triangle A B C)
|
|
#'(map string->number (list A B C)))
|
|
(provide triangle)
|
|
|
|
(define (valid-triangle? triangle)
|
|
(match-define (list a b c) triangle)
|
|
(and (> (+ a b) c)
|
|
(> (+ b c) a)
|
|
(> (+ a c) b))) |