Ask Programming Language Expert

PLC: Homework

The goal of this homework is to explore a little untyped functional programming using elisp, the version of the LISP programming language supported by the emacs text editor.

Basics of elisp programming

All coding in this assignment will be in elisp. emacs (and also the internet) provides quite a bit of good documentation about elisp. We will also be looking at this in class March 21 and 23. Some useful commands for basic elisp programming:

Control-h k tells you what elisp command is executed for the keystroke you enter right after typing Control-h k.

Control-h f gives you documentation about the elisp function you name.

Contrl-h v gives you documentation about an elisp variable you name.

Meta-: (type \meta", which is often bound to the \alt" key, or else the escape key always works for meta; and then type a colon): this lets you enter an elisp expression to be evaluated.

Control-Meta-x If your cursor is sitting in a function definition in a .el file (within emacs), then this will actually add that function definition to elisp, so you can then call it using Meta-:.

To define a new elisp function, the syntax is

(defun NAME(ARGS) DESCRIPTION CODE)

where NAME is the name of your function, ARGS is a list (separated just by spaces) of any input variables to the function, DESCRIPTION is a double-quoted string giving a description of the function, and CODE is then the code for the function.

2. Basic elisp programming

In a file called basic.el, write functions to do the following (of course you should test them in a sample buffer). I am giving some hints about how to do these tasks, by referencing existing elisp functions you can use. (These functions are already defined in elisp; use Control-h f, as described above, to learn more about these functions.)

1. goto-middle which should cause your cursor to jump to the middle character of the buffer. You can move the cursor using the function goto-char and you can find the beginning and ending characters of the buffer using (point-min) and (point-max) respectively.

2. switch-halves which should switch the first half of your buffer's text with the second half. You can use the function kill-region to cut a region of text, and yank to paste it back.

3. capother which should capitalize every other word in the buffer, starting from the beginning (point-min) to the end of the buffer (point-max). To capitalize a region of text, you can use upcase-region.

3. Extending an XML navigation mode

Thanks to some amazing software called se-mode (\structured editing mode") written by PLC alum Carl Olson, we can pretty easily turn emacs into an IDE for a language, if we have a backend parser for that language. For this problem, we will do this for basic XML. First, compile mainx.agda. This is the backend tool that will parse XML and send to the frontend (emacs mode) an abstract description of the parse tree. The se-mode code in the frontend will assemble a parse tree internally from that abstract description, and then provides commands for the user to navigate through the parse tree. To see what mainx is sending to the frontend, you can run mainx and just type in the name of a .xml file like AUFLIA.xml (provided with hw8). You will see a dump of a bunch of information.

For this problem, you will just be modifying xmlnav-mode.el. First, you need to configure emacs so it knows about this new mode. To do that, copy the se-mode directory and all its files into your hw8 directory. It is important that you have an se-mode directory as a subdirectory of your hw8 directory. Put xmlnav-mode.el and the mainx executable in your hw8 directory (not the se-mode subdirectory). Then open your .emacs file (type Control-x Control-f in emacs, and then type ~/.emacs). Add the following commands somewhere in the .emacs file (where PATH-TO-HW8-DIRECTORY should be the path on your computer to your hw8 directory) and then save it, and restart emacs: (add-to-list 'load-path "PATH-TO-HW8-DIRECTORY") (require 'xmlnav-mode)

Now open the file AUFLIA.xml, included with the hw8 files. If all goes well, you should be able to type \Meta-s" (alt-s or escape-s), and you should see \(xmlnav navi)" displayed in the mode line towards the bottom of your emacs window. You can then use \p", \n", \f", and \b" to navigate through the text following the structure of the parse tree.

3.1 Showing errors

Modify xmlnav-mode-update-mini in xmlnav-mode.el so that if the current selected parse-tree node has an error attribute, the error is shown as a message. To do this:

(se-mode-selected) will return the current selected node, if any.

se-term-data, given a node, will return the attributes associated (by the backend) with that data.

The assoc function will let you look for an 'error attribute in the attributes returned by se-term-data.

if there is an 'error attribute, you can use message to print out the data which is part of that attribute. The attribute is a pair that looks like 'error . m. To access the second component of a pair in elisp, you use the cdr function.

You should see an error at the very last end tag of AUFLIA.xml, which does not match the start tag.

3.2 Hiding elements

Modify xmlnav-mode-toggle-hidden so that it toggles whether the selected node (if there is one) is invisible or not. To get, set, or clear the invisibility property, respectively, you use get-text-property, put-text-property and remove-text-properties. There is good documentation about text properties here:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Properties.html

If there is no 'invisible property for the currently selected node, you should set the 'invisible to 'xmlnav-hide. I have already added code in xmlnav-mode.el to tell emacs to display invisible text with an ellipsis (...) if the 'invisible property is set to 'xmlnav-hide. If there is a 'invisible property for the currently selected node, you should remove it with remove-text-properties.

After this is done, call se-navigation-mode 1 to restart the navi mode (which shuts o
automatically if the buffer is modified), and also call se-mode-select with the node that was selected at the start of the call to xmlnav-mode-toggle-hidden, so it will be reselected.

Attachment:- Assignment.zip

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92248471
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in Programming Language

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As