我如何接受以下输入?

(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]))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top