Scheme is a functional language in the Lisp family.

learn more… | top users | synonyms

2
votes
1answer
76 views

Why is this RC4 code in Racket so slow?

According to shootout.alioth.debian.org, Racket is not much slower than C#, at least in the same order of magnitude due to its JIT compiler. However, I'm seeing at least two degrees of magnitude ...
0
votes
0answers
36 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
0answers
11 views

A with-input-from-pipe for Guile

I wrote this with-input-from-pipe function for Guile. I’m not that comfortable with dynamic-wind or set-current-input-port, so I’d appreciate any critiques. (use-modules (ice-9 popen) ...
0
votes
0answers
29 views

`multiple-value-call` in Scheme

Common Lisp has a "special operator" called multiple-value-call, which does something similar to Scheme's call-with-values but with a nicer syntax, and allowing multiple producers (unlike ...
0
votes
1answer
29 views

Check if element is a member of all sets in Scheme

Here is a function that checks whether an alement a is a member of every set in list l-set. I don't like the fact that it returns #t for an empty list of sets. What would be a clean fix to this ...
2
votes
0answers
48 views

Quick Insert Merge Sort

I have written a code for sorting a list of numbers in increasing order. It is a combination of quick sort, insertion sort and merge sort. I take the first element of the list as Pivot. Then I go ...
0
votes
0answers
27 views

String Matching

I recently came across a lecture on DFA. I tried to use it to determine whether a given 'search string' is found in the 'input string'. Please tell me if there is a better way (display "Enter input ...
0
votes
1answer
54 views

Numeric Value for a Date, dateAdd and dateDiff

In MS excel, a date is also represented as a numeric value, with 1-Jan-1900 as the first day. Also in VBA there are dateAdd and dateDiff functions. dateAdd adds a given unit (day, month quarter or a ...
2
votes
1answer
103 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 ...
4
votes
1answer
94 views

Improving a priority queue sketch in Racket/Scheme

I just put together the skeletons for a priority queue using a binary heap in racket/scheme. Using racket/scheme is all about the educational experience and I was wondering if anyone wants to ...
3
votes
1answer
132 views

A Simple Unix Filter in Racket - Learning the Racket Way

I've written the following simple filter in Racket as my first Racket program and am wondering if I am writing it in an "idiomatic Racket style". #! /usr/bin/env racket #lang racket (require ...
2
votes
2answers
240 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
164 views

Scheme, first timer first program, simple list removal technique

I have started my hand at writing some scheme code. I am trying to get the first n primes. I plan to do so but first getting a list from 2 to m, and doing the following algorithm. Remove the first ...
3
votes
2answers
221 views

A little scheme programming challenge

I am learning scheme to get something new from a programming language and this code below is the solution to Project Euler question 21 but the code runs 10x slower than the listed Python code when I ...
1
vote
1answer
79 views

Optimize this Scheme-written chess engine module

I'd like to know how to optimize this by shadowing symbols 'lo and 'hi inside nested function f. I guess CPS conversion would solve this but how? ;; chess engine - early development ;; Alist: (cons ...
2
votes
0answers
321 views

Merge sort in Scheme

(define (merge-sort lst (lt? <)) (let sort ((lst lst) (size (length lst)) (flip #f)) (define (merge l r (res '())) (cond ((null? l) (append-reverse r res)) ...
2
votes
0answers
113 views

Insert-everywhere

This is HTDP Excercise 12.4.2 :- Page 161 Develop a function insert-everywhere. It consumes a symbol and a list of words. The result is a list of words like its second argument, but with the ...
1
vote
0answers
126 views

SICP ex. 2.42 “eight queens puzzle”

The problem can be found online here. In short, we're given the following function definition, that will recursively generate all the possible solutions for the "eight-queen-problem". (define ...
1
vote
0answers
68 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 ...
3
votes
2answers
1k views

A newbie's Program to sort a list in scheme (DrRacket)

Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function). (define (sort-list l) (define first-element (if (not (null? l)) (car l) 0)) (cond ...
2
votes
1answer
319 views

An in-nested sequence generator for racket scheme

I've been learning about racket sequences and noticed a hole where nested iteration is concerned. We have the in-parallel construct but no in-nested construct. There's the for*/... family, but ...
3
votes
1answer
393 views

A list builder or list accumulator

Imagine a UTF-8 decoder that takes a list of bytes and returns humman readable code points like: > (utf-8->human-readable-code-points '(32 32 195 160 160)) ("u+0020" "u+0020" "u+00E0" ("Error: ...
3
votes
0answers
644 views

integrating SFML and Box2D lib, and a Mass Production Shape Factory

i just wrote two new headers: one that integrates Box2D and SFML by a class called BodyRep which creates/ is a graphic representation of any body, and one that produces huge amounts of uniform shapes, ...
6
votes
2answers
142 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
130 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
131 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 ...
0
votes
1answer
100 views

(Scheme) how to create a function that multiplies all numbers between “a” and “b” with do loop

I'm making a function that multiplies all numbers between an "a" input and a "b" input with do loop. If you please, check my function and say what's wrong since I don't know loops very well in Scheme. ...
2
votes
0answers
97 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
152 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
170 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
154 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
101 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 ...
5
votes
1answer
394 views

Find the Hardy–Ramanujan number using R5RS scheme. Please suggest improvements in idiom and calculations.

I remember once going to see [Srinivasa Ramanujan] when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I ...
1
vote
0answers
248 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
373 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
344 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
213 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
652 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
231 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
139 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
148 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
386 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
240 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 ...
4
votes
0answers
296 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
157 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
80 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
307 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
103 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
114 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
453 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 ...