- For(T,R,A,N
- 28 May 2020 07:26:20 pm Permalink
- Last edited by kg583 on 31 May 2020 12:44:26 am; edited 2 times in total

Almost a year ago, I discussed on the Cemetech Discord server a terrible yet vaguely interesting programming challenging: TI-BASIC using only For( loops. Beyond just basic control flow, For( loops are capable of storing and adding variables, which can then be extended to multiplication, division, and pretty much any other math operation you'd need to do. Conditional statements are also quite easy, since For( loops only loop if the start is smaller than the end.

Unfortunately, I/O presents a bit of challenge to the "language" I've dubbed For(T,R,A,N. The easiest solution is to allow Input and Disp commands; this is not particularly pure, however, so an alternative is to allow only one form of program input, via Ans, and program output dictated by the value of particular variables to be read at the end of execution. Neither are great, but what can you expect from TI-BASIC using only For( loops?

With this in mind, here are some other sample programs, which use the Disp/Input method:

Fibonacci generator

Prime generator

You'll notice the above program also negates a variable, which isn't particularly pure either. To formalize everything, here is the set of allowed tokens and commands for For(T,R,A,N as determined by myself and community consensus:

Everything else, such as lists, strings, math commands, additional control flow, and operations on variables are disallowed. Seems pure enough, I guess, and just hard enough to make subtraction non-trivial.

So, yeah. This is what pops into my head messing with my calculator at 2 AM. Suggestions, additional programs, and convoluted attempts at a C compiler are welcome.

**Code:**```
:A->B
```

becomes (when used before a loop)

:For(B,A,A

or (when used inside a loop)

:For(B,0,0,A:End

**Code:**```
:2A->A
```

becomes

:For(A,A,A,A:End

**Code:**```
:If A>=B
```

becomes

:For(X,B,A

Unfortunately, I/O presents a bit of challenge to the "language" I've dubbed For(T,R,A,N. The easiest solution is to allow Input and Disp commands; this is not particularly pure, however, so an alternative is to allow only one form of program input, via Ans, and program output dictated by the value of particular variables to be read at the end of execution. Neither are great, but what can you expect from TI-BASIC using only For( loops?

With this in mind, here are some other sample programs, which use the Disp/Input method:

Fibonacci generator

**Code:**```
:Input M
```

:For(A,0,0:For(B,1,1

:For(D,2,M

:For(C,A,A,B:End

:For(A,B,0:End

:For(B,C,0:End

:Disp B

:End

Prime generator

**Code:**```
:Input M
```

:Disp 2

:For(P,3,M,2

:For(Q,P,P,-1:End

:For(D,3,Q,2

:For(R,P,D,-D:End

:For(S,R,0

:For(D,Q,Q,Q:End

:End:End

:For(Q,Q,Q,Q:End

:For(S,D,Q

:Disp P

:For(S,Q,Q:End

:End:End

You'll notice the above program also negates a variable, which isn't particularly pure either. To formalize everything, here is the set of allowed tokens and commands for For(T,R,A,N as determined by myself and community consensus:

- Integer constants -- YES: 0, 7, -3, 12384 -- NO: 8.7, 9E15, pi, 2/3

Real variables -- YES: A, B, Q, theta -- NO: I%, u, Str3, n

For( commands -- YES: For(A,-1,B,Q -- NO: For(A,7.3,BC,-B

Disp commands -- YES: Disp -7, Disp Q -- NO: Disp A+B, Disp CD (use sparingly)

Ans (for input) -- YES: For(A,Ans,0 -- NO: For(A,AnsQ,3

Everything else, such as lists, strings, math commands, additional control flow, and operations on variables are disallowed. Seems pure enough, I guess, and just hard enough to make subtraction non-trivial.

So, yeah. This is what pops into my head messing with my calculator at 2 AM. Suggestions, additional programs, and convoluted attempts at a C compiler are welcome.