string?predicate is what you want:
> (string? "foo") #t > (string? #\f) #f > (string? (list #\f #\o #\o)) #f
isinstanceis "UnPythonic" and has a discussion on "duck typing", in that their solution just asks if you can concatenate a string to an unknown object. I'm not sure how to address this. You could literally ask if
(string-append an-object "")works w/o throwing an exception, but would anyone do this?
(define (is-string? s) (with-handlers ((not-break-exn? (lambda (exn) #f))) (let ((s2 (string-append s ""))) #t)))
isintancealso comes in part from general OO principles, where most things should be done with polymorphic method calls, and you shouldn't have to ask what type something is, most of the time. None of this applies to standard Scheme. However, with an object system, like PLT's classes or Swindle's CLOS implementation, then things like this are possible. For example, with Swindle, you could define string-append as a generic function that worked on all the basic Scheme types, which would give you duck typing in that case. I'm not sure offhand whether Swindle has anything like this built-in. -- AntonVanStraaten - 07 Apr 2004