Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Why does Perl have typeglobs? (sigils)

by tye (Sage)
on Jul 09, 2014 at 03:11 UTC ( #1092834=note: print w/replies, xml ) Need Help??


in reply to Why does Perl have typeglobs?

Perl has typeglobs because Perl has sigils. A typeglob would make no sense in a language where you write:

string s; array a; hash h;

But a typeglob makes sense in a language where you can say:

our( $stuff, @stuff, %stuff ); open *stuff, ...; &stuff(); write stuff;

Looking in the symbol table under the single name "stuff", you might find 6 different things. What's an obvious way to implement that?

- tye        

Replies are listed 'Best First'.
Re^2: Why does Perl have typeglobs? (sigils)
by LanX (Archbishop) on Jul 10, 2014 at 00:34 UTC
    You don't need typeglobs to handle sigils, lexical pads work without the "hash of slot" structure of STASHes.

    (well at least does padwalker not return such a structure, variables are in the hash with sigil as part of the name)

    Cheers Rolf

    (addicted to the Perl Programming Language)

      Where did you read the word "need"?

      If you want to use Perl's PADs as part of an argument against how symbol tables were implemented, then you probably should learn more about Perl's PADs first. Perl's PADs don't support looking things up by name so they'd really suck as an implementation of a symbol table. That's why that module has "walker" in its name. Plus PADs only support about half of the slot types of a typeglob.

      The obvious two choices are 1) a hash by name where each value has N slots for N types of things; 2) N hashes. If you have a complete set of sigils, then the third obvious choice is 3) a hash by "$sigil.$name" (where the values are of various types) but that might not be the best choice in C (and we don't have a complete set of sigils).

      The choice of typeglobs is more obvious in older features of Perl where "open FOO" then "write FOO" will use $FOO as the name of the file to open, *FOO as the handle to open, and FOO as the format to write. Even more slots of *ARGV are used together.

      - tye        

        > 3) a hash by "$sigil.$name" (where the values are of various types)

        which is what padwalker returns in a hash.

        > but that might not be the best choice in C (and we don't have a complete set of sigils).

        I wasn't sure about the pad (thats why I said "at least").

        Actually pads are organized more or less like AoA with the first sub-array holding the Sigil+Name keys for each "column". (recursive functions have a row for each recursion, reference Panther book)

        But I don't see why changing the first AV with the "sigiled" keys to a HV with indexes to the value AVs shouldt be a problem in C.

        > Where did you read the word "need"?

        Implicitly. It's an interpretation of how you replied.

        You may have meant it differently, but others may not, hence the correction.

        Cheers Rolf

        (addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2019-08-26 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?