(define-struct binding
(
let ; a string
num ; a number
)
)
(define Bind-A (make-binding empty 1))
(define Bind-B (make-binding "A" 2))
(define Bind-C (make-binding "F" 1))
(define Bind-D (make-binding "A" 1))
(define Bind-E (make-binding "C" 1))
(define Bind-F (make-binding "E" 3))
(define Bind-All (list Bind-A Bind-B Bind-C Bind-D Bind-E Bind-F))
J'ai donc une structure pour quelque chose que j'appellerai "binding" et une liste qui contient toutes les "bindings" que j'ai créés. Maintenant, pour la question: disons que je voulais créer une liste qui contenait la lettre dans chaque liaison qui a le même numéro que j'appelle une fonction avec. Par exemple:Aide de schéma. Structs Lists and Recursion
;;-----------------------------------------------------------------------------
;; Return a string containing the letters (in alphabetical order, separated by a
;; space) of all bindings with the same number in pool of "bindings".
;; If either letter is unknown or if no bindings have the same number
;; Return the null string ("").
;;-----------------------------------------------------------------------------
(define (same-num ; string
which-binding) ; binding to check
pool ; list of all bindings
)
(cond
[(empty? (binding-let which-binding)) ""]
[(equal? (binding-let which-binding) (binding-let (first pool)) ... ]
[else ... ]
)
)
(check-expect (same-num Bind-E Bind-all) "A F")
(check-expect (same-num Bind-F Bind-all) "")
(check-expect (same-num Bind-A Bind-all) "")
J'espère que cela a du sens comme je l'ai expliqué .. Je l'ai eu du mal avec cela pendant des heures et je me sens comme il est vraiment simple, je ne comprends pas la langue assez.
Scheme a également le type de données "character" qui est notée comme # \ a, # \ b, # \ c et ainsi de suite. (list-string '(# \ a # \ b # \ c)) donne "abc". – erjiang