Understanding Pass by Name with Examples
To better understand pass by name lets consider an example in python programming language;
Python
def swap(a, b): temp = a a = b b = temp def main(): x = 5 y = 10 swap(x, y) print ( "After swapping, x =" , x) print ( "After swapping, y =" , y) main() |
Output
('After swapping, x =', 5)
('After swapping, y =', 10)
In this code we’re showcasing the concept of Pass by Name in Python. The swap function has two parameters, a and b. When the swap(x, y) is invoked within the function it directly replaces the values of x and y in the swap function body without evaluating them.
Pass By Name in Compiler Design
Compiler design is a captivating field that plays a role, in transforming high-level programming languages into machine code enabling computers to perform tasks. One concept that often stands out in compiler design is the idea of “pass by the name“. We will explore the details of pass-by names, define terms, and provide insights into their significance in compiler design.