Hello world/Newbie: Difference between revisions
Line 238: | Line 238: | ||
$ chmod a+x my_script.py |
$ chmod a+x my_script.py |
||
$ ./my_script.py |
$ ./my_script.py |
||
=={{header|Racket}}== |
|||
===Installation=== |
|||
Install Racket from [http://racket-lang.org/|the Racket home page]. |
|||
On Windows and OS X when you have a 64 bit platform, you can install either the 64 bit Racket or the 32 bit one, the installer page will not try to detect this, since both options can be used. The choice will usually not make much difference; a quick summary is that with the 64 bit version you can use much more space (in 32 bit mode there's a 4gb limit), but things are going to run a bit slower due to Racket shuffling more memory around. (This is not Racket-specific, of course.) |
|||
On Linux, you can often find a Racket package for your distribution flavor. From the Racket web page you can find a few installers built on different Linux distros, and one of them might fit you even if you're on a different one. The Racket installers come in shell-script form, which you can just run in a terminal (<tt>sh installer.sh</tt> would do it). The first question that the installer will ask you is whether you want a unix-style distribution, with files spread across standard directories -- the recommendation is to not do this, and instead install Racket in a single directory. This choice makes it much easier to try Racket quickly -- you can just remove the directory when you're done, you can easily have multiple versions installed, and you don't need write permission to system directories. |
|||
===Developing Racket Code=== |
|||
Racket comes with DrRacket, an IDE that is designed to make Racket work easy (and implemented in Racket). However, you can use your own editor if you're used to one. See the [http://docs.racket-lang.org/guide/other-editors.html|Racket Guide] section on working with different editors, and running Racket from the command line. |
|||
===Learning Racket=== |
|||
One of Racket's main points is coming with thorough documentation, which you get with the installation and but you can also view it [http://docs.racket-lang.org/|on-line]. Specifically, pay attention to the [http://docs.racket-lang.org/getting-started/|Getting Started] page that will help with a few convenient entry points. |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
Revision as of 03:37, 1 June 2013
Guide a new user of a language through the steps necessary to install the programming language and selection of an editor if needed, to run the languages' example in the Hello world/Text task.
- Assume the language-newbie is a programmer in another language.
- Assume the language-newbie is competent in installing software for the platform.
- Assume the language-newbie can use one simple text editor for the OS/platform, (but that may not necessarily be a particular one if the installation needs a particular editor).
- Refer to, (and link to), already existing documentation as much as possible (but provide a summary here).
- Remember to state where to view the output.
- If particular IDE's or editors are required that are not standard then point to/explain their installation too.
- Note:
- If it is more natural for a language to give output via a GUI or to a file etc, then use that method of output rather than as text to a terminal/command-line, but remember to give instructions on how to view the output generated.
- You may use sub-headings if giving instructions for multiple platforms.
AWK
AWK on Linux
AWK should be already installed. To run awk, either provide code on shell (using single quotes).
$ awk 'BEGIN{print "Goodbye, World!"}'
Or put code to file and load it from file.
$ awk -f hello-world.awk
C
Using gcc
Debian Based Systems
Install gcc
$ sudo apt-get install gcc
All Distributions
After you have installed gcc
using instructions above. Create helloworld.c
. This uses HERE
document and bash
, the standard shell.
$ cat > helloworld.c <<HERE #include <stdio.h> int main( int argc, char *argv[] ) { puts( "Hello World!" ); return 0; } HERE
Compile it using gcc
.
$ gcc -o helloworld helloworld.c
Run it
$ ./helloworld
D
There is detailed information in The Hello World Program chapter of the online book Programming in D.
Here is a summary:
1) Download and install the latest dmd at dmd download page.
2) Open your favorite editor, write the following source code
<lang d>import std.stdio;
void main() {
writeln("Hello world!");
}</lang>
3) Save the source code under the name hello.d
4) Open a console window and compile the source code by entering the following command
dmd hello.d
5) Start the program on the console by entering the following commandz
hello
The program should produce the following output:
Hello world!
Erlang
Erlang on Linux
Here is a summary:
1) To install Erlang in Linux, open a terminal and run the command:
sudo apt-get install erlang
2) Open your text editor, write the following source code:
<lang erlang>% Implemented by Arjun Sunel -module(helloworld). -export([main/0]).
main() ->
io:fwrite("Hello world!\n").</lang>
3) Save the source code under the name helloworld.erl
4) Open a terminal, hit enter after typing the following command.
erl
5) Compile the source code by entering the following command
c(helloworld).
6) Run the code by calling the main() function using the command:
helloworld:main().
The program should produce the following output:
Hello world! ok
Haskell
Install GHC: <lang>$ sudo apt-get install ghc</lang> Create hello.hs: <lang>$ touch hello.hs $ cat > hello.hs << HERE main = putStrLn "Helo, World!" HERE</lang> Compile it: <lang>$ ghc hello.hs -o hello</lang> And run the executable: <lang>$ ./hello Hello, World!</lang>
J
Download J602 from http://jsoftware.com/stable.htm
Install it, using the defaults.
Run the program, and bring up the ide.
Type in: <lang j>'Goodbye, World!'</lang>
Locomotive Basic
Either use a browser-based CPC emulator (http://www.cpcbox.com/) or download a binary for your platform. A list of emulators is available at http://cpcwiki.eu/index.php/Emulators. JavaCPC (http://sourceforge.net/projects/javacpc/) or WinAPE (http://www.winape.net/) are particularly recommended. An advantage of native emulators is that they tend to have copy-and-paste functionality, so you can edit programs in external editors.
In the emulator, type
<lang locobasic>10 print "Goodbye, World!" run</lang>
Mathematica
Buy & Install the program from http://www.wolfram.com/mathematica/
Start Mathematica either :
- by calling math.exe(Windows) or math (Others)
- by double clicking on the Mathematica icon.
Open a new notebook and type : Print[ "Goodbye, World!"]
PARI/GP
PARI's official site is http://pari.math.u-bordeaux.fr/ .
PARI/GP on Windows
Go to the download page of the PARI/GP website and download one of the following:
- The latest self-installing binary distribution 2.4.2. This is the most full-featured but lacks some of the newer bugfixes and commands.
- The basic GP binary 2.5.0. This lacks some features like high-resolution graphing but has newer features.
- The SVN version 2.6.0. This has the bleeding-edge features but lacks many nicities and may contain bugs.
PARI/GP on the Mac
Install the latest available gp version on
or
PARI/GP on Linux
Install PARI/GP with an appropriate package manager: RPM, apt, etc. Alternately, install it from source.
Your first program
Open a text editor of your choice and type
<lang parigp>print("Hello, world!")</lang>
Save the file in your PARI working directory and start the program, either in a console (command: gp
) or in the GUI in Windows (by double-clicking the shortcut). Type \r filename
to read in the program. (If you saved the file with a .gp extension, you can leave it off here.) The program executes, displaying "Hello, world!".
PicoLisp
Debian-based systems
Install
$ apt-get install picolisp
then run it
$ pil + : (prinl "Goodbye, World!")
Other POSIX systems
Fetch and unpack the tarball
$ wget software-lab.de/picoLisp.tgz && tar xfz picoLisp.tgz
then build the executable (see http://software-lab.de/INSTALL file for 64-bit systems)
$ cd picoLisp $ (cd src; make)
and run it locally
$ ./pil + : (prinl "Goodbye, World!")
Non-POSIX systems
On non-POSIX systems only limited implementations of PicoLisp are available.
If Java 1.6 is installed, get and unpack either the tarball given in "Other POSIX systems", or just "software-lab.de/ersatz.tgz", and run
$ ersatz/pil : (prinl "Goodbye, World!")
(see also http://software-lab.de/ersatz/README).
If no Java is available, you can compile "software-lab.de/miniPicoLisp.tgz" and run it
$ ./pil + : (prinl "Goodbye, World!")
Python
Pythons official home site is http://www.python.org/. It will point you to everything Python.
Python on Windows
(Tested on Windows 7 but should be similar for XP & Vista ).
You need to download and install Python. Use the latest Windows installer for Windows (64bit if you have a 64bit Windows installation). It is a standard Windows click-through installer with an Open-source compatable license.
Once installed, use the new start-menu entry to open the "Idle (Python GUI)" application, which opens a GUI window with a command line and cursor at the bottom. This window displays program output and is a REPL for Python.
Use the File->New window item of the GUI to bring up new blank window and copy the text from Hello world/Text#Python into it, i.e.
<lang python>print "Goodbye, World!"</lang>
use the File menu to save the file with a name hello.py, (remember the .py extension). Use the "Run -> Run module
" menu item from the hello.py Idle editor window to pop the Idle Python shell window to the front whilst executing the program. The output of the program appears in this shell window as the line:
Goodbye, World!
(Followed by a prompt that is part of the REPL of the IDE rather than programmed by the hello.py file).
Python on GNU/Linux
On most Linux distribution, just install the package named python
with the package manager.
If you are using a mainstream Linux distribution, installing Idle along with Python gives you a GUI and two ways of working with your code. The easiest is through Idle, see the Windows instructions above for details. The other is outlined below:
A script can be executed with the command:
python my_script.py
or adding a shebang at the first line of the script:
$ head -n 1 my_script.py #!/usr/bin/env python $ chmod a+x my_script.py $ ./my_script.py
Racket
Installation
Install Racket from Racket home page.
On Windows and OS X when you have a 64 bit platform, you can install either the 64 bit Racket or the 32 bit one, the installer page will not try to detect this, since both options can be used. The choice will usually not make much difference; a quick summary is that with the 64 bit version you can use much more space (in 32 bit mode there's a 4gb limit), but things are going to run a bit slower due to Racket shuffling more memory around. (This is not Racket-specific, of course.)
On Linux, you can often find a Racket package for your distribution flavor. From the Racket web page you can find a few installers built on different Linux distros, and one of them might fit you even if you're on a different one. The Racket installers come in shell-script form, which you can just run in a terminal (sh installer.sh would do it). The first question that the installer will ask you is whether you want a unix-style distribution, with files spread across standard directories -- the recommendation is to not do this, and instead install Racket in a single directory. This choice makes it much easier to try Racket quickly -- you can just remove the directory when you're done, you can easily have multiple versions installed, and you don't need write permission to system directories.
Developing Racket Code
Racket comes with DrRacket, an IDE that is designed to make Racket work easy (and implemented in Racket). However, you can use your own editor if you're used to one. See the Guide section on working with different editors, and running Racket from the command line.
Learning Racket
One of Racket's main points is coming with thorough documentation, which you get with the installation and but you can also view it [1]. Specifically, pay attention to the Started page that will help with a few convenient entry points.
REXX
installation
Each REXX interpreter for a particular operating system has their own requirements, but most involve just copying (usually) two files:
- the REXX interpreter,
- the REXX run-time library (the built-in functions and REXX statement executors).
Note that some operating systems have REXX "built-in", so there
isn't any installation necessary.
The "MVS" and "VM/CMS" IBM mainframe
operating systems have REXX installed (indeed, built-into the operating
system) as well does OS/2 and AS/400.
Note that MVS and VM/CMS are more-or-less generic terms in the IBM world.
program creation
<><>Next, create a REXX program, most users use their favorite text
processor (text editor). It should be "plain" text.
Note that some operating systems require the first statement to be a
REXX-type comment, another requires the first word in the comment to be
the word REXX (in any case, upper/lower/mixed). Most REXX interpreters
enforce the first of these two rules.
The reason for this is that some operating systems had more than one
scripting language, and it is by this first record that allows the
interpreter to distinguish which type it is and then invoke the
appropriate interpreter.
So, a Hello world! REXX program (two lines) could look like:
<lang rexx>
/*REXX program to great the world enthusiastically. */
say "Hello world!"
</lang>
The above program could be made into one statement (since REXX comments
are treated like whitespace).
output
The output (for the SAY instruction) will be shown on the terminal
screen (or window).
Hello world!
execution
To execute the program depends on the operating system.
Just placing the program in a special library (or folder) and invoking
the name of the REXX program will execute it.
You could also invoke the name
of the REXX interpreter followed by the name of the REXX program.
For any CMS system, just place the "HELLO EXEC" file on any disk
that is accessed (normally the 'A' minidisk is used).
For Windows (in a DOS window), place the file "HELLO.REX" in the
current directory (folder) or place the file in the folder that is
specified for the REXX interpreter to use when the program can't be found
in the current directory (CD). Windows class of NT operating systems (NT,
XP, and later) can be set up so that whenever a program (file) that has an
extension of (say) REX, it will be executed (interpreted) by the REXX
interpreter (EXE program). It's possible to have a REXX program without a
file extension (filetype), but that would make it not obvious to what the
file's purpose is and also it'll make it harder to invoke easily.
Tcl
Installation
Many operating systems come with a distribution of Tcl, though it is often of an old version (Tcl 8.4 or occasionally before). Some also provide Tcl 8.5; it is not normally a problem to have both on your system at once, provided software is not coded to use a version-less executable name. As of the time of writing, nothing comes with Tcl 8.6.
Installing Tcl 8.5 on Linux
Your distribution will probably include a package for 8.5 in its distribution, often named something like “tcl8.5”. Many of the tasks here on Rosetta Code also require Tcllib, a collection of scripted Tcl packages; some distributions provide this as well.
Installing Tcl 8.5 on Windows and OSX
You are recommended to use ActiveState's Tcl distribution, which is of very high quality.
Installing Tcl 8.6
As of the time of writing, ActiveTcl is the only “full service” distribution of Tcl 8.6.
Running your first Tcl code
Going to a command prompt and typing:
tclsh8.5
(or tclsh85
on Windows) will start an interactive Tcl shell. At the prompt, you can just type in Tcl commands and have them executed immediately. For example, if you type in this little program:
<lang tcl>puts "Hello World"</lang>
You will get this message printed out:
Hello World
before another prompt symbol. Congratulations! You've just run your first Tcl code.
If you're using ActiveTcl, you can also try typing these examples into the Tkcon prompt. Tkcon's very slightly different, but for most Tcl programs it works just the same.
When running Tcl 8.6, change the tclsh8.5/tclsh85 to be tclsh8.6/tclsh86. If you want the Tk package as well because you're working on writing a GUI, it is often easier to use wish instead of tclsh (with appropriate version number suffix), though it's still the same language. It just has some extra commands.
Running your first Tcl program
Now save that same command in a text file called hello.tcl
. Any simple text editor will do (but not a word processor!); your author often uses Emacs for this, and it comes with automatic syntax highlighting for Tcl code.
To run that saved code, type one of these:
tclsh8.5 hello.tcl On Linux/OSX tclsh85 hello.tcl On Windows
The code in the file will be executed (printing the message to the screen) and then it the Tcl interpreter will exit. There you go, your first full Tcl program.
Going Further
If you're writing a larger program, you might want to use an IDE. The main two IDEs for Tcl are ActiveState's Komodo (commercial) and Eclipse with the appropriate DLTK module (free to use).
For a range of interesting Tcl programs and techniques beyond what is here on Rosetta Code, check out The Tcler's Wiki.
Documentation for many versions of Tcl is also online, which can be a handy supplement to your system docs.
The computer has a basic interpreter build into rom, so there is no need to install an software before entering a program. Switch on the computer. You should see a message as follows:
(C) 1982 Sinclair Research Limited.
Press the number 1 key followed by the number 0 key. (Note this is not the same as the letter O). Now press the P key. This should cause the keyword PRINT will appear in full. The computer knows that a keyword is required, and behaves accordingly. The flashing K cursor indicates that a keyword is expected. You should now see:
10 PRINT
followed by a flashing L cursor. The computer is now in letter entry mode, and is no longer expecting a keyword. Hold down the symbol shift key, and press the P key again. This time you should get a doublequote symbol. Let go of the symbol shift key.The screen should look as follows:
10 PRINT "
Now let go of the symbol shift key, and hold down the Caps Shift key. Press the letter H key. You should now get a capital H. Let go of the Caps Shift key and type the letters ELLO. Now press symbol shift again and press the P key, to produce another doublequote symbol.
You have now typed the first line of the program. Press the ENTER key. The program line will now appear at the top of the screen as follows:
<lang zxbasic>10 PRINT "Hello"</lang>
The cursor returns to a flashing K indicating that a keyword is expected again. Press the letter U. We now get the keyword RUN followed by a flashing L cursor. This time we have not entered a line number, because we want the command to be executed immediately. Press ENTER. The program will run and you should see the following:
Hello
0 Ok 10:1
You have just created and run your first program.