views:

326

answers:

2

How do I accept the following input?

(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)

something like

(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

EDIT: THIS IS NOT MY HOMEWORK. I trying to write something like ELIZA from PAIP but I know only how to write a pattern that begins with a word.

A: 

Maybe this can help you.

Dario
Could you please summarize the link for us? See this: http://stackoverflow.com/questions/518828/should-stackoverflow-be-self-contained
musicfreak
+2  A: 

You mention characters, but then use numbers in your example. I'm using numbers here, but switching to characters is trivial.

(require scheme/match)
(define satisfies
  (match-lambda
    [(list (? number?) ... 3) #t]
    [(list (? number?) ..1 4 (? number?) ...) #t]
    [_ #f]))
Jay Kominek