W liście z pią, 13-08-2004, godz. 17:26 +0200, Tels napisał:
> > Is there a relatively easy way to handle various BigInt representations > > as well? > > "use Math::BigInt;" and "use Math::BigFloat;" (as well as "use Math::BigInt > lib => 'GMP';"). This is from the point of view of a Perl user. But I'm making a bridge between my pet language Kogut and Perl, and I don't think that I should impose using a particular bigint library, especially if it makes all Perl arithmetic slower. This bridge is harder than the Kogut<->Python bridge I made earlier. For Python I could convert various simple types automatically in both directions (numbers, strings, booleans), despite differences in Unicode handling between languages. For Perl I can convert numbers and strings when passing from Kogut to Perl, but not in the other direction, for two reasons: - It's impossible to distinguish whether a Perl code meant a number 5 or a string "5". - Perl Strings are mutable, so converting them by value would lose their identity in cases it's important. Not only that, but a Perl subroutine can be called in scalar, list, or void context. This implies it can't be directly wrapped in a Kogut function which is just applied to arguments, because there is no place to pass the context. So I have separate functions for invoking Perl subroutines, depending on what is expected from them: CallPerlVoid CallPerlScalar CallPerlList CallPerlNumber \ CallPerlInt \ CallPerlFloat \ convenience wrappers over CallPerlScalar CallPerlString / CallPerlBool / CallPerlUnwrap / and analogously for methods. Arguments of various common types are converted automatically, but the result must be converted explicitly. I must rename these functions to something shorter... The case I asked about is needed for CallPerlNumber, or generally for converting a Perl scalar to a Kogut number if we don't know what kind of number to expect. Dually, when exposing a Kogut function to Perl, its arguments are not converted automatically - they are just wrapped Perl scalars - but the result can be converted, thanks to a richer type system on this side. A Kogut list is converted to a list of results, and other types are converted to single Perl scalars. -- __("< Marcin Kowalczyk \__/ [EMAIL PROTECTED] ^^ http://qrnik.knm.org.pl/~qrczak/