How Do I Compare Numbers and Strings in Racket
If I Wanted My String That I Entered to Be Less Than a Certain Number for Example 10. If It Is Less Than 10 I Would Assign It the Value 25. How Would I Go...
If i wanted my string that I entered to be less than a certain number for example 10. If it is less than 10 i would assign it the value 25. How would I go about doing so?
(define (name n)
(cond
[(< (string-length nom) 10) 25]))
n not defined
1 Answer
You're looking for set! (for "assignment") in conjunction with when (for the condition).
#lang racket
(define (name i)
(when (<= (string-length i) 10)
(set! i 10))
(displayln i))
(name "sustainability")
; => sustainability
(name "diversity")
; => 10