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.
5
votes
4answers
770 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
1answer
46 views
What's your opinion on this approach to 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
38 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 ...
0
votes
2answers
42 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 ...
6
votes
1answer
707 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 - ...
3
votes
2answers
45 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 ...
1
vote
1answer
56 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
132 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
50 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 ...
0
votes
0answers
63 views
Need guidance on creating an updating hash table
I'm not sure if this implementation is good enough. The function takes a vector of 1 million chars and creates a table of how many sequences pass before the next occurrence of itself.
Some questions ...
1
vote
1answer
53 views
A small emacs-lisp snippet for opening a register in another window
I'd like to get some feedback on whether this is idiomatic elisp, whether it's any good, and any small modifications that would be useful. Thanks
...
3
votes
1answer
201 views
Scheme/Racket: idiomatic infix math evaluator
Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an ...
6
votes
0answers
345 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 ...
2
votes
1answer
133 views
LISP - Modify string
I have to write a program that changes a string's vowels, consonants and other symbols into C, V respectively 0. I've done this but I wonder if there is a more efficient and elegant way to do it. ...
0
votes
2answers
236 views
Improving readability of non-recursive depth first search function in Lisp
As a free-time activity in order to learn some Lisp I had to implement depth first directed graph search. Due to large graph size (800K nodes, 5M arcs) recursion-based approach I could devise didn't ...
1
vote
1answer
160 views
Proper use of reduce, nested loops
Below is an implementation of Dijkstra's shortest path algorithm. It's input graph is represented as an association list of source nodes to assoc of target node and ...
1
vote
1answer
100 views
How to improve readability of a big lisp function
My main method (remove-random-edge) looks quite difficult to read. I'm new to list, so would appreciate any advice on how to improve the code.
...
4
votes
1answer
131 views
Seeking advice on lispiness of style and approach
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 ...
2
votes
1answer
138 views
Looking for any improvements to my Common Lisp code
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 ...
5
votes
1answer
137 views
First Go at Clojure and Functional Programming in General
Here's the code...
My goal is to simulate a Pile shuffle of a vector.
Here's the function..
...
4
votes
2answers
240 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?
...
2
votes
2answers
384 views
Counting Ways to Make Change — Is this good functional/Lisp style?
I have just started learning some Scheme this weekend. I recently solved a problem that goes something like:
...
3
votes
1answer
332 views
Connect Four: Bitboard checking algorithm
I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning.
The code below is a Clojure implementation of this bitboard algorithm.
The whole code can be found here: ...
3
votes
2answers
80 views
simple “if”-less algebraic computation using CLOS
For educational purposes I've tried to implement a simple algebraic OOP example using CLOS. The functionality is as far as I can say as it is supposed to be. The intended approach was to implement a ...
1
vote
1answer
298 views
Solution to 99 lisp problems: P08 with functional javascript
Solution to 99 lisp problems: P08, with functional javascript
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not ...
3
votes
1answer
164 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 ...
7
votes
1answer
474 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
All feedback is ...
1
vote
0answers
73 views
Implementing buffered channels in Guile
I was looking for a way of doing simple message passing in Guile and found some references to the module (ice-9 occam-channel) which is a pretty nifty, but undocumented, module for occam-like ...
1
vote
2answers
124 views
4
votes
4answers
1k 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 ...
3
votes
2answers
313 views
How can I improve this code?
The following code solves this problem:
The 3072 characters below contain a sequence of 5 characters which is repeated. However, there is a twist: one of the sequences has a typo. To be specific, ...
7
votes
2answers
158 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 ...
1
vote
0answers
141 views
Write a definition of a semaphore in terms of test-and-set! operations
From SICP:
Exercise 3.47. A semaphore (of size
n) is a generalization of a mutex.
Like a mutex, a semaphore supports
acquire and release operations, but it
is more general in that up to n
...
1
vote
0answers
144 views
Write a definition of a semaphore in terms of mutexes
From SICP:
Exercise 3.47. A semaphore (of size
n) is a generalization of a mutex.
Like a mutex, a semaphore supports
acquire and release operations, but it
is more general in that up to n
...
3
votes
0answers
118 views
Representing a queue as a procedure with local state
From SICP:
Exercise 3.22. Instead of
representing a queue as a pair of
pointers, we can build a queue as a
procedure with local state. The local
state will consist of pointers to the
...
4
votes
1answer
188 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 ...
1
vote
0answers
265 views
[SICP ex. 3.17] 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
204 views
[SICP ex. 3.8] 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 ...
1
vote
0answers
133 views
[SICP ex. 2.84] 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 successive
...
1
vote
0answers
287 views
(scheme [SICP ex. 2.82] 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 the
...
2
votes
1answer
529 views
Huffman encoding successive-merge function
From SICP:
Exercise 2.69. The following
procedure takes as its argument a list
of symbol-frequency pairs (where no
symbol appears in more than one pair)
and generates a Huffman encoding ...
1
vote
1answer
545 views
Encode-symbol for Huffman tree
From the text:
Exercise 2.68. The encode procedure
takes as arguments a message and a
tree and produces the list of bits
that gives the encoded message.
...
2
votes
1answer
274 views
Search on a binary tree
From SICP:
Exercise 2.66. Implement the lookup
procedure for the case where the set
of records is structured as a binary
tree, ordered by the numerical values
of the keys.
I wrote the ...
2
votes
0answers
762 views
Union-set intersection-set for a binary-tree implementation of sets [SICP ex. 2.65]
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
I ...
1
vote
1answer
278 views
Union-set for ordered representation
From SICP:
Exercise 2.62. Give a (n)
implementation of union-set for sets
represented as ordered lists.
I wrote this answer:
...
1
vote
1answer
168 views
(scheme) [SICP ex. 2.61] 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
...
4
votes
1answer
166 views
Set representation allowing duplicates
From SICP:
Exercise 2.60. We specified that a
set would be represented as a list
with no duplicates. Now suppose we
allow duplicates. For instance, the
set {1,2,3} could be represented as
...
1
vote
1answer
640 views
Union-set operation for unordered-list representation of sets
One way to represent a set is as a
list of its elements in which no
element appears more than once. The
empty set is represented by the empty
list. In this representation,
element-of-set? ...
1
vote
0answers
293 views
Standard Algebraic Derivative Calculator [SICP ex. 2.58 part b]
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 ...
10
votes
1answer
365 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 ...