more
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#lang racket
|
||||
|
||||
|
||||
|
||||
(define-syntax let*
|
||||
(syntax-rules () ;; special tokens
|
||||
[(let* () body ...)
|
||||
(let () body ...)]
|
||||
[(let* ((x v) (xs vs) ...) body ...)
|
||||
(let ((x v)) (let* ((xs vs) ...) body ...))]))
|
||||
|
||||
|
||||
|
||||
(let* [(x 5)
|
||||
(y (+ x 2))]
|
||||
y)
|
||||
;; ->
|
||||
(let ((x 5))
|
||||
(let* ((y (+ x 2)))
|
||||
y))
|
||||
;; ->
|
||||
(let ((x 5))
|
||||
(let ((y (+ x 2)))
|
||||
(let* ()
|
||||
y)))
|
||||
;; ->
|
||||
(let ((x 5))
|
||||
(let ((y (+ x 2)))
|
||||
(let ()
|
||||
y)))
|
||||
|
||||
(define-syntax annd
|
||||
(syntax-rules ()
|
||||
[(annd) #t]
|
||||
[(annd x) (if x x #f)]
|
||||
[(annd x y ...) (if x (annd y ...) #f)]))
|
||||
|
||||
(annd #f (/ 5 0))
|
||||
(and 5 2 3)
|
||||
(annd 5 2 3)
|
||||
@@ -0,0 +1,30 @@
|
||||
#lang pl
|
||||
|
||||
(define-type Token = (U Symbol Integer))
|
||||
|
||||
(: in? : Symbol (Listof Symbol) -> Boolean)
|
||||
(define (in? s l) (and (not (null? l)) (not (and (not (symbol=? s (first l))) (not (in? s (rest l)))))))
|
||||
|
||||
(test (in? 'a '(b d e a f e)))
|
||||
(test (in? 'a '(b x e a x e)))
|
||||
(test (in? 'a '(a b d e a f e)))
|
||||
(test (in? 'a '(b d e a f e a)))
|
||||
(test (not (in? 'a '(b d e f e))))
|
||||
(test (not (in? 'a '())))
|
||||
|
||||
#|
|
||||
(: abc : String -> Boolean)
|
||||
; Identifies strings that match "(ab(c+))+"
|
||||
(define abc (automaton one (four)
|
||||
[one : (a -> two)]
|
||||
[two : (b -> three)]
|
||||
[three : (c -> four)]
|
||||
[four : (c -> four) (a -> two)]))
|
||||
|
||||
(test (abc "abccc"))
|
||||
(test (abc "abcccabc"))
|
||||
(test (not (abc "ab")))
|
||||
(test (not (abc "q")))
|
||||
(test (not (abc "abcb")))
|
||||
(test (not (abc "abcab")))
|
||||
|#
|
||||
Reference in New Issue
Block a user