Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
17 views

Nested loop in lisp to process a 2d array - what's good style (with and/or without loop macro)?

Code below is answer to an exercise in Paul Graham's ANSI Common Lisp (ex. 4.1). The challenge is to rotate an array by 90 degrees. I found an example solution which I've commented below. It seems ok'...
1
vote
0answers
19 views

Puzzling SBCL Compiler Note

I’m having trouble understanding an SBCL compiler note about unreachable code in the following function. The referenced code is attempting to push a value into an Lparallel queue: ...
4
votes
0answers
74 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 ...
1
vote
1answer
33 views

Enigma questions from “ANSI Common Lisp” [closed]

I'm working through Paul Graham's ANSI Common Lisp and in Exercise 2.5, I'm stumped. My specific question (I wasn't sure whether this type of question is suitable for stack overflow, code review, or ...
3
votes
2answers
53 views

pos+ (value added to position) - ex 3.5 in “ANSI Common Lisp” (p57)

The problem is to take a list of integers and map them to another list containing those integers added to their respective position in the list. Example runs with required outputs: ...
6
votes
2answers
98 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 ...
1
vote
1answer
83 views

Verify that each named sequence is strictly increasing

The master launch sequence consists of several independent sequences for different systems. Your goal is to verify that all the individual system sequences are in strictly increasing order. In other ...
4
votes
1answer
110 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 ...
3
votes
2answers
151 views

A simple Tic Tac Toe game

I am trying to learn some Common Lisp, except basically all of my computing background is the C family of languages. So, I'm starting small. I have made a Tic-Tac-Toe game, and I am looking for some ...
4
votes
1answer
126 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 ...
2
votes
1answer
55 views

Extracting XML data from a node in Common Lisp (Closure XML DOM)

This is a function intended to take an XML element (in closure XML format) and a name and find a piece of simple data by that name (either in a tag or attribute) within that XML element. It works, but ...
6
votes
2answers
164 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,...
4
votes
0answers
57 views

Pure functional code for the sublists of a list

The code below gives me the list of sublists of a list. Code can still be improved to avoid the use of append, right? ...
4
votes
1answer
101 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. ...
3
votes
2answers
220 views

Reading lines of integers into a list of lists

I have a text file containing integers in different lines which I want to read into a list of lists. So 01 11 14 45 50 09 should become ...
1
vote
1answer
96 views

Calculating insulin bolus dose and infusion rate

I wrote a hobby program to ease the job of nurses to calculate insulin bolus dose and infusion rate according to measured blood glucose. There are several protocols around. Almost all hospitals ...
8
votes
1answer
160 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 ...
4
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 ...
2
votes
1answer
134 views

Pairwise grouping of elements of a list

I want to group the elements in an arbitrary long list into pairs and implemented the following so far: ...
4
votes
1answer
190 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 ...
5
votes
1answer
89 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: ...
4
votes
1answer
128 views

Extending COERCE to other reasonable object type conversions

It's a basic principle in AI that different problem representations can either facilitate or impede a solution. Being able to readily switch data representations while programming in Common Lisp may ...
6
votes
2answers
161 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) ...
3
votes
1answer
33 views

Determine indentation of a line of code

The following function determines the amount of indentation of a string. It returns two values. The first is an effective indentation where tabs are expanded such that their end aligns with 4 spaces ...
6
votes
1answer
251 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 ...
6
votes
1answer
125 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 ...
4
votes
3answers
216 views

Invert the bits of a non-negative integer in Common Lisp (SBCL)

I'm doing code challenges to learn Common Lisp. I'm trying to invert all the bits in any given positive integer. My current solution does it the math way, by recursing on a number, dividing it by two,...
7
votes
1answer
84 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. ...
9
votes
2answers
243 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 ...
5
votes
2answers
403 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 ...
2
votes
1answer
102 views

Sort 3 numbers in Common Lisp with the minimum number of operations

I’m wondering is the following function returns a list of three numbers sorted in ascending order with the minimum possible number of operations, or if there is some more efficient or elegant method (...
13
votes
2answers
866 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 ...
4
votes
3answers
142 views

Netstring parser in common lisp

Below is a netstring parser I wrote in Common Lisp. The docstring contains the usage and return. ...
3
votes
1answer
144 views

Once-only macro

I have been learning common lisp and am a newbie, using the great book Practical Common Lisp. There is a once-only macro in the book that I spent a lot of time figuring out how it works. Even after I ...
4
votes
2answers
309 views

Tail recursive FizzBuzz in Common Lisp

I solved FizzBuzz using tail recursion. Is it efficient enough? ...
12
votes
2answers
209 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 ...
3
votes
1answer
91 views

Golden Section Search in Lisp

I implemented the golden section search algorithm recursively in Lisp. My code is: ...
7
votes
1answer
218 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 ...
3
votes
2answers
256 views

“Skewed” average in Lisp

I set myself the task to calculate the average of a list, but with two conditions: negative numbers are ignored numbers greater than 100 are counted as if they were 100 So the "skewed" average of ...
4
votes
4answers
388 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 ...
2
votes
2answers
271 views

Standard deviation of hourly temperatures of 2 days

It seems that when I program in Lisp my brain goes on auto pilot and I end up solving the problem somehow. I don't even think I just do and it works out. That said, this is some horrible Lisp code ...
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
720 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}...
8
votes
1answer
737 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 ...
6
votes
1answer
963 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 ...
3
votes
3answers
521 views

Recursion vs. iteration in Lisp macro

I've been programming Clojure for a little while and recently started learning Common Lisp. One of my favorite things about Clojure is the threading operator ->, ...
3
votes
2answers
225 views

Using reduce twice in a row for Run Length Encoding

First of all, I'm new to Lisp (I currently use CLISP and SBCL). There probably are huge mistakes in this code so any guidelines are welcome :) I'm very confused about how to do this. It's just about ...
8
votes
5answers
357 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 ...
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: ...
4
votes
2answers
349 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 ...