Last active
February 14, 2016 12:25
-
-
Save miklund/d248791e2957f5c0db89 to your computer and use it in GitHub Desktop.
2016-02-09 Beginners guide to Arexx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Beginners guide to Arexx | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2016/02/09/beginners-guide-to-arexx.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sorting a list of random numbers with bubble sort */ | |
SAY "How many numbers should we sort? (number)" | |
PULL max | |
/* Randomize numbers */ | |
DO i = 1 to max | |
numbers.i = RANDOM(1, 100) | |
END | |
SAY "Random numbers" | |
CALL print | |
CALL sort | |
SAY "Sorted numbers" | |
CALL print | |
exit | |
swap: procedure expose numbers. | |
ARG i, j | |
swap = numbers.i | |
numbers.i = numbers.j | |
numbers.j = swap | |
return | |
sort: procedure expose max numbers. | |
DO i = 1 to (max - 1) | |
DO j = (i + 1) to max | |
IF numbers.i > numbers.j THEN CALL swap(i, j) | |
END j | |
END i | |
return | |
print: procedure expose max numbers. | |
output = "" | |
DO i = 1 to max | |
output = output || numbers.i || ", " | |
END i | |
SAY output | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A small program to encrypt a string with ceasar cipher */ | |
alphabet = 25 | |
ascii = C2D("A") | |
SAY "Enter the encryption key (number):" | |
PULL encKey | |
SAY "Enter the phrase to encrypt (capital letters):" | |
PULL data | |
result = "" | |
DO i = 1 to LENGTH(data) | |
char = C2D(LEFT(data, 1)) - ascii | |
encChar = D2C(((char + encKey) // alphabet) + ascii) | |
result = result + encChar | |
data = RIGHT(data, LENGTH(data) - 1) | |
END i | |
SAY "Encrypted phrase:" result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a program to demonstrate inter process communication */ | |
DO FOREVER | |
SAY "Please select of the following" | |
SAY " 1) Send message to open instances" | |
SAY " 2) Retrieve message" | |
SAY " Q) Quit" | |
PULL selection | |
SELECT | |
WHEN selection = 1 THEN CALL sendmessage | |
WHEN selection = 2 THEN CALL retrievemessage | |
WHEN selection = "Q" THEN LEAVE | |
OTHERWISE NOP | |
END | |
END | |
EXIT | |
sendmessage: procedure | |
SAY "Type in the message you want to send" | |
PULL message | |
SETCLIP("message", message) | |
return | |
retrievemessage: procedure | |
SAY "Pulling message from external source" | |
message = GETCLIP("message") | |
SAY message | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Calculate the factorial of a number */ | |
SAY "Calculate the factorial of: " | |
PULL n | |
result = 1 | |
DO i = n to 1 by -1 | |
result = result * i | |
END | |
SAY n || "! =" result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get a list of fibonacci numbers */ | |
SAY "How long fibonacci sequence do you want? (number)" | |
PULL size | |
fibonacci.1 = 1 | |
fibonacci.2 = 2 | |
DO i = 3 to size | |
prev = i - 1 | |
prevprev = prev - 1 | |
fibonacci.i = fibonacci.prevprev + fibonacci.prev | |
END | |
SAY "Fibonacci" | |
DO i = 1 to size | |
SAY i || ":" fibonacci.i | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Find an element in an array */ | |
numbers = "" | |
/* Create vector */ | |
vector.1 = 12 | |
vector.2 = 23 | |
vector.3 = 34 | |
vector.4 = 45 | |
vector.5 = 56 | |
SAY "Numbers: 12 23 34 45 56" | |
SAY "Test if number is in vector:" | |
PULL guess | |
IF find(1, 5, guess, vector) THEN SAY "Yes, number exists" | |
ELSE SAY "No, number doesn't exist" | |
exit | |
find: | |
ARG min, max, search, vector | |
/* found/* | |
IF search = vector.min | search = vector.max THEN return 1 | |
/* not found */ | |
ELSE IF max - min < 2 THEN return 0 | |
/* keep looking */ | |
ELSE | |
DO | |
middle = min + TRUNC((max - min) / 2) | |
IF search >= vector.middle THEN | |
return find(middle, max, search, vector) | |
ELSE | |
return find(min, middle - 1, search, vector) | |
END | |
SAY "Error in find function" | |
EXIT | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a small game that lets you guess a random number */ | |
number = RANDOM(1, 1000) | |
guess = -1 | |
guesses = 0 | |
SAY "The number is between 1-1000." | |
DO while guess ~= number | |
SAY "Guess the number: " | |
PULL guess | |
IF guess > number THEN SAY "Your guess was too high" | |
ELSE SAY "Your guess was too low" | |
guesses = guesses + 1 | |
END | |
SAY "You've found the in" guesses "tries"." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Prints Hello World! */ | |
SAY "Hello World!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This program will demonstrate procedures */ | |
width = 33 | |
call separator | |
call title | |
call separator | |
exit | |
title: | |
SAY "*** AREXX WILL RULE THE WORLD ***" | |
return | |
separator: | |
SAY COPIES("*", width) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This program will print a pyramid of a hiehgt the user specify */ | |
SAY "Height of the pyramid:" | |
PULL height | |
DO i=1 to height | |
spaces = "" | |
stars = "" | |
DO j=1 to (height - i) | |
spaces = spaces || " " | |
END | |
DO j=1 to (i + i - 1) | |
stars = stars || "*" | |
END | |
SAY spaces || stars | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a type test */ | |
seven = "7" | |
reallySeven = 7 | |
almostSeven = 7.0000000001 | |
SAY '22'x seven '22'x "=" reallySeven ":" (seven = reallySeven) | |
SAY '22'x seven '22'x "==" reallySeven ":" (seven == reallySeven) | |
SAY '22'x seven '22'x "=" almostSeven ":" (seven = almostSeven) | |
SAY '22'x seven '22'x "==" almostSeven ":" (seven == almostSeven) | |
SAY '22'x reallySeven '22'x "=" almostSeven ":" (reallySeven = almostSeven) | |
SAY '22'x reallySeven '22'x "==" almostSeven ":" (reallySeven == almostSeven) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This program asks the user for name and shoe size */ | |
SAY "What is your name?" | |
PULL name | |
SAY "What is your shoe size?" | |
PULL size | |
SAY "Hello" name "your shoe size is" size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment