Lisp is a family of programmable programming languages.

learn more… | top users | synonyms

2
votes
1answer
44 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
166 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 ...
2
votes
1answer
47 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
69 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
54 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
67 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
106 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 ...
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
2answers
117 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 ...
2
votes
1answer
130 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 ...
3
votes
1answer
221 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 ...
1
vote
1answer
142 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 ...
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
0answers
61 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
102 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
758 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, ...
5
votes
1answer
128 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
129 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
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 ...
2
votes
0answers
95 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
145 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
0answers
158 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 ...
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 ...
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
237 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 ...
1
vote
1answer
364 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
1answer
330 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) ...
2
votes
1answer
203 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
623 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
221 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
134 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 ...
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
329 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
0answers
222 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 ...
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 ...
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 '(* ...
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
285 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
101 views

(scheme) [SICP ex. 2.46] add-vect, sub-vect, scale-vect

Exercise 2.46. A two-dimensional vector v running from the origin to a point can be represented as a pair consisting of an x-coordinate and a y-coordinate. Implement a data abstraction ...
1
vote
1answer
110 views

(Scheme ) [SICP ex. 2.45] Write a general purpose “split” function {for SICP's imaginary language}

From SICP 2.2.4: The textbook has already defined a function (right-split ...) as follows: (define (right-split painter n) (if (= n 0) painter (let ((smaller (right-split painter (- n ...
3
votes
4answers
429 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 ...
5
votes
4answers
640 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 ...
0
votes
1answer
110 views

(Scheme) [SICP ex. 2.40] unique-pairs

From the section called Nested Mappings Exercise 2.40. Define a procedure unique-pairs that, given an integer n, generates the sequence of pairs (i,j) with 1< j< i< n. Use ...
2
votes
2answers
330 views

LISP-like list class.

So, here's my code: public class NList : SExp, IEnumerable<Object> { private Object _car; private NList _cdr; IEnumerator<Object> ...
3
votes
2answers
415 views

(scheme) [sicp ex. 2.39] 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: (define (reverse sequence) (fold-right (lambda (x ...
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 ...

1 2