const func = (() => {
let result; // cache
return () => {
if (result === undefined) {
result = someComputation();
}
return result;
}
})();
You could write it without the immediately invoked arrow funciton or a do expression if `result` is in the same scope as `func` let result;
const func = () => {
if (result === undefined) {
result = someComputation();
}
return result;
}
Result is in the same scope as func, inviting anyone to read from or write to it. const value = do {
switch (someString) {
case 'Monday':
0;
break;
case 'Tuesday':
1;
break;
...
}
}
const other = do {
if (isPrime(n)) {
'prime'
} else if (isOdd(n)) {
'odd'
} else {
'even'
}
}
Scad needs unit tests. It would be powerful to asset that a profile doesn't have slope greater than 45°, that intersection of two objects is null, or specific volume.
It also needs cut away views. I got okay results using boxes to remove everything except a sliver, to view a slice and internal details. But without hash marks, texture, or outlines it can be hard to tell the forms.