Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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...


You forgot to specify Chunky or Smooth peanut butter!


Ah, I knew I would forget something! Let it be a warning to whoever considers asking a British person to make their P&J sandwiches for them ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: