mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
Make variable assignment convert streams to full values
This commit is contained in:
parent
cdbd333c9b
commit
4ce9a5c894
3 changed files with 34 additions and 0 deletions
3
TODO.md
3
TODO.md
|
@ -14,12 +14,15 @@
|
||||||
- [x] parsing tables
|
- [x] parsing tables
|
||||||
- [x] Block params
|
- [x] Block params
|
||||||
- [x] Ranges
|
- [x] Ranges
|
||||||
|
- [ ] Iteration (`each`) over tables
|
||||||
|
- [ ] ctrl-c support
|
||||||
- [ ] Column path
|
- [ ] Column path
|
||||||
- [ ] ...rest without calling it rest
|
- [ ] ...rest without calling it rest
|
||||||
- [ ] operator overflow
|
- [ ] operator overflow
|
||||||
- [ ] finish operator type-checking
|
- [ ] finish operator type-checking
|
||||||
- [ ] Source
|
- [ ] Source
|
||||||
- [ ] Autoenv
|
- [ ] Autoenv
|
||||||
|
- [ ] Externals
|
||||||
- [ ] let [first, rest] = [1, 2, 3]
|
- [ ] let [first, rest] = [1, 2, 3]
|
||||||
|
|
||||||
## Maybe:
|
## Maybe:
|
||||||
|
|
|
@ -22,6 +22,29 @@ impl EvaluationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_var(&self, var_id: VarId, value: Value) {
|
pub fn add_var(&self, var_id: VarId, value: Value) {
|
||||||
|
// We need to make values concreate before we assign them to variables, as stream values
|
||||||
|
// will drain and remain drained.
|
||||||
|
//
|
||||||
|
// TODO: find a good home for this
|
||||||
|
// TODO: add ctrl-c support
|
||||||
|
|
||||||
|
let value = match value {
|
||||||
|
Value::RowStream {
|
||||||
|
headers,
|
||||||
|
stream,
|
||||||
|
span,
|
||||||
|
} => Value::Table {
|
||||||
|
headers,
|
||||||
|
val: stream.collect(),
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
Value::ValueStream { stream, span } => Value::List {
|
||||||
|
val: stream.collect(),
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
x => x,
|
||||||
|
};
|
||||||
|
|
||||||
self.stack.add_var(var_id, value);
|
self.stack.add_var(var_id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,3 +228,11 @@ fn range_iteration2() -> TestResult {
|
||||||
fn simple_value_iteration() -> TestResult {
|
fn simple_value_iteration() -> TestResult {
|
||||||
run_test("4 | each { $it + 10 }", "14")
|
run_test("4 | each { $it + 10 }", "14")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn concrete_variable_assignment() -> TestResult {
|
||||||
|
run_test(
|
||||||
|
"let x = (1..100 | each { |y| $y + 100 }); $x | length; $x | length",
|
||||||
|
"100",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue