-
20-08-2019 - |
题
我如何接受以下输入?
(list of 0 or more charcters and ends with 3) or
(list of 1 or more characters 4 and 0 or more characters after 4)
像
(match ( list 3)) -> #t
(match ( list 1 2 3)) -> #t
(match (list 1 2 3 4)) -> #t
(match (list 1 2 3 4 5)) -> #t
(match (list 4)) -> #f
编辑:这不是我的家庭作业。我想写从PAIP像伊莉莎,但我只知道如何写一个字开头的模式。
解决方案
您提到的人物,但随后在你的例子使用的号码。我在这里使用的数字,但切换到人物实在是微不足道。
(require scheme/match)
(define satisfies
(match-lambda
[(list (? number?) ... 3) #t]
[(list (? number?) ..1 4 (? number?) ...) #t]
[_ #f]))
不隶属于 StackOverflow