Archive for May, 2009|Monthly archive page

DeafGrandma program in PortablE

I have been using small programming exercises from a book about another language and coding them in PortablE. One of the programs was called DeafGrandma. I thought it sounded fun, so I chose it to code. This is a simple program, but you can learn some valuable things you will be using over and over. First, here is the description of what they wanted the program to do.

Write a Deaf Grandma program. Whatever you say to grandma (whatever you type in), she should respond with HUH?! SPEAK UP, SONNY!, unless you shout it (type in all capitals). If you shout, she can hear you (or at least she thinks so) and yells back, NO, NOT SINCE 1938! You can’t stop talking to grandma until you shout BYE.

The most difficult obstacle I had writing this program was how to use E-strings. This is a special feature of the Amiga E language. I thought I understood them, but I found out I wasn’t at all sure how to compare them with each other or normal strings. For a good explanation of E-strings check out this page of the Amiga E Beginner’s Guide.
Ok, so here is the code for DeafGrandma.e

/* DeafGrandma program 5-27-09 */

PROC main()
    DEF say[80]:STRING, upperSay[80]:STRING

    REPEAT
      Print('What would you like to say to Grandma?\n')
      ReadStr(stdin,say)
      SetStr(say, EstrLen(say) - 1)

      StrCopy(upperSay, say)
      UpperStr(upperSay)		->make uppercase version of "say"

      IF StrCmp(say, upperSay) = FALSE
        Print('HUH?! SPEAK UP, SONNY!\n')
      ELSE
        Print('NO, NOT SINCE 1938!\n')
      ENDIF
    UNTIL StrCmp(say, 'BYE') = TRUE
ENDPROC

To test this just go to the command line and use PortablE to compile it first.
PortablE DeafGrandma.e
This will give you a .cpp file that you can use a c++ compiler to compile to give you an executable. Like so.
g++ DeafGrandma.cpp -o DeafGrandma
Now you can just type the name DeafGrandma to run the program. On to the code.
/* DeafGrandma program 5-27-09 */
This first line is just a comment. I wanted to show what they look like, so here is one type. I have the other type down a few lines.
PROC main()
This next line is the main procedure of our program. Every PortablE program must have a main() procedure.
DEF say[80]:STRING, upperSay[80]:STRING
Now things start getting interesting. Here we define our E-strings. We have two fixed E-strings here named say and upperSay. Both have a max length of 80.
REPEAT
This is the start of our loop. A WHILE loop could have worked in this instance, but I went with REPEAT.
Print('What would you like to say to Grandma?\n')
Of course this displays the text. The \n adds a return on the end and sends the cursor to the next line.
ReadStr(stdin,say)
SetStr(say, EstrLen(say) - 1)

The first line here is waiting for input from the keyboard or user. It places what is typed into the “say” E-string we created earlier. It also saves the return that is pressed. The next line removes this return from the E-string.
StrCopy(upperSay, say)
Basically, this copies the content of the say E-string to UpperSay.
UpperStr(upperSay) ->make uppercase version of "say"
The UpperStr() function here makes all the characters in the upperSay E-string all caps. The -> out to the side is a way to place a comment on the same line as your code.
IF StrCmp(say, upperSay) = FALSE
This is the start of your IF statement. It is using the StrCmp() function to compare the two E-Strings. This is so we can test whether someone entered something in all caps or not. Because the only way Grandma is going to hear you is by yelling using all caps. The ELSE that follows is what happens if something is typed in lower case or mixed case.
UNTIL StrCmp(say, 'BYE') = TRUE
This is the condition test of our REPEAT loop. It just tests to see if BYE is typed in all caps. If it is, the program stops right here.
Finally the ENDPROC just finishes off our main PROC() that was stated earlier.

Since this was a very small program, I thought it would be good to go through each line of the program to explain everything. Hopefully beginners will find it useful. When I first tried to write this program I tried to compare E-strings using operators like and :=. This will not work, so this is why the functions are used. I think it makes it nice and easy to read as well.

Amiga E Useful Resources

As I was coding today I realized it might be a good idea to post a list of useful resources if you are interested in programming in Amiga E. I have mentioned different items here and there in this blog, but haven’t listed a nice list in one post. I’ll try to do that here and explain if it needs to be explained.

If you are programming on an Amiga or are using WinUAE to run an Amiga environment to program in, you have many choices since Amiga E originated on the Amiga. (duh!) Besides PortablE, there is the excellent compiler ECX by Leif Salomonsson. It is still being maintained! You can find it at http://www.blubbedev.net/ecx/. There are versions for AmigaOS 4.0 and MorphOS as well.

PortablE – PortablE language and compiler
AmigaE IRC Channel – irc.freenode.net at #amigaE
Wouter’s AmigaE page – The original Amiga E web site by creator Wouter van Oortmerssen.
Beginner’s Guide to Amiga E by Jason R. Hulance
Amiga E Mailing List
Amiga E programs available at Aminet – http://aminet.net/dev/e
Amiga E at Wikipedia – http://en.wikipedia.org/wiki/AmigaE
UtilityBase – Active web site with a lot of Amiga developer information including Amiga E of course.
AmiDevCpp – nice Windows IDE with Amiga cross compilers included.

The most complete Amiga E language reference you will find is at Wouter’s Amiga E page. Just download the main archive from that site even if you are using Windows. The language reference is in AmigaGuide format. To read this in Windows go to Safalra’s web site and download WinGuide 4.0 and install it. You will then be able to open the Amiga E reference guide that Wouter provides in the main archive. This and the beginner’s guide that I mention above will be your main references while coding Amiga E.

EDIT: I have just been informed that Wouter’s guide is now available online here.

Also, if you haven’t heard, PortablE for Windows is in beta. So we will soon be able to use Amiga E in Windows.
So now that you have all of that, there is no excuse not to become an Amiga E programmer!

Emacs, Editors and Stuff

I was thinking about a primary programming editor to use to write PortablE code in Windows. There are many out there. SciTE, Vim, Crimson Editor, and Notepad++ to name a few. Notepad++ is a popular editor and has some very nice features. I hate the name though! C’mon use some imagination when you create a good editor like that! It does have a nice way to create syntax highlighting for user defined languages, which I would like to have for PortablE.

There is a programming editor for Amiga OS4 called Annotate. It already has syntax highlighting for the Amiga E language. It has a GPL license. It might be kind of cool if someone ported it to Windows. Check out more about Annotate at it’s homepage.

Being a Lisp lover, Emacs came to mind quickly. But I didn’t want a big install headache. After a bit of research I found EmacsW32. Wow, I am so glad I did! One file has everything you need to run Emacs in Windows. This includes the latest Emacs version, 23.0. I downloaded the “patched” version. It worked fine in Windows XP and Vista. So I am now using Emacs as my editor of choice.
I would eventually like to have syntax highlighting for my PortablE/Amiga E code. To do this in Emacs you need to create a mode for it. I have never done this before, but I was reading about it. You can concentrate on just creating a mode that handles the syntax highlighting and comments. This is exactly what I need. I found a tutorial about it and it didn’t look too bad, but it might be tricky. Maybe I can find the time to tackle it at some point.

Nimrod Programming Language

While reading the reddit programming section the other day I read about a new programming language named Nimrod. It looks pretty cool. I ran through the first tutorial to check it out. On Nimrod’s web site it states that Nimrod is a language which combines Lisp’s power with Python’s readability and C’s performance.

I like what it combines and thought of Amiga E since Amiga E combines three different languages, Lisp, Ada and C++. There is plenty of documentation to get you started and it sounds like a fast language. So you might check it out at the Nimrod web site.

Testing Amiga E in Windows

I was able to start on some basic code the other day that I plan on posting, but I was asked to test PortablE for Windows. So that has been taking my time lately. I have been testing the new version of PortablE in Windows Vista and Windows XP. Things are going very well with just minor problems that Chris is taking care of.

I needed a C++ compiler for Windows because after PortablE does it’s job with the Amiga E code, then you have to use a C++ compiler to compile your .cpp file that PortablE creates for you. I decided I would like to have gcc. The best and easiest I found was Minimalist GNU for Windows or MinGW. This installed without problems in Windows XP, but with Vista it had a problem with placing the additions to PATH. In Vista just right click on “Computer”, go to “Properties”, on the left navigation click on “Advanced System Settings”, then click on the “Environment Variables…” button. At the lower portion of this window you will see “System Variables”. In that list is “Path”. Highlight this and click “Edit…”. This is where you need to add c:\mingw\;c:\mingw\bin;c:\mingw\libexec\gcc\mingw32\3.4.5\ to the end. This should allow you to run g++ from anywhere in the command line in Windows Vista.
Once I had g++, I was able to start testing my Amiga E programs created with PortablE!

Yesterday

With a title like that you expected me to break into a Beatles song didn’t you? Haha, that was the first thing that popped into my mind. Well yesterday I started brushing up on my Amiga E programming again. I started reading through Jason R. Hulance’s excellent beginner’s guide to Amiga E. You can find that here.
I also talked to Chris Handley a little about the next version of PortablE. I can’t say much about it at this point, although the major improvement is support for Windows. This will make it even more accessible to the masses.
I’ll try to post some Amiga E code in my next post. Just some basic stuff, but it may be interesting to people who haven’t done much with it.

Next Page »