Wie kann ich mit Scheme eine Variable ausgeben?

...komplette Frage anzeigen

2 Antworten

BTW das ist der gesamte Code.. noch nicht fertig.. Noch ein paar unnötige strings und so ich weiss

 (display "Type help! to view options") ;Popup at the beginning

(define (help!) (display 1.HUD)) ;Shows string 1.HUD

(define 1.HUD (string-append
"Possible Procedures are:" "\n" "\n"
"1. RPSLS, game" "\n" "\n"
"To find out more about a procedure, type its name and /? at the end")) ;The string for help

(define DrawStr1 (string-append "Hey, I have"))
(define DrawStr2 (string-append "too! Draw!"))
(define HumWinStr1 (string-append "I got"))
(define HumWinStr2 (string-append "You win!"))
(define MacWinStr1 (string-append "I got"))
(define MacWinStr2 (string-append "I win!"))

(define (RPSLS y) ; 0 is rock, 1 is paper, 2 is scissors, 3 is lizzard, 4 is spock

(let ((x 1))
(cond ((member? y '(Spock spock Sp SPOCK sp SP 4)) (set! x 4))
((member? y '(Scissors scissors Sc SCISSORS sc SC 2)) (set! x 2))
((member? y '(Rock rock Ro ROCK ro RO 0)) (set! x 0))
((member? y '(Paper paper Pa PAPER pa PA 1)) (set! x 1))
((member? y '(Lizard lizard LIZARD li LI 3)) (set! x 3)) ;This creates the option of different inputs and translates them into a number which is easier to compare later on
((member? y '(help help? / ? /? HELP Help)) (set! x 5)) ; This accesses the help HUD
(else (set! x 55))) ;should not occur but if it does, it will say something was wrong

(let ((numba 0))
(set! numba (random 5))
(let ((numasword
(if (equal? numba 0) 'rock
(if (equal? numba 1) 'paper
(if (equal? numba 2) 'scissors
(if (equal? numba 3) 'lizard
(if (equal? numba 4) 'spock 'Huh?))))))) ; This translates the sign the computer generated back into english
(let (
(machinewin (se HumWinStr1 (word numasword ".") HumWinStr2)) ;output when machine wins
(humanwin (se MacWinStr1 (word numasword ".") MacWinStr2))) ; output when human wins

(cond

((= numba x) (display (se DrawStr1 numasword DrawStr2)))

((and (= numba 0) (= x 2)) machinewin) ;Machine: Rock Human: Scissors
((and (= numba 0) (= x 3)) machinewin) ;Machine: Rock Human: Lizard
((and (= numba 1) (= x 0)) machinewin) ;Machine: Paper Human: Rock
((and (= numba 1) (= x 4)) machinewin) ;Machine: Paper Human: Spock
((and (= numba 2) (= x 1)) machinewin) ;Machine: Scissors Human: Paper
((and (= numba 2) (= x 3)) machinewin) ;Machine: Scissors Human: Lizard
((and (= numba 3) (= x 1)) machinewin) ;Machine: Lizard Human: Paper
((and (= numba 3) (= x 4)) machinewin) ;Machine: Lizard Human: Spock
((and (= numba 4) (= x 0)) machinewin) ;Machine: Spock Human: Rock
((and (= numba 4) (= x 2)) machinewin) ;Machine: Spock Human: Scissors

(else

(cond

((and (= numba 2) (= x 0)) humanwin) ;Machine: Rock Human: Scissors
((and (= numba 3) (= x 0)) humanwin) ;Machine: Rock Human: Lizard
((and (= numba 0) (= x 1)) humanwin) ;Machine: Paper Human: Rock
((and (= numba 4) (= x 1)) humanwin) ;Machine: Paper Human: Spock
((and (= numba 1) (= x 2)) humanwin) ;Machine: Scissors Human: Paper
((and (= numba 3) (= x 2)) humanwin) ;Machine: Scissors Human: Lizard
((and (= numba 1) (= x 3)) humanwin) ;Machine: Lizard Human: Paper
((and (= numba 4) (= x 3)) humanwin) ;Machine: Lizard Human: Spock
((and (= numba 0) (= x 4)) humanwin) ;Machine: Spock Human: Rock
((and (= numba 2) (= x 4)) humanwin) ;Machine: Spock Human: Scissors
((= x 5)

(display "This is Rock Paper Scissors Lizard Spock.
Rock beats Scissors and Lizard,
Paper beats Rock and Spock,
Scissors beat Paper and Lizard,
Lizard beats Paper and Spock and
Spock beats Rock and Scissors.
Just try it out!"))

(else (se 'an 'error (word 'occured ".") 'You 'might 'check 'the (word 'input ".") 'Sorry 'for 'the 'inconvenience)))))))))) ; if anything fails it wil output this line

Mit string-append kannst du Strings konkatenieren:

(define s "hello")
(display (string-append s " world" "!"))

PS.: Bitte konzentriere dich mehr auf gute Rechtschreibung, dann ist es auch nicht mehr ganz so kompliziert.

Was möchtest Du wissen?