Back to General

Operations on Lists (Iterators & Amend) · General · Practice Question

Replace Nulls with a Constant Value

Sign in to track your progress

Question

Given:

l:1 0n 20 21 0n 30 33 34 0n

Replace all null values with the value 100.0.

Expected result:

1 100 20 21 100 30 33 34 100f

Solution

100.0^l

Explanation

^ is the Fill operator — x^y returns y with every null replaced by the corresponding item of x. When x is a single atom rather than a list, that one value is used to fill every null in y, however many there are.

This is the simplest member of the fill-and-replace family of questions in this section — compare it with the forward-fill and backward-fill questions in the Over and Amend sections, which replace nulls with a neighbouring value instead of a fixed constant.