Root-relative namespace keys

Andrew Whitworth wknight8111 at gmail.com
Fri Jan 16 15:29:26 UTC 2009


I thought I had sent out a reply to this post a little while back, but
looking through the archives it doesn't look like I actually did
(which would explain the complete lack of responses!)

On Tue, Jan 6, 2009 at 11:44 PM, Allison Randal <allison at parrot.org> wrote:
> What if we reuse the parsing for that method call syntax to create a
> Hash (or Capture)? And make it legal anywhere a PMC argument is legal?
> So, that pseudocode above becomes the actual code:
>
>   $P0 = newclass ('hll'=>'lang', 'namespace'=>'my', 'name'=>'foo')
>
> Or, just creating a Hash:
>
>   $P0 = new 'Hash', ('foo' => 1, 'bar' => 2)
>
> Or maybe even:
>
>   $P0 = ('foo' => 1, 'bar' => 2)
>
> I used parens for the parallel with method calls, but the contexts are
> different enough that it may be a bad parallel. It could equally well
> use '|...|' or some other bracketing characters. I would avoid '[...]'
> for the sake of confusion, it does something completely different. But,
> it's important to be consistent on the syntax inside for "named lists",
> that is, key/value pairs.

What if, instead of reusing parens for this we use the as-yet-unused
curly brackets? Also, now might be a great time to consider the use of
general-purpose PMC literals, instead of a special case that only
allows hashes? Using prefix modifiers like we do for strings to
specify the PMC type, it would look something like this:

  FixedIntegerArray:{0, 2, 3, 4}
  Array:{"a", "b", "cde"}
  Hash:{"first", 0, "second", 1"}
  Integer:{5}

Alternatively, we could use postfix adverb syntax:

  {0, 2, 3, 4} :array('ResizableIntegerArray')
  {1, 5, 6} :array
  {"first", 1, "second", 2} :hash
  {"first", 1, "second", 2} :hash("OrderedHash")
  {1} :scalar("Integer")
  {"hello"} :scalar("String")

This would give us a nice and flexible way to specify PMC constants
that could be extended to cover most basic PMC types (Integer, Float,
String, anything that "provides array" or "provides hash") and it's a
syntax that wouldn;t be too hackish or too special-purpose.

--Andrew Whitwort


More information about the parrot-dev mailing list