Newsgroups: perl.perl6.internals Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stanford.edu!nntp.perl.org Return-Path: Mailing-List: contact perl6-internals-h...@perl.org; run by ezmlm Delivered-To: mailing list perl6-intern...@perl.org Delivered-To: perl6-intern...@perl.org X-Scanned-By: AMaViS-ng at sidhe.org Mime-Version: 1.0 X-Sender: dan@localhost Message-ID: In-Reply-To: <20031202200415.GA6856@bumblebury.com> References: <20031202200415.GA6856@bumblebury.com> Date: Mon, 8 Dec 2003 09:37:41 -0500 To: Sterling Hughes , perl6-intern...@perl.org Subject: Re: get_pmc_keyed() in PerlString? Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Spam-Check-By: one.develooper.com X-Spam-Status: No, hits=-0.2 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,REFERENCES,SPAM_PHRASE_00_01 version=2.44 X-SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/ Approved: n...@nntp.perl.org From: d...@sidhe.org (Dan Sugalski) Lines: 49 At 9:04 PM +0100 12/2/03, Sterling Hughes wrote: >Hey, > >I'm right now looking at getting a proper implementation of array/string >offsets done for the PHP compiler. > >Here's the problem, in PHP you can access indices of both string's an >array's in the same way, meaning: [Snip PHP treating strings as character arrays] >To have this available easily using Perl's types, get_pmc_keyed() would >need to be implemented in the PerlString PMC. Currently (for the sake >of nice looking mandelbrot demos), we just assume is a native string and >do the offset from that string (which parrot/imc does support.) > >Should PerlString support a get_pmc_keyed() method (according to Perl >5/6 semantics), or is this a point where its about time to start implementing >our own PMCs? This... could be a problem. Perl, using a perl string as an array, should treat it as a symbolic reference if that's enabled. And, strictly speaking, if PHP is handed a PerlInteger it ought to treat it the same way as a PerlString. Or not, but it'd be reasonable as they're really facets of the same base type. I can see a number of solutions here, some of which involve compiler hackery. The thing that first springs to mind is to have the PHP compiler emit a check of some sort before use, and either do array access or substring access. That's got a certain appeal to it, as it means we don't have to do anything. :) (Well, not true--we have to provide sufficient easily queryable metadata to tell if a variable is more or less an array, or a string, but we ought to so that anyway) If that's not a reasonable option, and I can see it not being so, that makes things somewhat more interesting. Definitely calls for at least one custom PMC for PHP, and potentially an automatic wrapping function to throw a PHPStringWrapper (or whatever) around anything stringlike that comes back from an 'external' function call. That requires a bit more work on parrot's part, though, and, while I'd like to do this at some point (for JVM and .NET native library wrapping) I hadn't intended to do it yet, for lack of time and need. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai d...@sidhe.org have teddy bears and even teddy bears get drunk