Questions tagged [lisp]

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.

Filter by
Sorted by
Tagged with
50 votes
1 answer
2k 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 ...
naeg's user avatar
  • 641
23 votes
1 answer
561 views

Is this IRC bot utility library Racket-y enough?

To help myself learn Racket, I ported a simple JavaScript ircbot module I wrote for Node.js to Racket. The Racket version is built atop the Racket irc package, so ...
Alexis King's user avatar
  • 3,172
14 votes
2 answers
962 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 ...
brian d foy's user avatar
14 votes
3 answers
419 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 ...
Phrancis's user avatar
  • 20.4k
13 votes
1 answer
2k 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 - ...
matio2matio's user avatar
13 votes
1 answer
411 views

(Lisp in (Rust))

I loved Norvig's Lispy, and made the first version of it in Rust, to learn Rust. I would love your thoughts :) A few specific questions: Is there a way to write ...
Stepan Parunashvili's user avatar
11 votes
1 answer
564 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 ...
John F. Miller's user avatar
10 votes
2 answers
386 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 ...
tscizzle's user avatar
  • 277
10 votes
2 answers
5k 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 (...
jaresty's user avatar
  • 2,243
10 votes
1 answer
876 views

WebSocket-based API library in Racket

I've developed a library in (typed) Racket that wraps a WebSocket-based API. The API itself is very simple—it operates via a series of three-letter commands optionally followed by a JSON-encoded ...
Alexis King's user avatar
  • 3,172
9 votes
1 answer
117 views

Edis: Emacs driven indentation script

Motivation I recently picked up Emacs. As part of the process, I've started to configure the editor to fit my needs with Emacs Lisp. The Elisp indentation rules are still foreign to me, so I pretty ...
Zeta's user avatar
  • 19.3k
9 votes
1 answer
1k 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 ...
Daniel Shapero's user avatar
8 votes
5 answers
509 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 ...
Alex L's user avatar
  • 5,737
8 votes
3 answers
936 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. ...
jaresty's user avatar
  • 2,243
8 votes
1 answer
104 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. ...
Alexander Artemenko's user avatar
8 votes
1 answer
882 views

"Curious Numbers" (HackerRank PE 34)

I was inspired by a certain recent question to try my hand at this challenge: Project Euler #34: Digit factorials \$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible by \$19\$...
Phrancis's user avatar
  • 20.4k
8 votes
2 answers
297 views

Compiler for a minimal LISP dialect to run on the Java Virtual Machine

As the title states, this is a compiler written in C with a ruby build script that translates a minimal LISP dialect and spits out an executable jar file. I designed this LISP dialect and named it ...
user avatar
8 votes
1 answer
111 views

Lisp-like language interpreter in Python

I decided to learn more about how interpreters work and made a simple Scheme interpreter in Python. I'd like to hear some advice on how I could have written this better, or on the mistakes I've made. ...
guy25678's user avatar
7 votes
4 answers
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: ...
henginy's user avatar
  • 183
7 votes
2 answers
321 views

Getting functional Common Lisp code for handling state in a SDL animation

The following code draws a red rectangle bouncing between the borders of a white display. I'm not particularly happy with the update function: ...
barerd's user avatar
  • 225
7 votes
1 answer
476 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 ...
Sod Almighty's user avatar
7 votes
1 answer
756 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 ...
LiamGoodacre's user avatar
7 votes
2 answers
176 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 ...
jaresty's user avatar
  • 2,243
6 votes
2 answers
661 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 ...
jaresty's user avatar
  • 2,243
6 votes
4 answers
4k 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 ...
gumbo's user avatar
  • 63
6 votes
2 answers
2k 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? ...
mpontus's user avatar
  • 163
6 votes
2 answers
7k 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 ...
jaresty's user avatar
  • 2,243
6 votes
2 answers
945 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,...
Benz's user avatar
  • 61
6 votes
1 answer
141 views

PE4: Largest Palindrome Product (Clojure)

I solved Project Euler 4 using Clojure Lisp. A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest ...
Phrancis's user avatar
  • 20.4k
6 votes
3 answers
2k 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 ...
jaresty's user avatar
  • 2,243
6 votes
1 answer
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 ...
Th30n's user avatar
  • 161
6 votes
1 answer
101 views

WOMOIWIW: What Org-mode Opens is What I Want

Motivation Previously, on the Emacs stack exchange: In Org mode, when I open a link (C-c C-o) [...] [that] contains a wildcard, such as file:3_o*.pdf, Emacs opens ...
Zeta's user avatar
  • 19.3k
6 votes
1 answer
478 views

Redefine count-leaves as an accumulation

Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: ...
jaresty's user avatar
  • 2,243
6 votes
1 answer
642 views

Binero puzzle solver

During my holiday I decided to implement a solver for those puzzles my girlfriend likes to do. They are called Takuzu, but "binero" in Dutch. The puzzle gives you a grid in which you have to ...
Christophe De Troyer's user avatar
5 votes
3 answers
3k 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 ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
169 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 ...
jcarpenter2's user avatar
5 votes
3 answers
3k 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 ...
jaresty's user avatar
  • 2,243
5 votes
3 answers
900 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 ...
jaresty's user avatar
  • 2,243
5 votes
2 answers
438 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 ...
tscizzle's user avatar
  • 277
5 votes
1 answer
312 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 ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
199 views

Finding next perfect number - brute force

A “perfect number” is defined as a number equal to the sum of all its factors less than itself. For example, the first perfect number is 6, because its factors are 1, 2, 3, and 6, and 1+2+3=6. The ...
lightning_missile's user avatar
5 votes
2 answers
87 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 ...
Mark Green's user avatar
5 votes
2 answers
775 views

Parsing infix expressions in Clojure

I'm trying to teach myself Clojure by reading the Brave Clojure book online, and at the end of Chapter 7 there is an exercise to parse a mathematical expression written as a list in infix notation to ...
Eric Zhang's user avatar
5 votes
1 answer
116 views

Selecting HTML nodes

I'm new to Clojure, and I'm writing some code that processes HTML. I'm parsing the HTML using clj-tagsoup and then trying to pull out the relevant bits with this function: ...
jpd's user avatar
  • 51
5 votes
1 answer
188 views

Pile shuffle of a vector

My goal is to simulate a Pile shuffle of a vector. It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle. As this is my first attempt at clojure code, ...
jondavidjohn's user avatar
5 votes
1 answer
466 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 ...
stackman's user avatar
5 votes
1 answer
546 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 ...
jaresty's user avatar
  • 2,243
5 votes
2 answers
3k views

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: ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
516 views

Axiomatic Lisp interpreter in C

This is not obfuscated. Or at least, that's not the intent. Let me try to address that concern straightaway. The goal here is brevity in the vein of Strunk&White. Nor is this codegolf, although ...
luser droog's user avatar
  • 2,018
5 votes
1 answer
326 views

“Guess My Number” with Racket

I am using the book "Realm of Racket" which was written by the people behind the Racket and Dr. Racket projects. It is a great book based on games, similar to the famous "Land of Lisp". The first ...
user avatar