String & list concatenation
This commit is contained in:
parent
c44a6858ff
commit
d81318333e
2 changed files with 17 additions and 2 deletions
|
|
@ -188,8 +188,21 @@ function evaluateBuiltIn(op: string, left: Value, right: Value): Value {
|
|||
return evaluate(right.body, callEnv);
|
||||
}
|
||||
|
||||
if (op === '&')
|
||||
throw new Error('TODO Not implemented yet');
|
||||
if (op === '&') {
|
||||
if (left.kind == 'list' && right.kind === 'list') {
|
||||
return {
|
||||
kind: 'list',
|
||||
elements: [...left.elements, ...right.elements]
|
||||
};
|
||||
}
|
||||
|
||||
if (left.kind == 'string' && right.kind === 'string') {
|
||||
return {
|
||||
kind: 'string',
|
||||
value: left.value + right.value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Unknown built-in: ${op}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,3 +19,5 @@ e('c = 5; { a = 3, b = c }');
|
|||
e('rec = { a = 3, b = 5 }; rec.a');
|
||||
e('rec = { a = 3, b = 5 }; rec{ a = 10 }');
|
||||
e('add1 = (x \\ x + 1); 3 > add1');
|
||||
e('[1, 2] & [3, 4]');
|
||||
e('"abc" & "def"');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue