# Tagged Questions

Lisp is a (family of) general purpose programming language(s), based on the lambda calculus, and with the ability to manipulate source code as a data structure.

676 views

### Union-set operation for unordered-list representation of sets

One way to represent a set is as a list of its elements in which no element appears more than once. The empty set is represented by the empty list. In this representation, element-of-set? ...
306 views

### Standard Algebraic Derivative Calculator [SICP ex. 2.58 part b]

I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP: Exercise 2.58. Suppose we want to modify the differentiation program so that it ...
372 views

### On Implementing a Lisp

Background: This began with James Colgan's Lisp-Dojo for Ruby. My implementation can be found here. I then moved on to Write yourself a scheme in 48 hours. This question has to do with one of the ...
202 views

### Extend sums and products functions

Exercise 2.57. Extend the differentiation program to handle sums and products of arbitrary numbers of (two or more) terms. Then the last example above could be expressed as ...
103 views

### Extending basic differentiator to handle more kinds of expressions

Exercise 2.56. Show how to extend the basic differentiator to handle more kinds of expressions. For instance, implement the differentiation rule by adding a new clause to the deriv ...
439 views

### (Scheme) [SICP ex. 2.54] Define equal?

Exercise 2.54. Two lists are said to be equal? if they contain equal elements arranged in the same order. For example, ...
151 views

### Adding, subtracting, and multiplying a vector by a scalar

Exercise 2.46. A two-dimensional vector v running from the origin to a point can be represented as a pair consisting of an x-coordinate and a y-coordinate. Implement a data abstraction ...
145 views

### (Scheme ) [SICP ex. 2.45] Write a general purpose “split” function {for SICP's imaginary language}

From SICP 2.2.4: The textbook has already defined a function (right-split ...) as follows: ...
654 views

### Eight-queens puzzle

Figure 2.8: A solution to the eight-queens puzzle. The eight-queens puzzle'' asks how to place eight queens on a chessboard so that no queen is in check from any other (i.e., no two ...
739 views

### Find all distinct triples less than N that sum to S

Exercise 2.41. Write a procedure to find all ordered triples of distinct positive integers i, j, and k less than or equal to a given integer n that sum to a given integer s. ...
142 views

### (Scheme) [SICP ex. 2.40] unique-pairs

From the section called Nested Mappings Exercise 2.40. Define a procedure unique-pairs that, given an integer n, generates the sequence of pairs (i,j) with 1< j< i< n. Use ...
376 views

### LISP-like list class.

So, here's my code: ...
700 views

### (scheme) [sicp ex. 2.39] reverse in terms of fold-right and fold-left

Exercise 2.39. Complete the following definitions of reverse (exercise 2.18) in terms of fold-right and fold-left from exercise 2.38: ...
2k views

### Matrix multiplication and dot-product

Exercise 2.37. Suppose we represent vectors v = (vi) as sequences of numbers, and matrices m = (mij) as sequences of vectors (the rows of the matrix). For example, the matrix is ...
311 views

### Redefine count-leaves as an accumulation

Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: ...
763 views

### Abstract tree-map function

Exercise 2.31. Abstract your answer to exercise 2.30 to produce a procedure tree-map with the property that square-tree could be defined as ...
186 views

### Square-tree using maps and recursion

Define a procedure square-tree analogous to the square-list procedure of exercise 2.21. That is, square-list should behave as follows: ...
391 views

### (scheme) [SICP ex. 2.27] deep-reverse

Exercise 2.27. Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements ...
1k views

### A definition of for-each

Exercise 2.23. The procedure for-each is similar to map. It takes as arguments a procedure and a list of elements. However, rather than forming a list of the results, for-each just ...
672 views

### Filter a list of integers by parity (SICP ex. 2.20)

Exercise 2.20. The procedures +, *, and list take arbitrary numbers of arguments. One way to define such procedures is to use define with dotted-tail notation. In a procedure definition, ...
1k views

### Design a procedure to reverse a list

SICP exercise 2.18 asks the following: Exercise 2.18. Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order: ...
555 views

### Church Numerals - implement one, two, and addition

Given the following exercise: Exercise 2.6. In case representing pairs as procedures wasn't mind-boggling enough, consider that, in a language that can manipulate procedures, we can get ...
253 views

### (Scheme) [SICP ex. 2.5] Represent pairs of nonnegative integers using 2^a * 3^b

Given the following exercise: Exercise 2.5. Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the ...
310 views

### (Scheme) [SICP ex. 2.2] Midpoint of a segment

From SICP: Exercise 2.2. Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ending point. Define a ...
274 views

### (Scheme) [SICP ex. 2.1] Make a version of make-rat that handles positive and negative arguments

Given the following task from SICP Exercise 2.1. Define a better version of make-rat that handles both positive and negative arguments. Make-rat should normalize the sign so that if the ...
612 views

### (scheme) [SICP ex. 1.37] Infinite Continued Fraction - iterative and recursive

Given the following exercise: Exercise 1.37. a. An infinite continued fraction is an expression of the form As an example, one can show that the infinite continued fraction expansion ...
808 views

### (Scheme) [SICP ex. 1.33] Filtered-Accumulate

Given the following task: Exercise 1.33. You can obtain an even more general version of accumulate (exercise 1.32) by introducing the notion of a filter on the terms to be combined. That ...
574 views

### (Scheme) [SICP ex. 1.32] Show that Sum and Product are both examples of Accumulation

Given this task: Exercise 1.32. a. Show that sum and product (exercise 1.31) are both special cases of a still more general notion called accumulate that combines a collection of terms, ...
693 views

### (Scheme) [SICP ex. 1.29] Integral using Simpson's Rule

As an answer to this problem: Exercise 1.29. Simpson's Rule is a more accurate method of numerical integration than the method illustrated above. Using Simpson's Rule, the integral of a ...
415 views

### (Scheme) [SICP ex. 1.31] Write a _product_ function analogous to _sum_

Exercise 1.31. a. The sum procedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures.51 Write an analogous procedure ...
512 views

### [SICP ex. 1.30] Iterative Sum

Given the following recursive definition of sum: (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) ...
632 views

### GCD - is this solution iterative?

Using the property that GCD(a, b) = GCD(b, r) where r is the remainder when you compute (a / b), you can write a recursive function as follows: ...
350 views

### (scheme) [SICP ex. 1.17] Multiplication in terms of Addition

Given the following task: Exercise 1.17. The exponentiation algorithms in this section are based on performing exponentiation by means of repeated multiplication. In a similar way, one ...
576 views

### Iterative exponentiation process

From SICP's 1.24: (Exponentiation) (you may need to click through and read ~1 page to understand) Exercise 1.16. Design a procedure that evolves an iterative exponentiation process that ...
1k views

### (scheme) Pascal's triangle

1 1 1 1 2 1 1 3 3 1 etc. What do you think of this solution for computing Pascal's triangle? ...
395 views

### Both an Iterative and a Recursive f(x)

A function f is defined by the rule that f(n) = n if n < 3 and f(n) = f(n-1) + 2f(n-2) + 3f(n-3) if n>=3. Write a recursive and an iterative process for computing f(n). I wrote the ...
1k views

### Cube root (Newton's method)

Newton's method for finding cube roots states that for any given $x$ and a guess $y$, a better approximation is $\dfrac{(\dfrac{x}{y^2} + 2y)}{3}$. What do you think of this code for finding a ...
656 views

### (Scheme) Use Newton's Method to compute sqrt(x)

Given the following task: Use Newton's method to compute the square root of a number. Newton's method involves successive approximation. You start with a guess, and then continue averaging ...
2k views

### Sum of squares of two largest of three numbers

Given the following problem (SICP Exercise 1.3): Define a procedure that takes three numbers as arguments and returns the sum of squares of the two largest numbers. I wrote the following ...
382 views

### (Common Lisp) Is f(n) = n^2 + 3n + 5 not ever divisible by 121?

Given the following problem: ...
86 views

### (Common Lisp) Tabulate k = 2^n Minimizing Multiplication

Given the following problem: ;3.3 Tabulate the function k = 2^n for n = 1..50. ;Do this for the fewest possible multiplications.[3] I wrote this answer: ...
888 views

### (Common Lisp) Palindrome-p

3.23 Palindromes. A palindrome is a number that reads the same forwards and backwards, like 12321. Write a program that tests input integers for the palindrome property. Hint.This should ...
155 views

### (Common Lisp) Find epsi

4.2 Machine Epsilon. Find the floating point number epsi that has the the following properties: 1.0+epsi is greater than 1.0 and Let m b e any number less than epsi. Then 1.0+m is ...
227 views

...
307 views

### Common Lisp - Abstract the (duplicate?) behavior between “sort” and “replace”

I have written these two functions that have a similar process. The first is meant to "split" a string on a given character and the second is meant to "replace-all" instances of a character in a ...
531 views

### Common Lisp - Solve a Cryptoarithmetic Problem

This code is intended to find all possible solutions to a cryptoarithmetic problem. The description of the problem I was trying to solve is here: ...
1k views

### (Common Lisp) Print an Integer and its Digits Reversed

This common lisp program is an exercise to print an integer and its digits reversed to the screen. ...
498 views

### Common Lisp - Calculate the weekday from a date (M-D-Y)

This Common Lisp exercise is to write a program that can calculate the weekday given a string of the format "M-D-Y." It was more challenging than I expected. If you have suggestions about how to ...