-
Notifications
You must be signed in to change notification settings - Fork 9
20230110 modern lambda #109
base: base
Are you sure you want to change the base?
Conversation
based on use, a bug fix might be needed. looking at a test case. |
not a bug, added some test cases. |
src/compiler/lambda.rs
Outdated
// M = (mod ((captures) arguments) (body)) | ||
// (list 2 | ||
// (c 1 (mod ((captures) arguments) body)) | ||
// (list 4 (c 1 (@ 2)) (list 4 (c 1 compose_captures) @)) |
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.
the 1
s and 2
s here refer to the quote- and apply- opcodes, right?
if so, it might be easier to understand by using #q
and #a
instead
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.
Admittedly, I find the mixing more confusing, but will change that.
// Test that leaving off the lambda captures causes bare words for the | ||
// requested values to find their way into the output and that having | ||
// the capture catches it. This shows that uses of uncaptured words | ||
// are unencumbered. |
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.
perhaps I misunderstand what this means, but I would hope that the compiler would catch my mistake if I misspell a variable name in the lambda body. having an explicit capture seems like an opportunity for us to be stricter about this
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.
As we discussed earlier, that wasn't a change I felt i could make at this point. Since it's been very contentious I will speed through the changes needed to be fully strict.
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.
This upcoming pr allows us to get to strictness in macro output since it allows precise control of the form the output takes, as well as other improvements.
https://github.com/Chia-Network/clvm_tools_rs/pull/134
It's a precondition for being fully strict.
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.
.to_string(); | ||
let res = run_string(&prog, &"(((2 3) (4 9)))".to_string()).unwrap(); | ||
assert_eq!(res.to_string(), "242"); | ||
} |
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 appreciate these tests. I think it would make sense to have negative tests as well. it's important compilation fails when it should
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's been a bit hard because not much actually is meant to fail in chialisp and I often discover things people want that are questionable or should fail to me, but I will set those bounds as well as I can.
… it to handle the sugared lambda bodyform
…serialized code as having a lambda rather than a mod+ with desugared forms surrounding it.
…that all one branch can contain all needed features
…chialisp we're testing is separate
now that other required features have been merged, the test suite for chia-gaming is now in here as a fairly comprehensive regression test. |
…ood ways to do it before now
Create a new form
Which captures the items in captures from the environment and creates runnable code taking (arguments) as arguments.
In this code:
A runnable (with the 'a' operator) lambda is emitted by the lambda form, which captures add-number from the environment. When run by 'map' with another argument (here filling 'number'), it can use both the captured arguments and the arguments given when it is run.
Run with (5 (1 2 3 4)) gives (6 7 8 9)
You can introduce bindings for capture using let:
Run with (5 (1 2 3 4)) gives (11 12 13 14)