I want to get two strings as arguments, and check if the first string is the beginning of the second string. I cannot get that since I don't know how to get strings as arguments to my function.
(define starts-with( lambda (prefix str)
(define str2 (string->list (str)))
(define prefix2 (string->list (prefix)))
( cond ( (= (string-length(prefix2) 0) display "#t")
( (= car(prefix2) car(str2)) (starts-with (cdr(prefix2)cdr(str2) ) ) )
( display "#f")))))
Error: application: not a procedure; expected a procedure that can be
applied to arguments
given: "ab" arguments...: [none]
Can anyone explain me what is my mistake, and in general how scheme works with lists or strings.. ? I want to have:
(starts-with "baz" "bazinga!") ;; "#t"
The problem is not how to pass strings as arguments, the problem is... that you have to understand how Scheme works in the first place. The parentheses are in all the wrong places, some are missing, some are unnecessary, and the way you're invoking procedures is incorrect. There are so many mistakes in your code that a complete rewrite is needed:
Be aware of the following errors in your original implementation:
let
for it - it's just syntactic sugar for a recursive procedure, not really a loopdisplay
the values you intend to return, just return them=
for comparing chars, the correct way is to usechar=?
orequal?
, which is more generalcond
should be anelse
(f x)
and not like this:f(x)
. Also, you can't put()
around something unless you intend to call it as a function, that's why this:(str)
was producing the errorapplication: not a procedure; expected a procedure that can be applied to arguments