Beginning at the Beginning
It is customary to declare your intention to learn the language by creating the “Hello World” program. The simplest way to do this in Magik is to type write(“Hello World!”) at the command line.
Magik2> write("Hello World")$
Hello World
Magik2>
This works because Magik compiles code on the fly and executes them instantly from the command line. This is great for a lot of stuff, but it doesn’t qualify as having coded our first program, so we need to find a new place to write code that doesn’t compile instantly. The best place for this is the scratch buffer.
To get to the scratch buffer press <ctrl>-x, b to bring up the “switch to buffer:” command on the very bottom of your emacs screen. Type *scratch* and hit enter and the scratch buffer will appear. In most cases typing *s followed by a tab should auto-complete the line for you, unless you have another buffer that starts with *s. Most people don’t.
The following text is populated in the scratch buffer the first time you enter it.
This buffer is for notes you don't want to save, and for Lisp evaluation.
If you want to create a file, visit that file with C-x C-f,
then enter the text in that file's own buffer.
This needs to be deleted before you can utilize the buffer. Once the buffer is empty you can begin writing a program. At the moment it is a plain text buffer, but we can fix that. Pressing <alt-x> and typing magik-mode will enable Magik mode in the buffer. This allows Magik specific functions like auto complete, keyword recognition, and word coloring to work.
To write our first program we will use one of the simplest constructs available, a procedure or a proc.
_global hi <<_proc()
write(“Hello World”)
_endproc
We declared a global variable named “hi”, which is not case sensitive so all you java educated camelCase programmers take note. The “<<” is Magik’s assignment indicator and is read “becomes” by most people. _proc and _endproc are keywords and the write statement between them should look familiar. Keywords are identified by the underscore at the beginning. If you enabled magik-mode earlier, pressing F12 should color them in a unique (usually blue) color.
The program needs to be compiled so that the command line will recognize it. To do this, press F2 then b which is short for buffer. There are other options for compiling less than the full buffer such as F2 then m for compiling the method. If your code can be fully parsed without errors the *gis* buffer should now show the following:
Magik2> Loading C:\Temp\Tua030992780--- line 0
Defining variable hi
--- line 7
True 0
Magik2>
Now type in your program name at the command prompt and hopefully you will see the expected output.
Magik2> hi()
$
Hello World
Magik2>
Congratulations on writing your first Magik procedure. If you did it correctly you just declared to the world, or at least the command line, that you are now a member of the rare breed of programmers that can write Smallworld Magik under the Skills heading on their résumés.