What value should be written to run the code correctly. I give any amount I do not see any output.
f(T, Y) :-Y is sqrt(abs(T)) + 5*T^3.
main :-
read(As),
length(As, N), reverse(As , Rs),
( foreach(Ai , Rs), for(I, N - 1, 0, -1) do
Bi is f(Ai),
( Bi > 400 -> printf("%w TOO LARGE\n", I)
;
printf("%w %w\n", [I, Bi])
)
).
Your program works fine. Maybe you forgot to terminate your data input with a fullstop/period?
[eclipse 2]: main. % Invoke 'main' from the ECLiPSe prompt.
[3,7,5,2]. % Input the list, terminate with fullstop.
produces this output
3 41.4142135623731
2 TOO LARGE
1 TOO LARGE
0 136.732050807569
Yes (0.00s cpu)
Remember that, if you use one of the primitives that read terms in Prolog syntax (read/1,2, read_term/1,2, etc), each term has to terminated with a fullstop (although ECLiPSe also accepts end-of-file).
By the way, instead of using read/1, you would normally just pass data as an argument. If you change your code in this way, you can just invoke main([3,7,5,2]).