CMSC 330, Spring 2013

Organization of Programming Languages

Eclipse Plugins for Ruby and OCaml

Ruby

  1. If you haven't already done so, install Ruby 1.8.6 and Eclipse.
  2. From Eclipse's main menu, choose Help Install New Software
  3. Next to the Work with field, choose Add...
  4. Choose a name like dltk (for Dynamic Languages Toolkit) and for location use http://download.eclipse.org/technology/dltk/updates/. Click OK.
  5. Expand the "Dynamic Languages Toolkit (DLTK) 2.0" subtree, and check the following items:
    • Dynamic Languages Toolkit - Core Frameworks
    • Dynamic Languages Toolkit - Core Frameworks SDK
    • Dynamic Languages Toolkit - Ruby Development Tools
    • Dynamic Languages Toolkit - Ruby Development Tools SDK
  6. Click Next, Next, I accept, Finish, Yes to restart to accept the license and install the software.
  7. Once Eclipse has restarted, to open the Ruby perspective, choose Window Open Perspective Other and select Ruby.
  8. Now set up the ruby interpreter: Choose Window preferences, expand the ruby subtree, and select interpreters.
  9. Click Add..., Browse... and navigate to your ruby executable (e.g. C:\ruby\bin\ruby.exe). Click OK, OK.
  10. Now you are ready to create a Ruby project: File New Ruby Project.
  11. Give it a name like myfirstruby and click Finish.
  12. Right click on the myfirstruby folder at the left, choose new empty ruby script and name it myfirstruby.
  13. In the editor region, type something like:

    puts "Just a whisper. ".concat("I hear it in my ghost.")

  14. Select Run Run As Ruby Script. If all is well, you will see the output in the console.

The OCaml plugin has a nice ready-made interpreter built right into the Eclipse console (see below). Unfortunately this does not appear to be the case for Ruby. You are probably better off using irb by itself, but it is possible to get a poorly formatted irb running in the Eclipse console:

  1. Choose Run External Tools External Tools Configurations ....
  2. Right click Program and select New.
  3. Give it a name like irb_conf, and for location, Browse File system... and navigate to your ruby install directory again. Select the irb executable. On windows I had two files, irb (no extension) and irb.bat. The former gives an error but the latter runs.
  4. Click Apply and Run. Now you can use irb in the Eclipse console, although the is missing from the prompt and all of your input gets echoed.

OCaml

  1. If you haven't already done so, install Eclipse. As for OCaml, version 4.00 was reported to have issues with Eclipse. It is recommended that you use 3.11.0 for Windows and 3.12.0 for Mac OS X.
  2. In Eclipse, click Help Install New Software...
  3. In Work with, enter http://www.algo-prog.info/ocaide then click Add, OK.
  4. Check OcaIDE and click Next, Next, I accept, Finish to accept the license and install the software. Eclipse will prompt you to accept unsigned code, you can click Yes.
  5. Click Yes to restart. After Eclipse restarts, choose Window Open Perspective Other... OCaml.
  6. Go to Window Preferences (Mac OS X users, go to Eclipse Preferences).
  7. Expand the OcaIDE subtree and then click on Paths. If all the paths in this panel (except for possibly make and omake) are already filled in, then continue to the next step. Otherwise, click Browse next to OCaml Binaries Directory and choose the "bin" directory inside your OCaml installation directory (for example, C:\Program Files\ObjectiveCaml\bin). Then click Apply. Eclipse should fill in additional path values for you (ocaml, ocamlc, etc).
  8. Under Other tools OCaml lib path, click Browse and choose the "lib" directory inside your OCaml installation directory. Press OK to close the dialog.
  9. Near the top right of Eclipse, you should see an OCaml button and Java button, with the Ocaml button selected. If you only see the Java button, click the button to the left which looks like a window with a yellow "+" sign, and then double click on "OCaml". Now you are in OCaml mode.
  10. Click the "Ocaml Toplevel" tab at the bottom of the workspace. Type into the prompt (do not type on the same line as the #; type below it at the bottom of the tab):

    print_endline "hello world";;

    . You should see the output:

    hello world
    - : unit = ()

Creating and running OCaml projects in Eclipse

To create and run your OCaml projects, follow the steps below. If you are on windows and do not have Cygwin installed, you may get error messages about Cygwin at several steps, but you can safely ignore them (just click OK).

  1. Download the project files to your computer and note the file location.
  2. In OcaIDE within Eclipse, click File New OCaml Managed Project. Enter a name for "project name" and click Finish.
  3. Right click on the newly created project folder and click Import... General File System Next.
  4. Click Browse, navigate to your download folder, and select the files to import.
  5. Click Finish. Now you can expand the project folder in Eclipse to see the files that were copied into your workspace as well as some OcaIDE-generated ones which are outlined in red.
  6. When you are ready to submit, make sure that you upload the final versions from your eclipse workspace, not the original versions you downloaded.
  7. To run your project, right click on the project folder and select Properties.
  8. Click Ocaml Project.
  9. Under "Make executable for:" check off the files that you want to compile. Leave "Compilation mode" as byte-code. Press Apply and OK to close the dialog.
  10. In your project, you should now see some new .exe files. If not, there is probably a compilation error in your code, so use the Toplevel to work out the kinks and try again.
  11. To run the executable, right click on it in Eclipse and select Run As OCaml Executable. The output of the program should appear in the Console tab.

Web Accessibility