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.
-1
votes
0answers
31 views
Unit test macro [on hold]
I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty with modifying it, so I ...
6
votes
1answer
122 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 ...
1
vote
1answer
159 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 ...
3
votes
4answers
256 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 ...
2
votes
2answers
41 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
1answer
31 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
42 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 ...
23
votes
0answers
751 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 ...
11
votes
1answer
1k 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
0answers
77 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 ...
9
votes
1answer
206 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 ...
4
votes
1answer
378 views
A crude clojure progress reporting function
The purpose of this function is to report processing progress to the terminal. It loops through an array of maps that contain two properties: :sequence and ...
5
votes
1answer
154 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 ...
0
votes
1answer
113 views
Extending basic differentiator to handle more kinds of expressions
Exercise 2.56. Show how to extend the
basic differentiator to handle more
kinds of expressions. For instance,
implement the differentiation rule
by adding a new clause to the deriv
...
2
votes
1answer
179 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 ...
2
votes
3answers
119 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 ->, ...
5
votes
1answer
161 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, ...
3
votes
2answers
121 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 ...
6
votes
4answers
181 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 ...
1
vote
4answers
418 views
Echoing back input in uppercase over a socket with Hy, a Python Lisp dialect
I think I'd like to learn Clojure eventually, but at the moment am having fun with Hy, a "dialect of Lisp that's embedded in Python."
...
2
votes
0answers
81 views
How common is the use of closure in Lisp?
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 ...
5
votes
3answers
587 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 ...
1
vote
2answers
2k views
A definition of for-each
Exercise 2.23
The procedure for-each
is similar to map. It takes as
arguments a procedure and a list of
elements. However, rather than forming
a list of the results, for-each just
...
2
votes
2answers
228 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
46 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
129 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:
...
16
votes
1answer
242 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 ...
0
votes
1answer
239 views
Defining a unique-pairs procedure
From the section called Nested Mappings
Exercise 2.40
Define a procedure
unique-pairs that, given an integer n,
generates the sequence of pairs (...
0
votes
1answer
636 views
Define the equal? predicate
Exercise 2.54
Two lists are said to
be equal? if they contain equal
elements arranged in the same order.
For example,
...
0
votes
1answer
657 views
Iterative sum using recursion
Given the following recursive definition of sum:
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
...
0
votes
1answer
471 views
Producing a deep-reverse procedure
Exercise 2.27
Modify your reverse
procedure of exercise 2.18 to produce
a deep-reverse procedure that takes a
list as argument and returns as its
value the list with its elements
...
1
vote
1answer
322 views
Make a version of make-rat that handles positive and negative arguments
Given the following task from SICP
Exercise 2.1
Define a better version
of make-rat that handles both positive
and negative arguments. Make-rat
should normalize the sign so that if
...
1
vote
1answer
468 views
Multiplication in terms of addition
Given the following task:
Exercise 1.17
The exponentiation
algorithms in this section are based
on performing exponentiation by means
of repeated multiplication. In a
similar way, one ...
1
vote
1answer
261 views
Adjoin-set for an ordered set representation
From SICP:
Exercise 2.61
Give an implementation
of adjoin-set using the ordered
representation. By analogy with
element-of-set? show how to take
advantage of the ordering to produce a
...
1
vote
0answers
406 views
Correctly count the number of pairs in an irregular list structure
From SICP:
For background, here is exercise 3.16:
Exercise 3.16
Ben Bitdiddle decides
to write a procedure to count the
number of pairs in any list structure.
...
1
vote
1answer
261 views
Order of evaluation of function arguments
From SICP:
Exercise 3.8
When we defined the
evaluation model in section 1.1.3, we
said that the first step in evaluating
an expression is to evaluate its
subexpressions. But we never ...
7
votes
2answers
109 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:
...
5
votes
2answers
455 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 ...
1
vote
0answers
152 views
Coercion of arguments using successive raising
From SICP:
Exercise 2.84
Using the raise
operation of exercise 2.83, modify the
apply-generic procedure so that it
coerces its arguments to have the same
type by the method of ...
1
vote
0answers
315 views
Coercion with multiple arguments
From SICP:
Exercise 2.82
Show how to generalize
apply-generic to handle coercion in
the general case of multiple
arguments. One strategy is to attempt
to coerce all the arguments to ...
1
vote
0answers
368 views
Standard Algebraic Derivative Calculator
I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP:
Exercise 2.58
Suppose we want to
modify the differentiation program so
that it ...
4
votes
1answer
559 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 ...
2
votes
0answers
871 views
Union-set intersection-set for a binary-tree implementation of sets
From SICP:
Exercise 2.65
Use the results of
exercises 2.63 and 2.64 to give (n)
implementations of union-set and
intersection-set for sets implemented
as (balanced) binary trees.41
...
4
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 ...
2
votes
2answers
1k views
Testing input integers for the palindrome property
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 ...
4
votes
2answers
947 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:
...
1
vote
1answer
828 views
Church Numerals - implement one, two, and addition
Given the following exercise:
Exercise 2.6
In case representing
pairs as procedures wasn't
mind-boggling enough, consider that,
in a language that can manipulate
procedures, we can ...
2
votes
1answer
246 views
Compute arithmetic sum of a constant difference sequence
3.1
Write a program that computes the arithmetic sum of a constant
difference sequence:
D0 = A
Dn+1 = Cdn + B
Run the following values and compare ...
6
votes
1answer
3k 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 ...
1
vote
1answer
317 views
Abstract the (duplicate?) behavior between “sort” and “replace”
I have written these two functions that have a similar process. The first is meant to "split" a string on a given character and the second is meant to "replace-all" instances of a character in a ...