-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for lambdas. #498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
docs/language/blocks-and-lambdas.mdx
Outdated
|
||
``` | ||
## Introduction to Blocks and Lambdas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Introduction to Blocks and Lambdas | |
## Introduction to blocks and lambdas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
[1, 2, 3].do: printer.call it | ||
``` | ||
|
||
## Key Differences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Key Differences | |
## Key differences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
4. **Flexibility**: Lambdas can be stored in variables, fields, and collections, and returned from functions. Blocks cannot. | ||
5. **Efficiency**: Blocks are significantly more efficient than lambdas. | ||
|
||
## Blocks in Detail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Blocks in Detail | |
## Blocks in detail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
|
||
## Blocks in Detail | ||
|
||
### Efficiency of Blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Efficiency of Blocks | |
### Efficiency of blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
|
||
- [Lambdas](../tasks) cannot capture blocks. | ||
## Lambdas in Detail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Lambdas in Detail | |
## Lambdas in detail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
callbacks_.do: it.call new-value | ||
|
||
add-printer box/WatchedBox: | ||
box.watch:: print "Was changed to $it." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
box.watch:: print "Was changed to $it." | |
box.watch:: print "was changed to $it." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would drop the trailing period here (and in the comments). It just seems misplaced and we don't typically have that in debug prints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
This example demonstrates how lambdas can be stored in a list | ||
(`callbacks_`) and called later. | ||
|
||
### Lambda Arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Lambda Arguments | |
### Lambda arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
main: | ||
// Both of these will print 42. | ||
my-function:: print it | ||
my-function: print it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels more logical to start with the block-variant call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/blocks-and-lambdas.mdx
Outdated
- Consider providing both block and lambda versions if you need to support both | ||
use cases. The lambda version can always redirect to the block version: | ||
``` | ||
my-function callback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe flip the order of these two functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
docs/language/index.mdx
Outdated
A block can return a value each time it is run. This is used for example in the `filter` method on lists. | ||
``` | ||
// Returns a function that adds n to its argument. | ||
add-n n: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add-n n: | |
add-n n -> Lambda: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
No description provided.