Slices in OpenSCAD
Our first data structure in OpenSCAD is the list, which is similar to slices in other languages. Lists are an important data type in OpenSCAD, giving a powerful interface to sequences of values.
Note that while lists in OpenSCAD are similar to slices in other languages, they have some key differences:
- OpenSCAD lists are immutable. Operations like
concat()
return new lists rather than modifying existing ones. - OpenSCAD doesn’t have built-in functions for comparing lists or finding elements. You often need to write your own functions for these operations.
- OpenSCAD lists are more similar to arrays in other languages, as they don’t have the dynamic resizing capabilities of slices.
To run this code, you would typically save it as a .scad
file and open it with the OpenSCAD application. The echo()
statements will print their output to the console window in the OpenSCAD interface.
Remember that OpenSCAD is primarily used for creating 3D models, so these list operations are often used in the context of generating or manipulating geometric data.