Domanda

Come accetto il seguente 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)

qualcosa come

(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

MODIFICA: QUESTO NON È IL MIO LAVORO. Sto cercando di scrivere qualcosa come ELIZA da PAIP ma so solo come scrivere uno schema che inizia con una parola.

È stato utile?

Soluzione

Menzioni i caratteri, ma poi usi i numeri nel tuo esempio. Sto usando i numeri qui, ma passare ai personaggi è banale.

(require scheme/match)
(define satisfies
  (match-lambda
    [(list (? number?) ... 3) #t]
    [(list (? number?) ..1 4 (? number?) ...) #t]
    [_ #f]))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top