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.

learn more… | top users | synonyms

10
votes
1answer
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 ...
7
votes
1answer
756 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 - ...
7
votes
1answer
491 views

Clojure TicTacToe (Logic, no Gui)

I whipped this up last night and was wondering if anyone had any thoughts/comments on it; for example, on: Code organisation Coding style Other improvements Semantic errors All feedback is ...
7
votes
2answers
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 ...
6
votes
4answers
830 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: ...
6
votes
1answer
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 ...
6
votes
3answers
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. ...
6
votes
0answers
364 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 ...
5
votes
2answers
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 ...
5
votes
1answer
138 views

First Go at Clojure and Functional Programming in General

Here's the code... My goal is to simulate a Pile shuffle of a vector. Here's the function.. ...
5
votes
0answers
573 views

Merge sort in Scheme

...
4
votes
4answers
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 ...
4
votes
1answer
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 ...
4
votes
2answers
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 ...
4
votes
5answers
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. ...
4
votes
1answer
133 views

Seeking advice on lispiness of style and approach

I'm new to Lisp and I'm yet to wrap my head around the Lisp way of writing programs. Any comments regarding approach, style, missed opportunities appreciated: In particular, please advice if I build ...
4
votes
2answers
270 views

Combinations of list elements

It was written in Emacs Lisp and requires Common Lisp loop facility. Can this code be improved? Did I hit any anti-patterns along the way? ...
4
votes
1answer
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 ...
4
votes
1answer
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: ...
4
votes
3answers
763 views

Sorting numbers in LISP

I am doing a CS practice exercise in which you are supposed to sort exactly three numbers using only if statements. I wrote the following code in LISP and would appreciate any suggestions how to ...
4
votes
1answer
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: ...
4
votes
1answer
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 ...
4
votes
3answers
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 ...
4
votes
1answer
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 ...
4
votes
1answer
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 ...
4
votes
0answers
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 ...
3
votes
3answers
1k views

Code Review of my Lisp Quicksort code

I would really appreciate it if someone could review my LISP code. I was attempting to write a quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. ...
3
votes
3answers
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. ...
3
votes
1answer
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 ...
3
votes
1answer
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 ...
3
votes
2answers
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 ...
3
votes
1answer
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 ...
3
votes
2answers
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 ...
3
votes
1answer
225 views

Scheme/Racket: idiomatic infix math evaluator

Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an ...
3
votes
1answer
348 views

Connect Four: Bitboard checking algorithm

I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning. The code below is a Clojure implementation of this bitboard algorithm. The whole code can be found here: ...
3
votes
2answers
81 views

simple “if”-less algebraic computation using CLOS

For educational purposes I've tried to implement a simple algebraic OOP example using CLOS. The functionality is as far as I can say as it is supposed to be. The intended approach was to implement a ...
3
votes
2answers
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 ...
3
votes
1answer
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 ...
3
votes
2answers
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: ...
3
votes
1answer
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 ...
3
votes
0answers
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 ...
3
votes
1answer
311 views

Redefine count-leaves as an accumulation

Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: ...
2
votes
1answer
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 ...
2
votes
2answers
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 ...
2
votes
1answer
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? ...
2
votes
1answer
133 views

LISP - Modify string

I have to write a program that changes a string's vowels, consonants and other symbols into C, V respectively 0. I've done this but I wonder if there is a more efficient and elegant way to do it. ...
2
votes
1answer
139 views

Looking for any improvements to my Common Lisp code

To start with Common Lisp I am doing Project Euler using this language. Usually I manage to solve problems but I am quite sure that my code is not as efficient as it could be in Common Lisp. That is ...
2
votes
2answers
376 views

LISP-like list class.

So, here's my code: ...
2
votes
2answers
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: ...
2
votes
1answer
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 ...