emacs/lisp function  Write a function in Lisp that takes one parameter which we can assume to be a list. The function should print all the elements of the list using the function princ and a space between them. Use the function mapc for this purpose.Show a few examples of testing this function. Show one example using the function apply and one using the function funcall.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

 emacs/lisp function 

Write a function in Lisp that takes one parameter which we can assume to be a list. The function should print all the elements of the list using the function princ and a space between them. Use the function mapc for this purpose.Show a few examples of testing this function. Show one example using the function apply and one using the function funcall.

Expert Solution
Explanation

1) Below is LISP program that defines a function that takes one list parameter and print all the elements of the list using the function princ and a space between them.

  • It first defines defines a new function called print-list that takes a single parameter, lst, which is a list.
    • It then uses the mapc function to apply a lambda function to each element of the list, which prints the element using the princ function and a space using another princ function call.
    • Add a new line after list is printed using terpri
  • Then there a few examples of testing this function and display the list to console
    • using normal function call
    • using the function apply
    • using the function funcall

2) Save this program in lsp file and run

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning