[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
loop translations (was: Re: language translator help)
From: |
John W. Eaton |
Subject: |
loop translations (was: Re: language translator help) |
Date: |
Sat, 27 Apr 2002 19:53:33 -0500 |
On 27-Apr-2002, Neil Jerram <address@hidden> wrote:
| I'm not aware of such a document. Suggest you post the translation
| code that you've tried already. I'll certainly take a look, and I
| guess you'll get a deluge of suggestions from others as well.
OK, here goes.
I'd like to understand how to translate some simple loops. For
example, the following loop is valid in Octave.
for i = 1:3
disp (i);
if (i == 2)
break;
endif
endfor
This should print
1
2
Note that this sequence of statements doesn't return any value. For
Guile, the best I've come up with is
(let for ((i 1))
(call-with-current-continuation
(lambda (break)
(if (<= i 5)
(begin
(display i)
(newline)
(if (= i 2)
(break (if #f #f)))
(for (+ 1 i)))))))
This works, but seems quite complex to me. Is there a simpler way?
Here is another:
for i = 1:4
if (i < 4)
disp ("foo-i-hithere");
if (i == 2)
continue;
endif
endif
disp (i);
endfor
This should print
foo-i-hithere
1
foo-i-hithere
foo-i-hithere
3
4
For Guile, I came up with
(let for ((i 1))
(call-with-current-continuation
(lambda (continue)
(if (<= i 4)
(begin
(if (< i 4)
(begin
(display "foo-i-hithere")
(newline)
(if (= i 2)
(continue (for (+ 1 i))))))
(display i)
(newline)
(for (+ 1 i)))))))
Again, this works but is there a better way? It seems undesirable to
duplicate the (for (+ 1 i)) bit.
jwe
- Re: language translator help, (continued)
- Re: language translator help, John W. Eaton, 2002/04/28
- Re: language translator help, Thomas Bushnell, BSG, 2002/04/29
- Re: language translator help, John W. Eaton, 2002/04/29
- Re: language translator help, Thien-Thi Nguyen, 2002/04/29
- Re: language translator help, MJ Ray, 2002/04/30
- Re: language translator help, Thomas Bushnell, BSG, 2002/04/30
- Re: language translator help, Neil Jerram, 2002/04/28
- Re: language translator help, Thomas Bushnell, BSG, 2002/04/28
- Re: language translator help, Per Bothner, 2002/04/28
- Re: language translator help, Neil Jerram, 2002/04/28
loop translations (was: Re: language translator help),
John W. Eaton <=
Re: loop translations (was: Re: language translator help), Marius Vollmer, 2002/04/28
Re: loop translations (was: Re: language translator help), John W. Eaton, 2002/04/28
Re: loop translations (was: Re: language translator help), Marius Vollmer, 2002/04/28
Re: loop translations (was: Re: language translator help), Marius Vollmer, 2002/04/28
Re: loop translations (was: Re: language translator help), Clinton Ebadi, 2002/04/29
Re: loop translations (was: Re: language translator help), Eric E Moore, 2002/04/29
Re: loop translations (was: Re: language translator help), Eric E Moore, 2002/04/30