Scheme symbols are normally case-insensitive. Thus the symbols Maya and maya are identical:
(eqv? 'Maya 'maya)
;Value: #t
;We can now use the symbol Maya as a global variable by using the form "define"
(define Maya 10)
;Value: maya
Maya
;Value: 10
maya
;Value: 10
;You see it again - not case-sensitive!
;Changing the value of a global variable is very easy. We use set! for the modification.
(set! maya 12)
;Value: 10
Maya
;Value: 12
maya
;Value: 12
;Working with strings. Simply a string is nothing but a combination of atoms.
(define setofatoms "Hello")
;Value: setofatoms
setofatoms
;Value 11: "Hello"
;Accessing the atoms of a given string
(string-ref setofatoms 0)
;Value: #\H
(string-ref setofatoms 1)
;Value: #\e
;Predicate for checking stringness:
(string? setofatoms)
;Value: #t
;But whow long is a given string. The answer give us:
(string-length setofatoms)
;Value: 5
; A function for splitting a given string
(define (splittmyatom mystring i)
(if (< i (string-length mystring))
(begin
(display "; #")
(display i)
(display ": ")
(display (string-ref mystring i))
(newline)
(splittmyatom mystring (+ i 1))
)
#t))
;Value: splittmyatom
(splittmyatom "Hallo" 0)
; #0: H
; #1: a
; #2: l
; #3: l
; #4: o
;Value: #t
; Appending new strings
(string-append "H" "A" "LLo")
;Value 13: "HALLo"
; Mod a string
(define mystring "Hallo")
;Value: mystring
mystring
;Value 14: "Hallo"
(string-set! mystring 1 #\e)
;Unspecified return value
mystring
;Value 14: "Hello"
; Et voilà: Hallo changed to hello.25. März 2019 | mit scheme | scheme | lisp | old data
Startseite | Impressum | Datenschutz