tags:

views:

159

answers:

5

Which languages are recursive-only languages?

+4  A: 

It depends on what you mean by looping construct - there are several types. Infinite loops, iterators - loops that count each item in an array or hash - and general loops like C style

for ( int i = 0; i < 10; i++ )

Wikipedia has a table of support for such constructs by language: Loop system cross reference table

To answer your question fully, Haskell and Scheme are two examples of languages that do not have standard for loops built in; they are generally done using recursion.

rjh
in Scheme, for example, "tail recursion" plays the role of a looping construct.
Nick D
A: 

The obvious answer (if it counts as a language) is various types of Assembly languages.

Rickard von Essen
I'd say a conditional jump is exactly a "looping construct", but it does depend on ones definition.
Svend
Since the OP said "recursive-only" and the common way to do iteration in assembly are jumps, not recursion, I'd say this doesn't count.
sepp2k
Ok I could agree, this is rather much a question of wording. Conditional jumps is "branching constructs" and as long you can jump "backwards" it could be a loop.
Rickard von Essen
Some ISAs even have specific looping instructions, e.g. Motorola DSP56k has a hardware (zero overhead) DO loop and also the REP instruction which executes the next instruction N times.
Paul R
Yes, some certainly have. Mostly for DSPs.
Rickard von Essen
Fun that you mention the DSP56k, I have written a assembler for it some years ago. The point was that a looping construct have a direct or indirect mapping to the flow control instructions in the CPU.
Rickard von Essen
+2  A: 

Erlang does not have looping constructs. You use recursion instead.

Brabster
+1  A: 

Prolog and other logic programming languages.

As an aside, doesn't this question more or less boil down to programming paradigm? Imperative languages have looping constructs; other do not have.

Edit: Language designed specifically to make you tear your eyes out, like

Mads Ravn
+2  A: 

Functional programming languages (e.g. Haskell, Erlang) generally don't have loops, nor do function-level languages (e.g. FP, J) or logic languages (e.g. Prolog, Planner). Indeed pretty much the entire group of declarative languages (of which functional, function-level, logic, etc. are a subset) tend not to have looping constructs.

But...

That being said a lot of those have ways of doing much the same as explicit looping. Common Lisp, for example, has macros that give you the ability to do what looks like regular for, while, etc. loops by macro trickery behind the scenes. Dylan (a very un-Lisplike Lisp) goes a step farther and elevates such macros into something that is effectively part of the language (although the semantics can still be defined in terms of recursion and macros). Too, common operations in functional languages like zips, maps, folds, takes, etc. are higher-level functions that mask explicit recursion behind a function call and act in many ways like assorted loop constructs.

JUST MY correct OPINION