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 about doing so?

(define (name n) (cond [(< (string-length nom) 10) 25])) 

n not defined

1

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 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like