'How can i append string to list?

I am trying to completing a school assignment where i have to write a function which takes two arguments where the first condition is the length of the list is greater than 4 which is working,however,the problems begins with appending the a variable "s" to the list.for e,g

(define SOB (λ ( s L1)

                (cond
                ((string? s)
                ((list? L1) (> 4)

                            (append  s L1))))))

this is my code i have been trying to find ways to do this but i keep getting errors.this is input test

(SOB "hi" '(1 2 3 4 5 6))

and this is the error i receive

append: contract violation
  expected: list?
  given: "hi"

i am new to racket and i would really appreciate some help with this



Solution 1:[1]

The correct function is cons, not append. append is for concatenating multiple lists, but s is not a list.

You also need to combine all your conditions with and.

(define SOB (? ( s L1)
  (cond
    ((and (string? s) (list? L1) (> (length L1) 4))
     (cons s L1))))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar