Ticket #816 (new bug)

Opened 13 years ago

Last modified 12 years ago

PMC 'Undef' does not support logical_not

Reported by: Austin_Hastings Owned by:
Priority: normal Milestone:
Component: core Version: 1.3.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

This code in Close:

   ok(!(o.flat()), "flat: New object (undef flat) is false");

compiles to:

    $P51 = o."flat"()
    not $P52, $P51
    "ok"($P52, "flat: New object (undef flat) is false")

And then fails, with:

logical_not() not implemented in class 'Undef'

Grepping for logical_not in *.pmc gives back only scalar.pmc.

  • While I know that Perl's Undef has 0/nil/false/"" behavior, is that right for Parrot? (To what extent is Undef just a safe Null?)

  • Should there even be a 'not' opcode? We've got isfalse.
  • Should other pmc types be implementing logical_not?
  • Should Undef be a subclass of scalar, and so inherit?

Change History

in reply to: ↑ description   Changed 12 years ago by bacek

Replying to Austin_Hastings:

This code in Close: {{{ ok(!(o.flat()), "flat: New object (undef flat) is false"); }}} compiles to: {{{ $P51 = o."flat"() not $P52, $P51 "ok"($P52, "flat: New object (undef flat) is false") }}} And then fails, with: {{{ logical_not() not implemented in class 'Undef' }}}

Undef.logical_not was implemented in r41259.

Grepping for logical_not in *.pmc gives back only scalar.pmc. * While I know that Perl's Undef has 0/nil/false/"" behavior, is that right for Parrot? (To what extent is Undef just a safe Null?)

No. Undef is not "safe Null". Undef is something declared but not defined. Null is undeclared at all.

* Should there even be a 'not' opcode? We've got isfalse.

Some weird languages can have semantic of "Foo == !Foo" :)

* Should other pmc types be implementing logical_not?

Not all of them. But all scalar types probably should.

* Should Undef be a subclass of scalar, and so inherit?

It's actually really good idea from my point of view. I would recommend to open "RFC ticket" with this proposal.

-- Bacek

Note: See TracTickets for help on using tickets.