[erlang-questions] Nested for-loops, there has to be a better way to do this

Brentley Jones <>
Wed Jul 29 21:22:55 CEST 2009


On Jul 29, 2009, at 2:13 PM, Zoltan Lajos Kis wrote:

> Brentley Jones wrote:
>>
>> On Jul 29, 2009, at 1:57 PM, Zoltan Lajos Kis wrote:
>>
>>> And what do I gain using this for function compared to simply  
>>> writing an "ad-hoc" recursive function whenever needed ?
>>
>> Nothing is gained by my bloated, yet modular function. I was just  
>> expanding on the modular function listed before mine.
>>
>>> PS: seriously, is this what the original question was getting at?
>>
>> I do think it shows how to do nested for loops in a way that looks  
>> very imperative, which is what I think the original question was  
>> getting at.
>>
>> On Jul 29, 2009, at 2:55 PM, Yves S. Garret wrote:
>>
>>> I was playing around with the idea of implementing a nested for-loop
>>> like construct (I will concede, they are evil, but at rare times,
>>> necessary.)  In non-functional programming languages, they are  
>>> trivial
>>> to do.  However, this has proved to be one of those simple things  
>>> that
>>> are a pain in the neck for me.
> But if you look just one sentence further...
> "The idea was to be able to pass in a list [5, 5, 10] (for example)  
> and go through it all like 3 dimensional array."

The fact that he says "in non-functional programming languages, they  
are trivial to do." just lead me to try to think that way. In a non- 
functional programming language there isn't a construct that he can  
just pass a list which has lengths for each dimension, he would have  
to set up each for loop with those values as the conditionals.

> Anyway, we should get the answer by dawn (CET) :)
>
> Z.


I think with the resources that we have provided though that we have  
answered the question in one way or another (either with these modular  
for loop constructs or the nice list comprehensions , etc).

And Joe asked a very good question, what does he want the output to be?
Does he want a body that has access to i, j, k [5, 5, 10] and is  
called like three nested for-loops (which is what I thought), or  
something totally different?



More information about the erlang-questions mailing list