This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Auto type conversion in target languages


"Marisha Ray & Neil Jerram" <mpriz@dircon.co.uk> wrote:
>>Better example: the inet-ntoa procedure of Guile (or any other
>>guile procedure that doesn't want a string)
>>In tcl you just want to be able to write
>> inet-ntoa "388639255"
>>because Tcl doesn't differenciate between numbers and strings -
>>they're converted as needed. For that above to work, the Tcl
>>reader needs to know that inet-ntoa wants a number and not a
>>string. Currently it requires the Tcl user to predeclare this in
>>the source file, which i think isn't the best solution.
>>
>>Thus i was asking wether anyone has any thoughts about how to
>>improve this situation :)
>
>
>I see - thanks for explaining.  Instead of explicit predeclaration, 
>we could make inet-ntoa a generic function and give it a method that
>takes a string:
>
>(define-method inet-ntoa ((s <string>))
>   (inet-ntoa (string->number s)))
>
>Is that an improvement?  You might still consider this a form of
>predeclaration, but at least it is using a mechanism that is 
>soon-to-be core Guile, rather than a roll-your-own type declaration
>system.

The problem is that this new inet-ntoa isn't proper Scheme.  Scheme is a
type-aware language, Tcl isn't.  Making Scheme type-neutral isn't a good
compromise, nor is it necessary.  Tcl isn't core Guile (and, obviously,
never will be), so the means to accomidate Tcl's type system don't need
to be core Guile.

The basic information you need to deal with type-system
incompatibilities between Tcl and Scheme is only the default types of
the arguments of the Scheme procedure.  In the code I wrote this
information is used to create a wrapper-function, but I suppose other
things are possible.  The code you wrote is just another possible way of
using this information.  The basic information is "inet-ntoa takes a
number as its first argument".  Once this information is given for all
Scheme procedures then the problem is mostly solved.  Short of this I
don't see any good solution.

Including type-information in the documentation is a potential way to
make all of this transparent to the end-user/programmer and encourage
universality.

  -- Ian

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]