| Nice. I like this more for a functional idiom: case foo of
TUESDAY => "Taco Tuesday"
| _ => "Not Taco Tuesday"
Or this: (cond (= foo TUESDAY)
("Taco Tuesday")
("Not Taco Tuesday"))
All programs, at heart, are imperativeYes, but only because the underlying machine architecture is imperative, right? If you had a chip that could evaluate pure functions with no mutable state (like a Lisp Machine that used a purely functional dialect of Lisp) then you could have programs with no underlying imperativeness. But in a perhaps more relevant sense, in languages like Haskell or Prolog it is possible to write a program with no imperative state manipulation happening at the programmer's working level of abstraction. Still, this really has nothing to do with determinism. Also, I like SQL as an example of declarative programming. SELECT * FROM USERS
WHERE JOIN_DATE = "20150106"
That is a declarative program; the SQL engine it's run on decides the underlying imperative implementation of the solution at runtime. It is also deterministic in that when it's run on the same database containing the same data multiple times it will return the same result.From what I know about Prolog, I understand it's similar in this regard. |
An actual declarative language would choose TUESDAY over _ because it's the most specific match, and not because it matched it first.