Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: RFC: Is there more to alias? (cases)

by tye (Sage)
on Aug 24, 2004 at 22:37 UTC ( [id://385534]=note: print w/replies, xml ) Need Help??


in reply to RFC: Is there more to alias?

Say I have an object, $heap. And say I want to store some really whopping huge strings in this heap. But $heap was not written to know about aliases and I don't want to add the overhead of putting references into the heap and telling it to use a dereferencing comparison function.

Is there much chance that I could use:

alias $heap->Push( $dna );

to acheive a heap of aliases? My understanding of your description says "no". Would it make sense to be able to copy an opcode tree and transform the copy like:

my $heapPush= aliasize $heap->can("Push"); $heapPush->( $heap, $dna );

(noting that routines called by $heapPush would still remain unaffected, perhaps unfortunately)

How would you go about retrofitting a module to support storing aliases instead of copies?

On a related note, compare these two bits of code:

my @x; sub swap { my( $i, $j )= @_; alias @x[$i,$j]= @x[$j,$i]; } sub exchange { my( $i, $j )= @_; alias do { my $t= $x[$i]; $x[$i]= $x[$j]; $x[$j]= $t; }; }

Do these cases work?

swap( 0, 1 ); exchange( 0, 1 ); swap( 0, 0 );

I expect I could work that out for myself but I don't want to expend the effort and I thought you might appreciate the opportunity. (:

BTW, smashing great idea for a module.

- tye        

Replies are listed 'Best First'.
Re^2: RFC: Is there more to alias? (cases)
by xmath (Hermit) on Aug 24, 2004 at 22:56 UTC

    Ehh, hmmm, alias-ifying someone else's code? I can already smell the sulphurous fumes of the dragons that await you down that road. Most likely you'd manage to break something by doing that, and even if it miraculously works, it could very well break when the module is updated. I've just examined some Heap module to imagine what would happen.. at the very least all subs that operate on the heap (directly or indirectly) would need to be aliasified to have any chance of working correctly. I really wouldn't go down this road.

    So, this also answers simply how to retrofit a module to store aliases: always use aliasing internally, and make a copy at the API boundary when aliasing is not desired.

    Your swap and exchange are both fine and functionally equivalent, the cases you suggest work. Note that you can omit the 'do' in exchange, since alias BLOCK is valid syntax.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found