Creates a new list or appends to an existing one if not null.
If dest is null this function creates a new list with element x and returns it. Otherwise, it appends x to dest and returns the mutated list.