ANSI Common Lisp, the programmable programming language.
1
vote
1answer
41 views
common lisp: nested loop beautification (checkboard texture generator)
I've written a small code snippet that generates checkboard texture using cl-opengl.
(defun init-texture (tex)
(gl:bind-texture :texture-2d tex)
(gl:tex-parameter :texture-2d ...
4
votes
1answer
79 views
Prime test - style and correct idiom review please
Below is some code I've created to generate and use a list of prime numbers. This is some of the first common lisp code I've written, and I'd be grateful for any comments regarding style and its use ...
2
votes
1answer
68 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
113 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
79 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
77 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) ...
1
vote
1answer
47 views
Written numbers to numerical representation
So I took a stab at this task to begin learning common lisp.
The idea is that you give it a written representation of a number such as "three thousand and forty nine" and it will output 3049.
I was ...
2
votes
1answer
116 views
Determinant calculation of a matrix of any degree
My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know.
//;;MakeShift make element number 'ind' the head of ...
4
votes
1answer
116 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
101 views
Simplify complex hash-table manipulations in Common Lisp
I'm trying to write a simple triplestore in Common Lisp that will store triples in the form subject-predicate-object. The code is inspired by the book "Programming the Semantic Web".
(defvar ...
6
votes
1answer
108 views
Sundaram's sieve in Common Lisp
I have this Sundaram's sieve to generate prime numbers up to limit in Common Lisp.
(defun sundaram-sieve (limit)
(let ((numbers (range 3 (+ limit 1) 2))
(half (/ limit 2))
(start ...
2
votes
1answer
120 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
1answer
66 views
Common Lisp. Please advise how the code could be improved
I have strong feeling that the code below is ugly at least as there are 2 same "cons".
I would appreciate if you advise me ways to improve it.
The code produces all allocation by n items from list ...
2
votes
1answer
109 views
Message queues in Common Lisp
General advice for a change. This is an implementation of message queues that I'm going to use for some work on an actors model library.
(defclass message-queue ()
((messages :accessor messages ...
3
votes
1answer
80 views
Need feedback on my first Common Lisp vector math code
I'm studying Common Lisp on my own. Coming from C++ Common Lisp feels kind of strange sometimes. I'd like to get some feedback on what I understood so far.
For learning purposes I wrote this simple ...
2
votes
0answers
122 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
107 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 ...
7
votes
2answers
162 views
Common Lisp macro: review for code quality & leaky name escaping
(defmacro with-condition-retries(retries expected-errors fail-function &body body)
"Attempts to execute `body` `retries` times, watching for
`expected-errors`. Optionally, if `fail-function` is ...
3
votes
4answers
879 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 ...
2
votes
1answer
176 views
Critique & improve a file reading routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun read-sim-file (filename)
"Reads file.
File is presumed to be the output from a simulation.
Returns lines from the simulation as a list of strings
We throw an ...
2
votes
1answer
764 views
Simple web-scraper in Common Lisp (SBCL)
I have written a simple web-scraper in Common Lisp, & would greatly appreciate any feedback:
(defpackage :myfitnessdata
(:use :common-lisp)
(:export #:main))
(in-package :myfitnessdata)
...
1
vote
1answer
328 views
Simple octal reader macro in Common Lisp
As an exercise, I've implemented a simple reader macro in Common Lisp (using SBCL). It converts Octal (unsigned integers only) into numbers.
Usage:
* #z1234
668
The code:
(defun ...
1
vote
2answers
332 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
79 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
673 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
139 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
198 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
278 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 ...
3
votes
1answer
477 views
Common Lisp - Solve a Cryptoarithmetic Problem
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:
;;Cryptoarithmetic. In cryptoarithmetic problems, we ...
2
votes
3answers
930 views
(Common Lisp) Print an Integer and its Digits Reversed
This common lisp program is an exercise to print an integer and its digits reversed to the screen.
(defun read-number () (format t "Enter a number: ~%") (read))
(defun reverse-string ...
4
votes
2answers
405 views
Common Lisp - 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 ...
4
votes
5answers
601 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 ...
4
votes
3answers
581 views
Sorting numbers in LISP
I am doing a CS practice exercise in which you are supposed to sort exactly three numbers using only if statements. I wrote the following code in LISP and would appreciate any suggestions how to ...
3
votes
3answers
962 views
Code Review of my Lisp Quicksort code
I would really appreciate it if someone could review my LISP code. I was attempting to write a quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. ...