You need to test if an object is a string.
The
string? predicate is what you want:
500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)
Notice that a character is not a string. Also, even though we've said that a string is a list of characters, a list of characters is not a string.
(Hence the utility of the conversion function
list->string. --
MarcCharpentier - 07 Dec 2004 )
--
GordonWeakliem - 05 Apr 2004
The Python Cookbook discusses how simply asking
isinstance is "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?
500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)
--
GordonWeakliem - 05 Apr 2004
Scheme definitely doesn't have built-in duck typing, by design, but of course you can implement it, using e.g. generic functions. I suspect the Python idea of not asking
isinstance also 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