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.
2
votes
1answer
19 views
Find common factor of numbers in a list
This program calculates common factor for given numbers. The original use case is to find a possible resolution for pixel games that scale well with new screen resolutions (that's why I don't have any ...
1
vote
1answer
38 views
Netstring parser in common lisp
Below is a netstring parser I wrote in Common Lisp. The docstring contains the usage and return.
...
1
vote
1answer
58 views
Exercism: clean and format a phone number in Clojure
Problem statement
Phone Number
Write a program that cleans up user-entered phone numbers so that they can be sent SMS messages.
The rules are as follows:
If the phone number is ...
1
vote
1answer
79 views
SICP exercise 1.28 - miller-rabin primality test
From SICP
Exercise 1.28: One variant of the Fermat test that cannot be fooled is
called the Miller-Rabin test (Miller 1976; Rabin 1980). This
starts from an alternate form of Fermat’s Little ...
5
votes
1answer
62 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:
...
2
votes
1answer
23 views
SICP 1.3 Sum of Squares of two largest numbers
Define a procedure that takes three numbers as arguments and returns the sum of squares of the two largest numbers.
I'm using just the machinery that was developed so far in SICP to be true to the ...
1
vote
1answer
37 views
SICP - exercise 1.12 - pascal's triangle
From SICP:
Exercise 1.12: The following pattern of numbers is called Pascal’s triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
. . .
The numbers at the ...
3
votes
2answers
115 views
Tail recursive FizzBuzz in Common Lisp
I solved FizzBuzz using tail recursion. Is it efficient enough?
...
8
votes
1answer
103 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 \$...
3
votes
1answer
52 views
SICP - exercise 1.11 - tree recursion
From SICP
Exercise 1.11: 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 procedure ...
8
votes
2answers
80 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 ...
2
votes
1answer
53 views
SICP exercise 1.3 - sum of squares of two largest of three numbers
From SICP
Exercise 1.3: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
Square is:
...
2
votes
1answer
107 views
Mutable stack in Racket
I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's ...
3
votes
1answer
56 views
SICP exercise 2.28 - counting leaves in a tree (recursive process)
From SICP
Exercise 2.28: Write a procedure fringe that takes as argument a tree
(represented as a list) and returns a list whose elements are all the
leaves of the tree arranged in left-to-...
2
votes
2answers
66 views
SICP - exercise 2.27 - reversing elements of a list and sublists
From SICP
Exercise 2.27: Modify your deep-reverse procedure of Exercise 2.18 to produce a deep-deep-reverse procedure that takes a list as argument and returns as its value the list with its ...
1
vote
1answer
46 views
SICP - exercise 2.5 - representing pairs of nonnegative integers using only numbers and arithmetic operations
From SICP
Exercise 2.5: Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product 2^x*...
2
votes
1answer
24 views
Replacing elements from a list and its sublists - part II
This is sort of a follow-up to
Replacing elements from a list and its sublists
but now there are arbitrary numbers of words that would be replaced stored in a list.
Now write substitute2 that takes ...
1
vote
2answers
43 views
SICP - exercise 2.20 - same-parity
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, a parameter ...
3
votes
1answer
53 views
Reversing a list without (append)
I would like to reverse a list using cdr, car and cons. Since lists in lisp are asymmetrical (can only insert at the beginning), I am interested on how one would write a procedure to do that without ...
3
votes
1answer
57 views
Replacing elements from a list and its sublists
Write a procedure substitute that takes three arguments: a list, an old word, and a new word. It should return a copy of the list, but with every occurrence of the old word replaced by the new word, ...
9
votes
2answers
92 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
...
5
votes
1answer
61 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 ...
3
votes
1answer
50 views
Replacing words from a sentence
I am extremely new at scheme and I am doing this problem from here:
Write a procedure switch that takes a sentence as its argument and
returns a sentence in which every instance of the words I ...
2
votes
1answer
68 views
Golden Section Search in Lisp
I implemented the golden section search algorithm recursively in Lisp. My code is:
...
6
votes
1answer
89 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 ...
2
votes
2answers
124 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 ...
3
votes
2answers
93 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 ...
1
vote
2answers
80 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
294 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 fill in ...
7
votes
1answer
177 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 ...
2
votes
1answer
362 views
Simple, functional URL parsing library in Clojure
I recently wrote some code to handle parsing of URLs, even if those URLs might not be one hundred percent perfectly well-formed. (This constraint made using Java's ...
5
votes
1answer
360 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 ...
2
votes
3answers
216 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 ->, ...
10
votes
1answer
369 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 ...
3
votes
0answers
100 views
Mangling MP3 collections
I'm writing a little tool for mangling MP3 collections and, as a challenge, I decided to write in in Hy, a dialect of Python that uses Lisp syntax. Like every good developer, I wrote out my list of ...
2
votes
2answers
287 views
Computing pairwise bitwise OR in a list of bit-strings
I am trying to solve this problem using Clojure:
You are given a list of \$N\$ people who are attending ACM-ICPC World
Finals. Each of them are either well versed in a topic or they are
not. ...
1
vote
2answers
61 views
Split every vector in a sequence into two parts: old elements that were contained in previous vectors and new elements never before seen
Am I doing it right? Is there some function in the standard library I should be using? This is my first real(ish) world Clojure program…
Input
...
1
vote
1answer
174 views
Reading/writing null-terminated strings from socket
I need to handle C style ('\0' delimited) strings from/to a socket and came up with this as a first attempt:
...
18
votes
1answer
324 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 ...
7
votes
2answers
150 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:
...
7
votes
4answers
224 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 ...
6
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:
...
3
votes
2answers
163 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 ...
5
votes
1answer
70 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 ...
3
votes
4answers
494 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 ...
11
votes
1answer
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 - ...
4
votes
2answers
70 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 ...
2
votes
1answer
102 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 ...
1
vote
1answer
164 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?
...
1
vote
2answers
70 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 ...