Skip to content

Instantly share code, notes, and snippets.

@happy-barney
Last active September 27, 2022 06:12
Show Gist options
  • Save happy-barney/8daa827fb641e674643bdaeb803296f2 to your computer and use it in GitHub Desktop.
Save happy-barney/8daa827fb641e674643bdaeb803296f2 to your computer and use it in GitHub Desktop.

new internal value not_exists

Abstract

Introduce new internal SV value PL_sv_not_exists acting like PL_sv_undef in most cases (in every case when feature is not enabled).

PL_sv_not_exists will be used when value is not initialized yet.

  • when key lookup doesn't exist (without autovivification)
  • when optional parameter is not provided
  • when variable is not initialized

Motivation

  • to be able to distinguish between uninitialized value and value initialized to undef
  • hash slices - to be able to distinguish between "key didn't exist in master hash" vs. "key set to undef in master hash"
  • to prevent autovivification (overlaps with RFC-0021 but optional chaining is implicit)
  • leads to: Data::Path-like extension capable to set value to not_exist-ing lookup (with necessary autovivification)

Intended behaviour

Some overview of changes in language (lot of boring details omitted)

  • new feature not-exists
  • new internal constant SV PL_sv_not_exists will be treated like PL_sv_undef except of PL_sv_not_exists specific behaviour
  • every dereference of not_exists will result into not_exists
  • new postfix operator ?
    • returning not_exists for undef, not_exists, builtin::false
  • new postfix operator !
    • returning undef when argument is not_exists
  • exists
    • will accept also scalar (holding not_exists value)
  • delete
    • will accept also scalar
    • will set value to not_exists

Related

Affected RFCs

  • RFC-0021 - optional chaining this pre-RFC wraps intended usage of optional chaining completely with small difference, instead of single operator ?-> there will two operators ? ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment