Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which paradigm do the Raku concepts role and adverb come from?

Tags:

raku

Upon reading certain documents, I have noticed that they use classes, functions, symbols, methods, things that even I, as an electronics engineer, know about. Then, they have concepts which I have never heard of, such as roles, and adverbs. If I don't understand the nomenclature, I can't understand well the documents, and might be getting very unexpected results, and not utilize well the language as well.

I could not find their definition anywhere, including as tags in StackOverflow....Any pointers would be appreciated.

like image 821
user1134991 Avatar asked Jan 19 '18 16:01

user1134991


People also ask

Is Raku a dynamically typed language?

Because Raku has such capable type inference, it is possible to write it just as you’d write a dynamically typed language. But Raku has a powerful type system and allows you to constrain the types your functions accept. For example, in the current code, we have the function sub fuel ($mass) { +$mass div 3 - 2 }.

What is a paradigm?

The collection of beliefs and concepts is what is known as a paradigm, which is a set of theories, assumptions, and ideas that contribute to your worldview or create the framework from which you operate every day.

What are the Raku advent calendar and advent of code?

Now that it’s December, it’s time for two of my favorite traditions from the tech world: the Raku Advent Calendar and Advent of Code. These two holiday traditions have a fair amount in common – they both run from December 1 through Christmas, and both involve releasing something new every day during the event.

Is there a private leaderboard for the Raku community?

I’ve also registered a private leaderboard for the Raku community, which you can access by logging in, following that link and then entering the code 407451-52d64a27 (if necessary, I can change that code and distribute it more securely, but I don’t anticipate any issues).


2 Answers

which paradigm do the concepts role and adverb come from?

roles

Roles are an OO concept.

They are Raku's generalization and unification of the notion of OO interface protocols, mixins, and traits.

Quoting the Characteristics section of the Trait page:

For inter-object communication, traits are somewhere between an object-oriented protocol (interface) and a mixin. An interface may define one or more behaviors via method signatures, while a trait defines behaviors via full method definitions: i.e., it includes the body of the methods. In contrast, mixins include full method definitions and may also carry state through member variable, while traits usually don't.

Raku's roles cover all three of the above, er, roles, plus some additional capabilities to extend classes, or other roles, or objects, with:

  • Interfaces that enforce compliance relative to either just method name level or full signature; AND/OR

  • Mixins that inject state via attributes (member variables), methods, or role scoped lexical variables; AND/OR

  • Traits that inject partial or full method definitions.

Roles can also act as classes themselves in the sense that instantiating one will work via type punning.

adverbs

Adverbs in Raku are:

  • Directly analogous to adverbs in natural languages like English.

  • Named parameters/arguments that are used to modify a routine's behaviour rather than serving as input per se.

Adverbs are frequently specified using ordinary key/value pair syntax but, in a manner analogous to adverbs in natural languages, can appear in a diverse range of convenient syntactic and semantic forms, eg:

m:i / foo /

The :i is the "ignoring case" adverb (set to True) being passed to the match (m) routine. Note how this is not input in the same way that the foo is, or $_ which is implicitly used as the string being matched against, but instead just modifies how the matching process does what it does.

Using a pair argument to modify a routine's behaviour like this is what justifies calling :i an "adverb" for the m routine.

like image 122
raiph Avatar answered Sep 21 '22 14:09

raiph


maybe the glossary on the perl 6 documentation site helps:

https://docs.perl6.org/language/glossary

Also, there's a documentation section on roles specifically: https://docs.perl6.org/language/objects#Roles

like image 39
timotimo Avatar answered Sep 21 '22 14:09

timotimo