Guest User

Raku – Introspection methods (draft)

a guest
Oct 28th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. General:
  2. .Str, .gist, .raku
  3.  
  4. Reserved method names (classes can't define them themselves), cf. https://docs.raku.org/language/typesystem#Reserved_method_names :
  5. WHAT -
  6. WHO -
  7. HOW - ~manner of implementation
  8. VAR
  9.  
  10. Methods of the class Mu (classes can re-define them):
  11. WHY - Documentation
  12. WHERE - Memory address, probably
  13. WHICH -
  14.  
  15. VAR
  16. .VAR.WHAT or .VAR.^name: Type of the container: Scalar, Array, etc.
  17. .^name
  18. .^type (sometimes)
  19. .^attributes
  20. .^parents
  21. .^methods
  22. .^mro ("method resolution order")
  23. .^roles
  24.  
  25. .keys # esp. for modules: Foo::Bar::.keys
  26.  
  27.  
  28. For classes and their instances:
  29. Classes: .^parents .^parents(:all) .^roles .^methods .^mro .^attributes .^api
  30. Instances: .^parents .^parents(:all) .^roles .^methods .^mro .^attributes
  31. Methods: [see Routines. Furthermore, specifically for methods: ...]
  32.  
  33. Routines: .name .signature .candidates
  34.  
  35.  
  36.  
  37. say (
  38. .name
  39. .package
  40. .has_accessor
  41. .^type
  42. ) for C.^attributes; # or C.new.^attributes
  43.  
  44. To test if a given type object is a class:
  45. class C {}; say C.HOW ~~ Metamodel::ClassHOW;
  46.  
  47. # https://docs.raku.org/language/typesystem#Type_system
  48. class C:ver<4.2.3>:auth<github:jane>:api<1> {}
  49. say C.^ver; # OUTPUT: «v4.2.3␤»
  50. say C.^ver.parts; # OUTPUT: «(4 2 3)␤»
  51. say C.^auth; # OUTPUT: «github:jane␤»
  52. say C.^api; # OUTPUT: «1␤»
  53.  
  54.  
  55.  
  56.  
  57. Seq (Lists, Arrays...)
  58.  
  59.  
  60. Hash
  61.  
  62.  
  63.  
  64. <What I've skipped so far: >
  65. enum (/language/typesystem)
Advertisement
Add Comment
Please, Sign In to add comment