Lisp Programming Interview Questions and Answers
by Mohammed, on May 18, 2018 1:06:05 PM
Q1. What is Lisp Programming ?
Ans: Lisp is the second-oldest high-level programming language after Fortran and has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme.
Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).
Q2. Why use LISP?
Ans: In short, no single improvement you can make to your AutoCAD system will save you more time, effort, and money. You can spend thousands on the latest generation computers, the fastest video cards, and so on, but that won't make nearly as big a difference as automating your system with software. With an arsenal of LISP routines, you will send accuracy, consistency, and productivity soaring while greatly reducing the stress and strain of CAD operation. The right software is the key, and there is no amount of software you can buy that beats being able to program AutoCAD yourself with as many tailor-made routines as you want. And that is exactly what the LISP Generator enables you to do.
Q3. Why LISP is used for Artificial Intelligence?
Ans: LISP is used for Artificial Intelligence for following reasons
- It supports the symbolic programming, and old AI was based on symbols
- LISP is powerful. The code or data distinction is weaker, so it feels more extensible than other programming languages which make it feels like a domain specific language
- It is an excellent prototyping tool and good at tackling problems
Q4. What is a "Lisp Machine" (LISPM)?
Ans: A Lisp machine (or LISPM) is a computer which has been optimized to run lispefficiently and provide a good environment for programming in it. The original Lisp machines were implemented at MIT, with spinoffs as LMI (defunct) and Symbolics (bankrupt). Xerox also had a series of Lisp machines (Dandylion, Dandytiger), as did Texas Instruments (TI Explorer). The TI and Symbolics Lisp machines are currently available as cards that fit into Macintosh computers (the so-called "Lisp on a chip").
Optimizations typical of Lisp machines include:
- Hardware Type Checking. Special type bits let the type be checked
efficiently at run-time.
- Hardware Garbage Collection.
- Fast Function Calls.
- Efficient Representation of Lists.
- System Software and Integrated Programming Environments.
Q5. What is the "minimal" set of primitives needed for a Lisp interpreter?
Ans: Many Lisp functions can be defined in terms of other Lisp functions.
For example, CAAR can be defined in terms of CAR as (defun caar (list) (car (car list))) It is then natural to ask whether there is a "minimal" or smallest set of primitives necessary to implement the language.
There is no single "best" minimal set of primitives; it all depends on the implementation. For example, even something as basic as numbers need not be primitive, and can be represented as lists. One possible
set of primitives might include CAR, CDR, and CONS for manipulation of S-expressions, READ and PRINT for the input/output of S-expressions and APPLY and EVAL for the guts of an interpreter. But then you might want to add LAMBDA for functions, EQ for equality, COND for conditionals, SET for assignment, and DEFUN for definitions. QUOTE might come in handy as well. If you add more specialized datatypes, such as integers, floats, arrays, characters, and structures, you'll need to add primitives to construct and access each.
AWKLisp is a Lisp interpreter written in awk, available by anonymous ftp from ftp.cs.cmu.edu:/user/ai/lang/lisp/impl/awk/. It has thirteen built-in functions: CAR, CDR, CONS, EQ, ATOM, SET, EVAL, ERROR, QUOTE,COND, AND, OR, LIST.
Q6. How data types are categorized in LISP?
Ans: In LISP, data types are categorized as
- Scalar Types: Number types, Characters, Symbols, etc.
- Data Structure: list, vectors, bit-vectors and strings
Q7. What is the programming structure for LISP?
Ans: LISP programming structure is composed of symbolic expressions or s-expressions. The s-expression consists of three valid objects
- Atom: It is a number or string of contiguous characters
- Lists : A list is a sequence of atoms or other lists enclosed in parentheses
- String: A group of characters enclosed in double quotation marks is referred as String.
LISP programs can be either run on an interpreter or as a compiled code
Q8. What if I get interrupted?
Ans: You are free to come and go from the LISP Generator and do whatever you want in AutoCAD while you are in the middle of creating a program. There are helpful tools in case you forget things like the names of variables you defined.
Q9. Can I save my programs to files?
Ans: Yes, absolutely, and the files are standard LISP code that will run on any AutoCAD system.
Q10. How to pass commands to LG3?
Ans: By selecting general operations from the tools menu. You can think of the tools as building blocks - each tool corresponding to several lines of LISP code. The tools you use and the order in which you select them defines what your program does.
Q11. Explain what is slot and what are the most commonly used slot options?
Ans: Slots are nothing but variables that stores data or fields. A slot description has the form, where each option is a keyword followed by name, expression and other options.
The most commonly used slot options are:
Q12. Explain What Is The Ouput Like?
Ans: LG3 writes easy-to-read, fully indented AutoLISP programs loaded with detailed comments in English that explain what all of the LISP code is doing. The files are standard “.LSP” files. You can view, edit, or print them with any editor, and run them on any AutoCAD system with or without the Generator.
Q13. Is it possible to call LISP functions from other languages?
Ans: LISP provides a “call-back” function, when programmer associates a foreign language function name with a LISP function, it is linked with these call-back functions. With foreign function programmer must supply the result data types and argument, so that LISP may perform conversions at the interface.
Q14. Mention what are the three functions required by LISP?
Ans: For defining functions, macro named defun is used, it needs three arguments
- Name of the function
- Parameters of the function
- Body of the function
Q15. What is REPL in context of Node?
Ans: REPL stands for Read Eval Print Loop and it represents a computer environment like a window console or unix/linux shell where a command is entered and system responds with an output. Node.js or Node comes bundled with a REPL environment. It performs the following desired tasks.<
Eval - Takes and evaluates the data structure
Print - Prints the result
Loop - Loops the above command until user press ctrl-c twice.