Tagged Questions
2
votes
1answer
42 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
67 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
66 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 ...
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 ...
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 ...
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 ...
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
77 views
(Common Lisp) Tabulate k = 2^n Minimizing Multiplication
Given the following problem:
;3.3 Tabulate the function k = 2^n for n = 1..50.
;Do this for the fewest possible multiplications.[3]
I wrote this answer:
(defun k (n) (ash 2 (1- n)))
(loop for n ...
2
votes
2answers
651 views
(Common Lisp) Palindrome-p
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
should ...
1
vote
1answer
134 views
(Common Lisp) Find epsi
4.2 Machine Epsilon. Find the floating point number epsi that has
the the following properties:
1.0+epsi is greater than 1.0 and
Let m b e any number less than epsi. Then 1.0+m is ...
2
votes
1answer
196 views
Compute Arithmetic Sum of a Constant Difference Sequence
3.1 Write a program that computes the arithmetic sum of a constant difference sequence. I. e.:
D0 = A
Dn+1 = Cdn + B
Run the following values and compare to the closed form solution.
Maximum index = ...
1
vote
1answer
266 views
Common Lisp - 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 ...