You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fantasy-docs.md
+28-4Lines changed: 28 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ Two or more Solid2ds can be:
78
78
79
79
_Solid3ds_ can be simple shapes like spheres and cubes, or a combination of them (a sphere on top of a cube).
80
80
81
-
Previously every type we've examined has had geometric properties, like length or height. But Solid3d is different, because it also has a _material_. Materials (for example, aluminium or plastic) let KCL analyze your model and report back important data like its weight or tensile strength. We'll discuss materials more below.
81
+
Every type we've previously examined had geometric properties, like length or height. But Solid3d is different, because it also has a _material_. Materials (for example, aluminium or plastic) let KittyCAD analyze your model and report important data like its weight or tensile strength. We'll discuss materials more below.
82
82
83
83
Create a Solid3d by:
84
84
- Extruding a 2D shape into the third dimension (along a straight line, or any path)
@@ -249,7 +249,7 @@ A KCL program is made up of _functions_. A function has a name, parameters, and
249
249
/// A can for our line of *awesome* new [baked beans](https://example.com/beans).
But we generally find the `|>` operator makes your KCL functions easier to read.
@@ -272,7 +272,7 @@ In this example function, we specified the types of both input parameters and th
272
272
```kcl
273
273
can_of_beans = (radius, height) =>
274
274
circle(radius)
275
-
|> extrude_closed(material.aluminium, height)
275
+
|> extrude_closed(height)
276
276
```
277
277
278
278
Here, the KCL compiler:
@@ -370,6 +370,30 @@ doubleAllDistances = (distances: List Distance -> List Distance) =>
370
370
List.map((x: Distance -> Distance) => x * 2, distances)
371
371
```
372
372
373
+
#### Keyword arguments
374
+
375
+
All the functions you saw previously had a list of required arguments. Users will look at the function definition, read every parameter from first to last, and pass in the right values as arguments.
376
+
377
+
These are called _positional_ or _required_ arguments. But KCL also supports _keyword_ arguments. Like this:
378
+
379
+
```kcl
380
+
sphere = (radius: Distance, material: Material = Aluminium.ISO5052) => ...
381
+
```
382
+
383
+
Here, the `material` parameter is a _keyword parameter_. It's optional, so if the caller doesn't provide it, it takes a default value, in this case the `Aluminium.ISO5052` alloy from the KCL standard library.
384
+
385
+
You pass keyword arguments like this:
386
+
387
+
```kcl
388
+
/// Using a keyword argument.
389
+
sphere(Distance::metre(1), material = Plastic.ISO1234)
390
+
391
+
/// Or, don't use a keyword argument and rely on the default.
392
+
sphere(Distance::metre(1))
393
+
```
394
+
395
+
Keyword arguments help keep your KCL programs readable, and allows us to add new features to the standard library in a backwards-compatible way. Suppose that KittyCAD releases KCL 1.4, which adds a new positional argument to a standard library function `sphere`. Any programs using the definition of `sphere` from KCL 1.3 would stop compiling when you upgrade to 1.4 (because they're missing a parameter to `sphere`). But if we add the new parameter as a _keyword parameter_, your existing programs will keep working -- they'll just use the default value for that parameter.
396
+
373
397
### KCL files
374
398
375
399
KCL files are just a collection of KCL functions (including constants).
0 commit comments