(NOTE: This project is currently out of commission as I find a new place to host it and adjust the code to accommodate recent changes in the Twitter API.)
My day 2 project is called twbasic. It’s an implementation of classic, line-numbered, home computer-era BASIC that runs on top of Twitter. You can start using twbasic right now by twittering your program listing to @twbasic. Here’s how to get twenty rolls of a six-sided die:
@twbasic 10 for i = 1 to val(ARG$) @twbasic 20 print rnd(6) + 1 @twbasic 30 next i @twbasic run 20
(The above screenshot depicts twbasic providing a listing of the program above, and then the results of running the code.)
A reference for using twbasic can be found after the jump.
Twbasic Language Reference
Twbasic is built on top of Malcom McLean’s liberally licensed MiniBasic. Twbasic supports all of MiniBasic’s keywords (see the manual for a list and explanations), with the following additions and omissions:
- The INPUT keyword is unsupported. (It doesn’t make sense in the context of twitter, since there is no keyboard to retrieve input from.)
- An additional global variable, ARG$, is available to your program. This variable contains the whatever string follows the run command (see below).
- Keywords are insensitive to case. (MiniBasic requires keywords in all-caps. I found that to be annoying for use from mobile phones.)
Twbasic also limits the output of any program to 120 characters (approximately one tweet). The server is currently set up to automatically kill any twbasic process that runs longer than fifteen seconds (so keep your programs brief).
To use twbasic, simply start tweeting your program listing to twbasic using the reply syntax, like so:
@twbasic 10 rem my first twbasic program @twbasic 20 print "hello!"
To retrieve a listing of your program, send
@twbasic list. Your program will be sent back to you as a reply, one line at a time. (This might take a while.)
To clear your current program and start from scratch, send
You can revise a line in your program by sending another line with the same line number. For example, if you had originally sent the program above, then sent
@twbasic 20 print "goodbye!", then you’d receive the following listing from
@twbasic 10 rem my first twbasic program @twbasic 20 print "goodbye!"
Once you’re satisfied with your program listing, run your program with the following syntax:
@twbasic run. Any characters following
run will be available within the program as the
After you’ve run your code, twbasic reply with its output (if any). If you’re following @twbasic, the output will show up on your timeline. If not, you’ll have to visit twitter.com/twbasic.
(Please be patient with twbasic: it’s only as responsive as its friendly whale master allows it to be.)
The abbreviated, text-heavy and asynchronous nature of Twitter reminded me of my formative years in front of a TRS-80 Color Computer 2. I used BASIC then, why not use it now?
While twbasic is mostly just a fun hack, it could potentially form the basis of a mobile, cross-platform programming platform. Twitter’s biggest assets are its scriptability (via the excellent API) and its accessibility (if you can text, you can tweet). So if you’re on the road somewhere with only your uncle’s crippled mobile phone, you can still use twbasic to write some trigonometry algorithms.
Let me know if you have any problems (that can’t be explained away by twitter’s recent flakiness) or if you come up with any ideas for interesting applications.