# 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.

573 views

...
101 views

### Quick Insert Merge Sort

I have written this code to sort a list of numbers, in increasing order. It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go ...
46 views

### FizzBuzz - officially now in CLISP

I had to jump on the bandwagon for this one. The task does a great job of helping you learn a language you're unfamiliar with. So today I present you with my version of the infamous FizzBuzz game in ...
319 views

### Searching for repeated characters in a sequence of characters

The following code solves this problem: The 3072 characters below contain a sequence of 5 characters which is repeated. However, there is a twist: one of the sequences has a typo. To be ...
65 views

### Rewrite apply function to use recursion instead

Probably the hardest part of learning lisp has been to think in the "lisp way" which is elegant and impressive, but not always easy. I know that recursion is used to solve a lot of problems, and I am ...
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: ...
67 views

### Creating an updating hash table

I'm not sure if this implementation is good enough. The function takes a vector of 1 million chars and creates a table of the sequences that pass before the next occurrence of itself. Some questions ...
832 views

### Finding the sum of all the multiples of 3 or 5 below 1000

As a Lisp (and functional programming) newbie, I wrote the following code that finds the sum of all the multiples of 3 or 5 below 1000, and I suspect that it is lousy: ...
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 ...
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 ...
553 views

### Huffman encoding successive-merge function

From SICP: Exercise 2.69. The following procedure takes as its argument a list of symbol-frequency pairs (where no symbol appears in more than one pair) and generates a Huffman encoding ...
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 ...
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: ...
53 views

### What's your opinion on this approach to creating a repetitive string in Common Lisp?

I needed to have a Lisp function that could produce a string of a certain length, created by repeated concatenations of a another string given as argument (so for example by giving 10 and "abc" i ...
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: ...
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 ...
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: ...
287 views

### Union-set for ordered representation

From SICP: Exercise 2.62. Give a (n) implementation of union-set for sets represented as ordered lists. I wrote this answer: ...
60 views

### Generic sequence splitter in Common Lisp

I wrote a function split-seq-by-n which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the ...
280 views

### Search on a binary tree

From SICP: Exercise 2.66. Implement the lookup procedure for the case where the set of records is structured as a binary tree, ordered by the numerical values of the keys. I wrote the ...
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 ...
40 views

### Accessor functions in elisp

I'm writing some simple emacs tools for visual studio solutions. I've got a function sln-process-csproj-file. This function takes the path to a project, and ...
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 ...
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 ...
166 views

### Set representation allowing duplicates

From SICP: Exercise 2.60. We specified that a set would be represented as a list with no duplicates. Now suppose we allow duplicates. For instance, the set {1,2,3} could be represented as ...
599 views

### Encode-symbol for Huffman tree

From the text: Exercise 2.68. The encode procedure takes as arguments a message and a tree and produces the list of bits that gives the encoded message. ...
118 views

### Representing a queue as a procedure with local state

From SICP: Exercise 3.22. Instead of representing a queue as a pair of pointers, we can build a queue as a procedure with local state. The local state will consist of pointers to the ...
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 ...
192 views

### Examine a list for cycles

From SICP: Exercise 3.18. Write a procedure that examines a list and determines whether it contains a cycle, that is, whether a program that tried to find the end of the list by taking ...
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. ...
365 views

### Connect Four AI (Minimax) in Clojure

I wrote a Connect Four game including a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc. But ...
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 ...
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 ...
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? ...
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 ...
166 views

### iterative copy-tree in lisp

The common lisp function copy-tree is often implemented in a recursive way, and thus is prone to stack overflow. Here is my attempt at writing an iterative version, one-pass, no stack, no ...
757 views

### Clojure Neural Network

After reading this article about Neural Networks I was inspired to write my own implementation that allows for more than one hidden layer. I am interested in how to make this code more idiomatic - ...
49 views

### Calculating series of rows to use to play a melody on 5-row Bayan Accordion

This was my first attempt at writing a program in LISP. Can anyone give any guides as to how it could be improved? The multiple loops in best-pattern seem awkward (I'd normally do that in just one ...
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, ...
51 views

### Is using defvar for a non-global variable ok?

I am calling defvar in the middle of a function definition. And so far I've always seen its use, with defparameter for global ...
134 views

### How do I avoid eval in elisp?

I have wrote a simple util to submit my code to a online judge site, how to avoid the evil function? ...
159 views

### Write a procedure stream-limit that finds

From SICP: Exercise 3.64. Write a procedure stream-limit that takes as arguments a stream and a number (the tolerance). It should examine the stream until it finds two successive elements ...
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 ...
56 views

### A small emacs-lisp snippet for opening a register in another window

I'd like to get some feedback on whether this is idiomatic elisp, whether it's any good, and any small modifications that would be useful. Thanks ...
1k views

### Finite State Machine code

I have been making this FSM today. However, as this is probably the biggest practical program I have ever written in CL, I don't know if there are some things that could be improved, or if using a ...
402 views

### Counting Ways to Make Change — Is this good functional/Lisp style?

I have just started learning some Scheme this weekend. I recently solved a problem that goes something like: ...
705 views

### Determine type of triangle in LISP

This is a simple LISP program to read in three sides of a triangle and report what kind of triangle it is (or isn't). Any feedback would be much appreciated. ...