Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 4303 Concept of Programming Languages Purpose: Introduction to Functional Programming/LISP This document provides instructions about using Lisp and examples of the design of Lisp

CS 4303 Concept of Programming Languages

Purpose: Introduction to Functional Programming/LISP

This document provides instructions about using Lisp and examples of the design of Lisp functions. For more information about Lisp programming, look at the links in Lisp_sources.html.

TASK 1: Using the LISP interpreter

Install Allegro-Lisp software (https://franz.com/downloads/clp/survey) on your computer. You may explore the features of the software by trying to run simple lisp functions.

Some of the primitive functions allowed in Lisp are listed below. It would be a very good practice if you try these primitive functions on the system. You may look at the other primitive functions supported by Lisp by looking at any book on common lisp.

EXAMPLE:

LC-USER 1>(car '(a b c)) <in>

A <out>

LC-USER 2>(eq 'x 'y) <in>

NIL <out>

LC-USER 3>(setq x '(a b c)) <in>

(A B C)

To learn more about LISP programming, click on the following link:

http://cms.dt.uh.edu/Faculty/LinH/courses/CS4303/LISP/Lisp_sources.html

TASK 2: More practice:

In each of the following questions predict the results first and then use the Lisp interpreter to check your answers:

6. Write a function DOT-PRODUCT that takes two lists, each list has three numbers (elements), and produces the dot product of the vectors that they represent. For example,

->(DOT-PRODUCT '(1.2 2.0 -0.2) '(0.0 2.3 5.0))

->3.6

The answer for this question can be found in file DOT-PRODUCT.LSP in the same directory. The key for designing a lisp function is using recursion.

7. Write a function COUNT-NUMBER that counts the number of numbers that occur in a list. It should work like this:

->(COUNT-NUMBER '(A 2.3 B 5 4.53 C F))

->3

Hint: To determine whether s-expression is a number or not, use numberp function. The following examples show how numberp works:

-> (numberp 5)

-> T

-> (numberp 5.5)

-> T

-> (numberp T)

-> nil

-> (numberp (A B))

-> nil

8. Write a function NEW-LIST that takes a number as its argument and constructs a list of that length containing all Ts. For example,

-> (new-lit 5)

-> (T T T T T)

9. The Lisp function LENGTH counts the number of elements in the top level of a list. Write a function ALL-LENGTH of one argument that counts the number of atoms that occur in a list at all levels. Thus, the following lists will have the following ALL-LENGTHs.

(A B C) => 3

((A (B C) D (E F)) => 6

(NIL NIL (NIL NIL) NIL ) => 5

Turn in your responses to these questions 6-9 in one single Lisp program file (.lsp or .lisp file)

Can you type it out on source code.

I am having a hardtime grasping the situtation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Aware of differences in the role of employees unions.

Answered: 1 week ago