Question

In: Computer Science

Either the iftcase macro in Emacs Lisp which can be used as follows : (iftcase <exp>...

Either the iftcase macro in Emacs Lisp which can be used as follows :

(iftcase <exp>

((1 3 5) <exp1>)

((4) <exp2>)

(_ <exp3>))

Which will mean : first evaluate exp then evaluate exp1 if exp returns 1, 3, or 5; otherwise evaluate exp2 if exp returns 4; otherwise evaluate exp3

  1. Show the desired expansion for this code.
  2. Identify the possible risks of excessive repeated evaluation (similar to passing by name) and name capture , if the macro is defined too naively
  3. Give a definition of this macro which does not suffer from these problems.

Solutions

Expert Solution

Emacs LISP is a programming language which is used to perform data string manipulation, It is also a scripting language developed by Emacs. It is one of the oldest language which is still in use for the artificial intelligence now'a days. It can read the entire file through Emacs buffer instead of reading file at a time.

If case in Emacs LISP:

A conditional statement "IF" can also be used in Emacs programming. This is used to solve conditional problems by applying certain conditions (conditions can be as per the requirement). The main idea behind the processing of conditional statement "IF" is like if the condition defined with in the "IF" statement is true then whatever is mentioned with in the "IF" should be evaluated otherwise not evaluated.

Syntax of conditional statement (IF):

If (condition){

// statement 1;

}else{

// statement 2;

}

Example: To check whether a number is even or odd, "IF" logic is given as:

If (x % 2 == 0){

"Even Number";

}else{

"Odd Number";

}

This is the easiest way to get the problem solution but in the case of multiple expressions it requires looping statements too. There are two looping statements are there in Emacs such as:

1. While loop: useful when set of code is repeated again and again.

(while (Expression)

// body...

(statement))

Like for Increament of counter through while loop:

(while (< count Number)

// body...

(set count(+1 count)))

2. Recursion: useful when function calling itself again and again.

The main problem while applying looping statement in the programming is:

  1. It creates on-off problem in the program.
  2. It creates infinite loops in case of wrong condition defined in expression.
  3. It may cause statefulness issue.
  4. It can create hidden-intent problems in the program.

The desired expansion for code:

Code given:

(iftcase <exp>

((1 3 5) <exp1>)

((4) <exp2>)

(_ <exp3>))

Code after expansion: This the code after expansion of the expression in IF statement.

(IF <exp>

((1) <exp1>

  ((3) <exp1>

((5) <exp1>)))

((4) <exp2>)

(<exp3>))


Related Solutions

Write a LISP program to play either the game "Connect Three" on a size 4x4 game...
Write a LISP program to play either the game "Connect Three" on a size 4x4 game board. Your program must use min-max search and should be invoked by the function call: > (connect-3) The game is single player, human vs the computer AI.
How can macro policy be used to combat problems of recession, overheating, and stagflation?
How can macro policy be used to combat problems of recession, overheating, and stagflation?
Assume that there are 50 units of an exhaustible resource that can be used in either...
Assume that there are 50 units of an exhaustible resource that can be used in either period 1 or period 2. The demand curve is given by: P=100-Q. The interest rate is 50%. The industry is perfectly competitive. There are no costs of extraction. a) Solve for the efficient level of output and price in period 1 and period 2 b) Suppose that the government imposes a tax of $30 per unit. Solve for the level of output and price...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in 1959. Alice 1.0 was released in 2006 from CMU, and Python in 1994. Based on what you know of the Scheme language, describe the major differences between how it works and how Alice or Python works. What advantages might Scheme have over Alice/Python? What advantages might Alice/Python have over Scheme?
Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C...
Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C * D) / S + F)             Where the values of the variables are:                         Z = 3, B = 6, C = 2, D = 5, S = 4 , F = 21             Evaluate the expression using a stack. Shows the logical representation of the evaluation process. ..............................................................................
Energy can be classified as either potential or kinetic energy. Explain how energy follows the first...
Energy can be classified as either potential or kinetic energy. Explain how energy follows the first law of thermodynamics as it goes from the sun to glucose. Clearly state when there is a transition from one form to another.
Energy can be classified as either potential or kinetic energy. Explain how energy follows the first...
Energy can be classified as either potential or kinetic energy. Explain how energy follows the first law of thermodynamics as it goes from the sun to glucose. Clearly state when there is a transition from one form to another.
Write a LISP function COUNTX which takes an atom and a list and returns the number...
Write a LISP function COUNTX which takes an atom and a list and returns the number of top-level occurrences of the atom in the list. For example: (COUNTX ‘A ‘(A (A B) B A B A (B A)) Returns the value 3, the other two A’s are not at the top level
Most analytical machines used in science can either measure absorbance of light, like the spectrophotometers used...
Most analytical machines used in science can either measure absorbance of light, like the spectrophotometers used in BioZ 151 and 152 labs, or can measure change in electrical conductance. In order to convert things like absorbance values into concentration data, a linear regression is used. In order to determine nitrite concentration in water samples, nitrite is reacted with several chemicals to produce a purple color. The absorbance of the solution is measured from known amounts of nitrite to produce a...
ind a dietary assessment tool that can be used either generally or for a specific alteration...
ind a dietary assessment tool that can be used either generally or for a specific alteration in health. You can use your favorite search engine (Google, Bing, Yahoo Search, AltaVista, to name a few). You may find the tool on a governmental database, being used by an organization or facility, or in journals and registries. You may decide to select a general tool or one that you can include in your course project for Canavan disease selected. When you have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT