That's the imperative programming case. Declarative programming is about defining each part of the final result.
What's a peanut butter and jelly and sandwich (the result)? It's a slice of bread atop a layer of peanut butter atop a layer of jelly atop a slice of bread. Recursively define each part, for instance defining a layer of jelly in terms of manipulated blobs of jelly. Reverse the order of the definitions if using an early-binding language.
(setq p&j-sandwich '(bread-slice peanut-butter-layer jelly-layer bread-slice))
;; TODO work out why jelly layer isn't transferred to sandwich in one piece
(setq bread-slice (with-tool bread-knife (slice bread-loaf)))
(setq jelly-layer (with-tool table-knife (spread jelly-blob)))
...
Disclaimer: I've never eaten nor made a P&J sandwich; please consider this code experimental...
What's a peanut butter and jelly and sandwich (the result)? It's a slice of bread atop a layer of peanut butter atop a layer of jelly atop a slice of bread. Recursively define each part, for instance defining a layer of jelly in terms of manipulated blobs of jelly. Reverse the order of the definitions if using an early-binding language.
Disclaimer: I've never eaten nor made a P&J sandwich; please consider this code experimental...