AFL

Arguably Functional Language



AFL Documentation

Code Examples


This entry contains a few examples of AFL code, to show what AFL is capable of.

Parrot

# This program asks for the user's name and repeats it. "What's your name?"; name=input(); # Get input from the user # output "Hi, "+name+". It's nice to meet you!"

Guessing game

# This program lets you play a guessing game. # it demonstrates functions and some utility functions function("guess"1); limit = arrayGet(params 0); # get the high bound for our game number = truncate(random(1 limit+1)); # figure out the number we are thinking of # get the game started! "I'm thinking of a number between 1 and "+limit+"..."; guess=neg(1); # keep asking for guesses until the player gets it right while(guess!=number); # prompt the player for a guess "Make a guess!"; guess = truncate(numInput()); # the player won! congratulate them if(guess==number); "Good job!"; break(); end(); # nudge the player in the right direction if(guess>number); "Your guess was bigger than the number..."; end(); else(); "Your guess was less than the number..."; end(); end(); end()

Play the guessing game with guess(num), where the num is the high limit on the number!

Prime Numbers

# This program prints prime numbers smaller than 100. limit = 100; # if you want more numbers, you can just adjust this variable. # toCheck represents the current number we are looking at, which may or may not be prime. toCheck = 2; # toCheckBy represents a number we are using to check whether toCheck is prime. toCheckBy = 2; "Here are the prime numbers smaller than "+limit+":"; while(toCheck < limit); toCheckBy = 2; isPrime = true; # whether the number in question is prime. We start off assuming it is. while(toCheckBy < toCheck); # Check whether toCheck/toCheckBy is a whole number. # if it is, the number is not prime. if((toCheck/toCheckBy)%1==0); isPrime=false; # Nope, it's not. break(); end(); toCheckBy= toCheckBy+1; end(); if(isPrime); # write the numbers we know to be prime, and not the ones that aren't. toCheck; end(); toCheck= toCheck+1; end()

Silly Bar

# How does this work? Magic! # This was written a while ago. function("drawBar"1); # draw the bar, I guess... str="|"; filled = arrayGet(params 0); unfilled=16-filled; while(filled>0); str=str+"#"; filled=filled-1; end(); while(unfilled>0); str=str+" "; unfilled=unfilled-1; end(); str=str+"|"; clear(); str; end() progress=0; while(true); # the bar is growing while(progress<16); drawBar(progress); progress=progress+1; sleep(50); end(); # the bar is shrinking while(progress>0); drawBar(progress); progress=progress-1; sleep(50); end(); end()

Now you can see the power of AFL.

Not that much, to be honest, but AFL is capable of more things than this limited selection shows. Try exploring the reference pages, maybe something interesting is in there. Maybe.