From f939aef691c579acc92e64cd01a12c8eb0ed5984 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Thu, 3 Aug 2017 11:48:01 -0700 Subject: [PATCH] more better lambda example --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8368a85..1272657 100755 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Different projects have led to the architecture of PLASMA, most notably Apple Pa - [Assignment](#assignment) - [Empty Assignments](#empty-assignments) - [Increment and Decrement](#increment-and-decrement) - - [Lambda Functions](#lambda-functions) + - [Lambda (Anonymous) Functions](#lambda-functions) - [Control Flow](#control-flow) - [CALL](#call) - [RETURN](#return) @@ -477,7 +477,7 @@ end def keyin(x, y, key) if key == '+' - eval(x, y, &(x, y) x + y) + eval_op(x, y, &(x, y) x + y) fin end ```` @@ -1037,11 +1037,11 @@ puti(i) // print 4 ### Lambda Functions -A Lambda function is a simple, anonymous function that can be passed to a function or assigned to a variable. It is called as a function pointer. The function can take a number of parameters and return a value based on the parameters and global values. By enclosing the expression of the lambda function in paranthesis, multiple values can be returned. +A Lambda function is a simple, anonymous function that can be passed to a function or assigned to a variable. It is called as a function pointer. The function can take a number of parameters and return a value based on the parameters and/or global values. By enclosing the expression of the lambda function in paranthesis, multiple values can be returned. ``` -def whatop(a, b, op) +def what_op(a, b, op) puti(a) puts(" ? ") puti(b) @@ -1057,10 +1057,10 @@ def lambdas lambda1 = &(a, b) a + b lambda2 = &(a, b) (a + b, a - b) - x = lambda1(1, 2)#1 // This will return 3 - x, y = lambda2(3, 4)#2 // This will return 7, -1 - whatop(10, 20, &(a, b) a * b) // This will print 10 ? 20 = 200 - return &(x, y, z) x * z / y // You can even return lambdas from definitions + x = lambda1(1, 2) // This will return 3 + x, y = lambda2(3, 4)#2 // This will return 7, -1 (the #2 denotes two returned values instead of the default of one) + what_op(10, 20, &(a, b) a * b) // This will print 10 ? 20 = 200 + return &(x, y, z) x * z / y // You can even return lambdas from definitions (these x, y are different from the locally defined x, y) end ````