Questions tagged [common-lisp]

Common Lisp, or ANSI Common Lisp, is a standardized version of the Lisp programming language intended for production-strength power and libraries.

Filter by
Sorted by
Tagged with
14
votes
2answers
879 views

A Lisp version of the Schwartzian transform

Randal Schwartz stole Lisp's decorate-sort-undecorate idiom when he came up with what we'd later call the Schwartzian transform. All of my Lisp knowledge disappeared through nine half lives, but I ...
12
votes
2answers
218 views

Advent of Code: “Not Quite Lisp”

I have solved this simple challenge on Advent of Code: Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little ...
10
votes
1answer
203 views

Generating hard to guess session tokens

Does this code create sufficiently hard-to-guess session tokens, assuming the server and client are communicating over HTTPS? Take 2 (thanks to this crypto.SE answer): ...
9
votes
2answers
261 views

Project Euler #2 (classic) - Sum of even fibonacci numbers below 4 million

I'm looking to use LISP as best I can, not just get the right answer. This is very early on in my LISP career so feedback is welcome and exciting! Recently asked about Project Euler #1, got some ...
8
votes
5answers
371 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 ...
8
votes
1answer
176 views

Scoring poker hands

Just for fun I solved another Project Euler problem dealing with poker cards. I think it is also part of other programming puzzles which can be found in the web. While there is not much mathematics in ...
8
votes
1answer
795 views

Functional tree iteration in Common Lisp

I'm adding some functionality to an existing library of data structures in Common Lisp, with a view to asking the original author if I can take over maintenance and development of it. While the ...
7
votes
4answers
1k 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: ...
7
votes
1answer
321 views

Sundaram's sieve in Common Lisp

I have this Sundaram's sieve to generate prime numbers up to limit in Common Lisp. ...
7
votes
1answer
85 views

A heart.lisp I wrote with my 6 year old daughter

Is it possible to improve this program somehow? It will probably be more convenient to suggest edits as forks of this Gist. ...
7
votes
1answer
222 views

Unit test macro

I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty with modifying it, so I ...
7
votes
1answer
54 views

Binary Heap implementation in Common Lisp and tests

I implemented a basic binary heap in Common Lisp to learn programming using the CLOS. It is quite neat and self-contained, the core of the program is about 100 SLOC. The whole repository can be found ...
7
votes
2answers
228 views
6
votes
2answers
625 views

Determining if f(n) = n^2 + 3n + 5 is ever divisible by 121

Given the following problem: It is conjectured that for any \$n > 0\$, \$n^2 + 3n + 5\$ is never divisible by 121. Test this conjecture for \$n = 1,2,...,9999,10000\$. I wrote the following ...
6
votes
1answer
114 views

Occurrences (frequency count) - exercise 3 ch. 3 in “ansi common lisp”

Looking for hints on style and clarity re. below. While I'm not saying speed is irrelevant, it's less of a priority than style & avoiding bad habits at this point. Focus is on clean use of ...
6
votes
2answers
199 views

Returning the prime factors of a number

I am trying to create a function prime-factors that returns the prime factors of a number. To do so, I created is-prime function,...
6
votes
2answers
2k views

Simple web-scraper in Common Lisp (SBCL)

I have written a simple web-scraper in Common Lisp, & would greatly appreciate any feedback: ...
6
votes
2answers
164 views

Language training program using Common Lisp and the ltk library

The idea is as follows: We provide program with two files: one with English words and one with words in, let's say, Spanish. The files have one word (it could be a word, or word+some explanation etc) ...
6
votes
1answer
1k views

ANFIS network based on Sugeno model I

I've been learning Common Lisp lately and I've implemented ANFIS network based on Sugeno model I. Network layout and details can be read in these slides by Adriano Oliveira Cruz. I use sigmoid as the ...
6
votes
1answer
94 views

Calculating the cube root

Inspired by a question on SO I was checking how to calculate the cube root of an integer and found a C-ish solution on Hacker's Delight: ...
6
votes
1answer
139 views

Using get-setf-expansion

In a previous post at Simplifying complex setf expressions, @sds suggested using the get-setf-expansion macro for implementing place modification, as discussed in ...
6
votes
1answer
61 views

Finding capitalized characters and printing their position & ASCII value

I was trying to find out if a string contained a capitalized letter and if it did I wanted to know the position of the character and its ASCII code. I might have refactored a little to much. Given an ...
6
votes
1answer
2k views

Generating and using a list of prime numbers

Here is some code I've created to generate and use a list of prime numbers. This is some of the first Common Lisp code I've written, and I'd be grateful for any comments regarding style and its use ...
6
votes
1answer
726 views

Solving the 'Vietnamese school maths problem'

Having read Can you do the maths puzzle for Vietnamese eight-year-olds that has stumped parents and teachers?, which presented the problem of filling in numbers 1 to 9 to satisfy $$ a + 13 \frac{b}{c}...
6
votes
1answer
282 views

Generic copy function

Common Lisp does not have a generic copy function for reasons outlined in Kent Pitman's article The Best of Intentions. However, it may still be convenient for rapid prototyping purposes to provide ...
5
votes
3answers
2k views

Lisp quicksort code

I would really appreciate it if someone could review my quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. Of course, I realize that the tests are ...
5
votes
4answers
3k 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 ...
5
votes
3answers
2k 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 ...
5
votes
3answers
707 views

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
2answers
422 views

Sum of all multiples of 3 or 5 below 1000 (Project Euler #1 - typical)

I'm learning LISP and am starting with Project Euler. I would love some initial feedback on my LISP code for this simple task. I know it spits out the correct answer, but what I'm not sure about is ...
5
votes
2answers
2k views

Split a list into two parts with a given length

I'm learning Common Lisp as a hobby and am trying tasks from L-99: Ninety-Nine Lisp Problems, but I'm not sure how good my code is. Here is one of the tasks which I solved: GitHub solution ...
5
votes
2answers
84 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 ...
5
votes
1answer
443 views

Did I convert this C++ class to Common Lisp correctly?

Here is the original C++ class I converted to Lisp at the very bottom of this post. ...
5
votes
1answer
388 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 ...
5
votes
1answer
103 views

Calculation of lexicographic permutations

Just for fun, I studied the generation of lexicographic permutations and came across the following algorithm which I transcribed into Common Lisp, as good as I can, being a hobbyist: ...
5
votes
0answers
90 views

A Parallel Processing Template for Divide & Conquer Problems

I’ve written a program for solving a problem using standard single-threaded code. However, it looks like it could be recast as a multi-threaded problem using divide & conquer. Since this is a ...
4
votes
4answers
1k 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 ...
4
votes
5answers
1k 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
2answers
328 views

Tail recursive FizzBuzz in Common Lisp

I solved FizzBuzz using tail recursion. Is it efficient enough? ...
4
votes
4answers
454 views

Insertion sort in Common Lisp

This is my first bit of significant code in Common Lisp, an implementation of insertion sort. Being new to Lisp in general, I'm wondering if this code follows best Lisp practices in regards to program ...
4
votes
1answer
146 views

FizzBuzz in Common Lisp

Where I stand on Lisp So, Lisp. It's been on my radar for years and I'm finally getting around to learning it. The syntax is foreign but I find I'm having the most difficulty in the areas of ...
4
votes
1answer
110 views

lisp-koans Greed implementation

I have implemented Greed as part of the lisp-koans extra-credit challenge. I am seeking some general feedback with respect to Common Lisp style, appropriate use of language features, and so forth. ...
4
votes
3answers
157 views

Netstring parser in common lisp

Below is a netstring parser I wrote in Common Lisp. The docstring contains the usage and return. ...
4
votes
3answers
338 views

Project Euler #35 in Common Lisp

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 ...
4
votes
2answers
382 views

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 ...
4
votes
1answer
116 views

Implementing a tree parsing function

I've solved an assignment a week ago, which is my first assignment using Lisp. Tasks: Task 1: a. Given a tree as recursive lists, print the tree in breadth first order. b. Given a tree like ...
4
votes
3answers
220 views

Mergesort with an inversion counter

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
3k views

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: ...
4
votes
1answer
216 views

(SBCL) ASCII Game of Life

I'm implementing Conway's Game of Life in Lisp to familiarize myself with the language, with the eventual goal of hosting it on a website with a pretty GUI. I'm a hobbyist and inexperienced (this is ...
4
votes
1answer
595 views

Finding a cryptoarithmetic solution

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: In cryptoarithmetic problems, we are given a ...