Lisp is a family of programmable programming languages.
2
votes
1answer
41 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. ...
5
votes
1answer
125 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 ...
2
votes
1answer
125 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:
Count the number of ways possible to give out a certain amount of change using
1 5 10 25 ...
2
votes
1answer
34 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 ...
3
votes
0answers
150 views
Connect Four AI (Minimax) in Clojure
I wrote a Connect Four game inlcuding 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 ...
0
votes
2answers
62 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 ...
0
votes
1answer
53 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 arc weight.
My question is about ...
1
vote
1answer
65 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.
(defun find-node (node graph)
(find-if #'(lambda (i) ...
4
votes
1answer
105 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
112 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 ...
3
votes
2answers
113 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?
(defun combos (list)
(let* ((a (car list))
(d ...
5
votes
1answer
111 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..
(defn pile
([cards] (pile cards 3 1))
([cards num_piles] (pile cards num_piles 1))
([cards ...
3
votes
1answer
220 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
72 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 ...
6
votes
1answer
363 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
1answer
135 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 ...
2
votes
0answers
116 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 ...
5
votes
4answers
638 views
(Scheme) [SICP ex. 2.41] 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.
(define ...
1
vote
1answer
363 views
Huffman encoding successive-merge function [SICP ex. 2.69]
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
0answers
60 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
101 views
with-alist-bind
Take 4 (alteration based on feedback from Rainer Joswig):
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro ...
1
vote
0answers
123 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
...
1
vote
0answers
157 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.
It's easy,'' he reasons.The
...
2
votes
0answers
622 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
0answers
128 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
...
2
votes
1answer
202 views
Lookup (search) on a binary tree [SICP ex. 2.66]
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
94 views
[SICP ex. 3.22] represent 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
...
3
votes
1answer
415 views
GCD - is this solution iterative?
Using the property that GCD(a, b) = GCD(b, r) where r is the remainder when you compute (a / b), you can write a recursive function as follows:
(define (gcd a b)
; recursive
(if (= 0 b) a
...
3
votes
1answer
144 views
SICP ex. 3.18 - Write a program to 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
1answer
322 views
(Encode-symbol …) for Huffman tree [SICP ex. 2.68]
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.
(define (encode message tree)
...
1
vote
0answers
215 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 ...
2
votes
4answers
743 views
(Common Lisp) 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
305 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, ...
3
votes
4answers
421 views
(Scheme) [SICP ex. 2.42] eight-queens puzzle - help me fix my popsicle-stick-bridge solution!
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 ...
4
votes
5answers
552 views
Determine type of triangle in LISP
This is a simple LISP program to read in three sides of a triangle and report what kind of triangle it is (or isn't). Any feedback would be much appreciated.
(defun read-side (side) (format t "Enter ...
1
vote
2answers
323 views
(Common Lisp) Is f(n) = n^2 + 3n + 5 not ever divisible by 121?
Given the following problem:
;3.4 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.[3]
I wrote the following ...
1
vote
1answer
149 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 ...
0
votes
1answer
382 views
[SICP ex. 1.30] Iterative Sum
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))))
And the task:
Exercise 1.30. The ...
1
vote
1answer
127 views
[SICP ex. 2.11] A more efficient mul-interval
From 2.11
Exercise 2.11. In passing, Ben also
cryptically comments: ``By testing the
signs of the endpoints of the
intervals, it is possible to break
mul-interval into nine cases, only ...
1
vote
0answers
99 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
236 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
138 views
(scheme) [SICP ex. 2.60] 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
220 views
(scheme) [SICP ex. 2.62] 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:
(define (union-set set1 set2)
(cond ((null? set1) set2)
...
1
vote
1answer
132 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
...
1
vote
1answer
328 views
(Scheme) [SICP ex. 2.59] union-set
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
1answer
147 views
(Scheme) [SICP ex. 2.57] Extend sums and products functions without changing deriv function
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
(deriv '(* ...
3
votes
0answers
281 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 ...
0
votes
1answer
78 views
(Scheme) [SICP ex. 2.56] Extend Differentiator
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
...
0
votes
1answer
284 views
(Scheme) [SICP ex. 2.54] Define equal?
Exercise 2.54. Two lists are said to
be equal? if they contain equal
elements arranged in the same order.
For example,
(equal? '(this is a list) '(this is a list))
is true, but
...
1
vote
2answers
1k views
(Scheme) [SICP ex. 2.37 Matrix Multiplication
Exercise 2.37. Suppose we represent
vectors v = (vi) as sequences of
numbers, and matrices m = (mij) as
sequences of vectors (the rows of the
matrix). For example, the matrix
is ...