TWiki> INFBase Web>AnswersPage>YearOne (15 Oct 2012, Main.s1245526)EditAttach

Quotas

If you can't get into your account, and have tried on several machines, there is a strong chance that you are over your quota. Get a lab demonstrator to log you via the alternative console login method and remove some files.

Haskell Mode for Emacs (Windows)

This explains how to use Haskell mode in Emacs on a Windows machine.

1. Download the latest from http://projects.haskell.org/haskellmode-emacs/

2. Navigate to C:/users/your_username/Appdata/Roaming/.emacs

Note: .emacs is a hidden file, so you must change your settings so that hidden files are displayed (right click -> properties)

3. Open .emacs with notepad

4. Add the following line to the bottom of the file:

load path_to_haskell_mode_folder/haskell-mode/haskell-site

"haskell-site" is the actual file that emacs needs to load for haskell mode to work.

5. Save the file and close it.

Accessing DICE from a windows home machine

You have six possible choices:

1. Install putty ssh client ( http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html ). Enter the host name (ssh.inf.ed.ac.uk) and select port 22 (ssh). You'll have to ssh on to student.login. You will then be able to edit files using the command line (e.g. using vim or nano).

2.[Not recommended] If you want to use a graphical text editor, you'll need to install an x-server, either xming ( http://www.straightrunning.com/XmingNotes ) or cygwin ( http://www.cygwin.com ).You'll also have to forward X11 ports (choose an option in putty).

3. Edit you files locally (e.g. using notepad or whatever) and copy them using a SCP client (such as winSCP http://winscp.net/eng )

4. Try to figure out how to run it locally (e.g. install haskell for windows?) you'll still need an SCP client (above)

5. Install ubuntu locally (e.g. dual boot), then you can just use Places->Connect to server... from the gnome menu bar.

6. Install VPN and AFS: https://wiki.inf.ed.ac.uk/DICE/AFSWinXP

C

Almost every day at InfBase we get questions about programming in C. On this page you can find answers to some of the more common questions, along with longer articles about trickier things. This is intended to be in no way an exhaustive guide; think of it as more of a handbook to basic tasks.

A very small handbook.

Pointers
A (comparatively) short guide to pointers, addresses, and references.
Booleans
A (tragically) brief tour of boolean operators and types.
Arguments
Getting things out of function arguments.
Magic
Interesting C hacks.
-- TrevorFountain - 05 Dec 2008

Java Exceptions

Okay, so a common problem that people come up against in java when they are starting out is the urge to recall a method from inside an exception thrown in that method. For instance one might be tempted by something like this:-

public void method(int par){
    try{
        doSomethingThatBreaks(par);
    }

    catch(Exception e){
      method(par+1);
    }
}

The intuition is that if the parameter is different then it should be possible to do this, the problem is that java exceptions dont work in this way. Put simply you can't do this and the code will fail. A better approach to this type of task would be to try something like this:-


public void method(int par){
    if(method_prime(par)==0){
          method_prime(par+1);
    }
}


public int method_prime(int par){
    try{
        doSomethingThatBreaks(par);
        return 1;    
    }

    catch(Exception e){
      return 0;
    }
}

If you generate different types of exception, you can do the following:

try {
   ...
} catch (ExceptionTypeA name) {
   ...
} catch (ExceptionTypeB name) {
   ...  
}  

However, if you want to try one statement after having tried and failed another statement of the same exception type, you should nest the try-catch block inside the catch block like the following:

try {
   ...     
} catch (ExceptionTypeA name) {
  try {
     ...   
  } catch (ExceptionTypeA name) {
     ...
  }  
}  

You can of course nest try-catch inside catch as many times as you need.

-- PhilMGraham - 28 Oct 2008

Regular Expressions in Python

There were some questions regarding REGEX in Python. People who have difficulties with it might want to look at the following tutorial: http://www.amk.ca/python/howto/regex/ . It's really worth consulting when you are not sure about how to construct/decipher certain patterns.

-- KisuhAhn - 06 Nov 2008

Haskell and List difference

Someone asked about how to find the difference between the elements of two integer lists.

Using Recursion

The function is of the form

subtractLists :: [Int] -> [Int] -> [Int]

We can take the first element from each list by matching to (m:ms) and (n:ns). The difference between elements m and n ("m-n") can be joined onto a new list, with the remaining elements generated by another call to subtractLists:

c :: [Int] -> [Int] -> [Int]

c (m:ms) (n:ns) = m-n : c ms ns

c _ [] = []

c [] _ = []

Without (explicit) recursion

The pair of lists can be made into a list of tuples, by using the zip function, for example:

*Main> zip [1,2,3] [4,5,6]
[(1,4),(2,5),(3,6)]

Each item from a list can be taken and processed into a new list using the following syntax:

[x|x <- [1,2,3]]

Putting the two together, we can perform the operation by zipping the two lists, then taking off one tuple at a time, and calculating the difference:

[x-y|(x,y) <- zip [1,2,3] [4,5,6]]

This can be put into a function file as:

diffFn xs ys = [x-y | (x,y) <- zip xs ys]

It can also be achieved by using map or zipWith:

subtractLists xs ys = map f (zip xs ys)
where f (x,y) = x-y

or

subtractLists = zipWith (-)

Advice provided by Willem Heijltjes.

-- MikeSmith - 20 Oct 2009 & 27 Oct 2009

Topic revision: r13 - 15 Oct 2012 - 13:27:16 - Main.s1245526
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
This Wiki uses Cookies