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



From: Jorgen `forcer' Schaefer <forcer@mindless.com>

>"Marisha Ray & Neil Jerram" <mpriz@dircon.co.uk> writes:
>
>> From: Jorgen `forcer' Schaefer <forcer@mindless.com>
>> >If in the tcl world someone says
>> >   double "100"
>> >then foo can quite plausibly return 200, but the tcl reader for
>> >Guile has no idea that double wants a number not a string.
>> >
>> >Has anyone any thoughts about this?
>>
>> Yes.  I don't understand why the Guile/tcl reader needs to know that
double
>> expects a number.  It is double that needs to know this: its
implementation
>> should convert its argument to a number.  As far as the reader is
concerned,
>> it looks like a string, so it should be read as a string.
>>
>> But I suspect I may have misunderstood how you envisage the
implementation
>> of Tcl procedures like double.
>
>[...]
>
>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.

Hang on a moment!  Perhaps we don't need to add this method at all.  Simply
use reflection on inet-ntoa to find out what methods it has, and then
perform appropriate type conversions on the arguments before passing them to
inet-ntoa.  But this relies on being able to use reflection on all Guile
procedures, whereas currently (in the non-integrated GOOPS) I think it only
works on generics.

Can anyone say what reflection will apply to in the GOOPS-integrated Guile?
Will all procedures become generic?

    Neil



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