Why does a DesignScript inline conditional expression behave differently from the If node?

I have 2 input curves and create a polycurve. Then I’m asking via design script: “was the original input for the polycurve only one curve, or more?”. In the case of 1, I want the original curve, in the case of 2 or more, I want the polycurve. Why on earth does DesignScript give me 2(!) polycurves as a result??

nuts.dyn (27.5 KB)

1 Like

Long answer:
The DesignScript expression works differently than the If node. What you’re expecting from the DS expression is the output from the If node which will be the single PolyCurve as shown:

The difference is that the DS expression replicates over all three inputs whereas the If node will only replicate over the test input.
For the code block node (DS expression), since the true condition is a list (of 2 lines), whereas the false is only a single value (1 polycurve), by default, longest lacing is happening so the polycurve output is being repeated twice. In order to enforce shortest lacing, you can use replication guides as shown:

However, it is recommended to use the If node if what the user just expects is the true input or the false input to be returned as-is.
Or if you still prefer using DesignScript, you could also do the “if” check in an imperative block like this, in which case there is no replication happening at all: