Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Raku (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Macros=== In low-level languages, the concept of [[Macro (computer science)|macros]] has become synonymous with textual substitution of source-code due to the widespread use of the [[C preprocessor]]. However, high-level languages such as [[Lisp programming language|Lisp]] pre-dated C in their use of macros that were far more powerful.<ref>{{cite book | title=Successful Lisp: How to Understand and Use Common Lisp | author=Lamkins, David B. | date=2004-12-08 | publisher=bookfix.com | url=http://psg.com/~dlamkins/sl/chapter20.html | access-date=13 September 2006 | archive-date=12 September 2006 | archive-url=https://web.archive.org/web/20060912113327/http://www.psg.com/~dlamkins/sl/chapter20.html | url-status=dead }}</ref> It is this Lisp-like macro concept that Raku will take advantage of.<ref name="syn6"/> The power of this sort of macro stems from the fact that it operates on the program as a high-level [[data structure]], rather than as simple text, and has the full capabilities of the programming language at its disposal. A Raku macro definition will look like a subroutine or method definition, and it can operate on unparsed strings, an [[Abstract syntax tree|AST]] representing pre-parsed code, or a combination of the two. A macro definition would look like this:<ref name="macros">{{Cite web|url=https://github.com/Raku/old-design-docs|title=Raku/old-design-docs|date=10 September 2024|via=GitHub}}</ref> <syntaxhighlight lang="raku"> macro hello($what) { quasi { say "Hello { {{{$what}}} }" }; } </syntaxhighlight> In this particular example, the macro is no more complex than a C-style textual substitution, but because parsing of the macro parameter occurs before the macro operates on the calling code, diagnostic messages would be far more informative. However, because the body of a macro is executed at [[compile time]] each time it is used, many techniques of [[Optimization (computer science)|optimization]] can be employed. It is even possible to eliminate complex computations from resulting programs by performing the work at compile-time.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)