KCL: Keyword function calls for stdlib (#4647)

Part of https://github.com/KittyCAD/modeling-app/issues/4600

Adds support for keyword arguments to the stdlib, and calling stdlib functions with keyword arguments.

So far, I've changed one function: `rem`. Previously you would have used `rem(7, 2)` but now it's `rem(7, divisor: 2)`.

This is a proof-of-concept. If it's approved, we will:

1. Support closures with keyword arguments, and calling them
2. Move the rest of the stdlib to use kw arguments
This commit is contained in:
Adam Chalmers
2024-12-05 14:27:51 -06:00
committed by GitHub
parent 7a21918223
commit 6366bc4766
21 changed files with 1030 additions and 374 deletions

View File

@ -108,6 +108,10 @@ impl crate::docs::StdLibFn for Show {
vec![]
}
fn keyword_arguments(&self) -> bool {
false
}
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
let mut settings = schemars::gen::SchemaSettings::openapi3();
settings.inline_subschemas = inline_subschemas;
@ -117,6 +121,7 @@ impl crate::docs::StdLibFn for Show {
type_: "[number]".to_string(),
schema: generator.root_schema_for::<[f64; 2usize]>(),
required: true,
label_required: true,
}]
}
@ -130,6 +135,7 @@ impl crate::docs::StdLibFn for Show {
type_: "number".to_string(),
schema,
required: true,
label_required: true,
})
}