1. # A Slip is a kind of List that is immediately incorporated into an iteration
  2. # or another List. Other than that, it's a totally normal List.
  3. my class Slip { # is List
  4. multi method Slip(Slip:D:) { self }
  5. method defined () { self.so }
  6. method CALL-ME (+args) { args.Slip }
  7. multi method perl(Slip:D:) {
  8. nqp::if(
  9. nqp::eqaddr(self,Empty),
  10. 'Empty',
  11. nqp::stmts(
  12. (my str $guts = callsame),
  13. nqp::if(
  14. nqp::eqat($guts,'$',0), # we're itemized
  15. nqp::concat('$(slip',nqp::concat(nqp::substr($guts,1),')')),
  16. nqp::concat('slip',$guts)
  17. )
  18. )
  19. )
  20. }
  21. multi method List(Slip:D:) {
  22. nqp::stmts(
  23. (my $list := nqp::create(List)),
  24. nqp::if(
  25. nqp::getattr(self,List,'$!todo').DEFINITE,
  26. nqp::bindattr($list,List,'$!todo',
  27. nqp::getattr(self,List,'$!todo'))
  28. ),
  29. nqp::if(
  30. nqp::getattr(self,List,'$!reified').DEFINITE,
  31. nqp::bindattr($list,List,'$!reified',
  32. nqp::getattr(self,List,'$!reified'))
  33. ),
  34. $list
  35. )
  36. }
  37. }
  38. # The slip(...) function creates a Slip.
  39. proto slip(|) { * }
  40. multi slip() { Empty }
  41. multi slip(@args) { @args.Slip }
  42. multi slip(+args) { args.Slip }