Define procedure to input integers and returns the average, C/C++ Programming

Assignment Help:

The procedure +, * and list take arbitrary numbers of arguments. One way to define such a procedure is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates that, when the procedure is called, the initial parameters (if any) will have as values the initial arguments, as usual, but the final parameter's value will be a list of any remaining arguments. For instance, give the definition:

(define (f x y . z) )

the procedure f can be called with two or more arguments. If we evaluate

(f 1 2 3 4 5 6)

then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6).

Given the definition:

(define (g . w) )

the procedure g can be called with 0 or more arguments. If we evaluate

(g 1 2 3 4 5 6)

then in the body of g, w will be the list ( 1 2 3 4 5 6).

(a) Use this notation to write a procedure average that takes one or more integers and returns the average. For example:

(average 1 2 3 4 5 6 7) => 4
(average 2) => 2

(b) Write a procedure called pipeline that accepts a variable number of arguments that are procedures and returns the composition of those procedures. This is called pipeline processing. You may assume that all procedures in the pipeline accept a single argument. For example:
(define square-cubed (pipeline square square square))
; is equivalent to:
(define square-cubed (lambda (x) (square (square (square x)))))
(square-cubed 2) => 256

(c) Using your definition for pipeline from (b), write procedures for cdar, cddar and cdadr.


Related Discussions:- Define procedure to input integers and returns the average

C program to show overloading of matrix operator, C program to show overloa...

C program to show overloading of matrix operator: Write a program for matrix operator overloading. class matrix{                   private :                 int x[

Write short note on classes in c++, Introduction to Classes Object-orie...

Introduction to Classes Object-oriented programming (OOP) is a conceptual approach to design programs. It can be executed in many languages, whether they directly support OOP c

Refactoring, Refactoring Project Description: TASK 1 - DESIGN ALGORIT...

Refactoring Project Description: TASK 1 - DESIGN ALGORITHM You are required to design a suitable solution algorithm by using structured chart, pseudocode or flowchart. Thi

How the compiler arranges the several sections , Q: How the compiler arrang...

Q: How the compiler arranges the several sections in the executable image? A: The executable contained following sections: 1.      Data Section (initialized data variable sec

C code for implementation on binary heap, what is binary heap ? what is the...

what is binary heap ? what is the c code for the implementation for the binary heap

Luminous Jewels - The Polishing Game, 1. Jewels can only be removed for pol...

1. Jewels can only be removed for polishing from either end of the necklace (i.e. head or tail) 2. Once a jewel type is removed from the necklace, all other instances of the same j

What is namespace and explicit container, What is Namespace and Explicit ...

What is Namespace and Explicit container Namespace - Namespaces are used to group entities such as objects, classes and functions under a name. Explicit container.

Help finish programming assignment, how much is it to fix a small data stru...

how much is it to fix a small data struct in a sorted list that pass itemtypes. all the code is written just logical errors

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd