- Joined
- Jun 18, 2007
- Messages
- 65,869
- Likes received
- 32,666
- Thanks received
- 10,047
- Location
- Your local branch
What if I need to loop through that data you've shown on top and then inside the loop do some other look ups in some other arrays in order to calculate what I need...
The second highlighted bit of your post ("inside the loop") begs the question raised by the first ("What if I need to loop through that data"), and the first begs the fundamental question. (Note to knee-jerk pedants: I am in fact using "beg the question" correctly here.)
Why do you assume that the only way to process a set of data is by "looping through" it? Such an assumption betrays your inability - or refusal - to understand the nature of declarative programming. "Looping" is an implementation issue; one should merely need to state "For every member of the set S, apply the function F" (that's why it's called a "statement"). If the function F needs to consult the set T ("do some other look ups") in order to determine what to do with a given member of S, it can do so by applying the function G with the current member of S and the related member of T as members of the set of sets to which G should apply itself - or as "arguments" to G, if you prefer that terminology (although arguments to a function are still a set of sets, whatever you may call them).
Note that the application of a function to a set does not imply or require looping of any kind. It is merely a declaration that all members of the set should be transformed by said function. Hence the terms "declarative" and "functional" programming (although the set of functional languages is a subset of the set of declarative languages, and a number of programming languages that are members of the set of functional languages are also members of one or more other sets, such as the set of object-oriented languages, the set of imperative languages, and the set of prototype-based languages).
Your point about optimised code for a given architecture is a worthwhile one. However, you seem to be missing the point that declarative (and functional) languages exist to provide a level of conceptual abstraction that makes for more efficient programming, where the word "efficient" is used in relation to lines of code produced over time, debuggability (horrid neologism - my apologies to the English language) of such code on its initial creation, readability and understandability of such code for maintenance purposes, debuggability of such code for maintenance purposes, and - guess what? - optimisation of such code at runtime. Tail-call optimisation means that some function that is represented with clarity by a recursive definition in the high-level source will often, even usually, be resolved at runtime into... well, lookyhere: a tight loop that fits into the processor's instruction cache

Last edited:
03:43



