Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.

learn more… | top users | synonyms

7
votes
2answers
343 views

My first accumulators

Notes I'm working my way through SICP, and as I got very confused by the section on folds, I decided to try to implement foldr in scheme and javascript to understand how it works differently with ...
4
votes
4answers
74 views

Project Euler 1 (sum of multiples of 3 or 5 under 1000)

I solved this a while ago. In the moment I solved it I was learning Scheme and, well, I still am. I'm not looking at the best solution (I searched for it and coded it already, in Python), what I want ...
2
votes
0answers
16 views

Completing a Graph in Scheme

For the record, this is part of a homework assignment, but I have already implemented a solution. I am simply wondering if there is a better way to do it. Background: I am asked to write a procedure, ...
2
votes
1answer
52 views

lexical scope v let in scheme functions

I've been chewing through a bit of The Little Schemer and the Peano examples got me thinking about operation size and time. I got some help on making Peano Multiplication linear -- however ...
1
vote
1answer
40 views

Linear Peano multiplication in Scheme?

I've been running through The Little Schemer, and have hit the example of Peano multiplication. The solution is given in TLS (reproduced below) -- however what interests me is the order of the ...
0
votes
1answer
84 views

remove first occurance of element from list

As explained here i'm learning a limited subset of scheme. My task has been to sort a numerical list. To implement a simple insertion sort, i need to remove a single element from a list. I've ...
1
vote
1answer
176 views

sorting a numerical list using basic scheme

I would like some feedback on the appropriate way of ordering a numerical list using the most elementary scheme functions (sorry, i realise that elementary is not ...
3
votes
2answers
203 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
60 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
24 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 ...
0
votes
0answers
44 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 ...
0
votes
1answer
36 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 ...
2
votes
0answers
86 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 ...
1
vote
0answers
36 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 ...
0
votes
1answer
100 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 ...
3
votes
1answer
183 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 ...
5
votes
1answer
239 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
162 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". ...
2
votes
2answers
347 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: ...
3
votes
1answer
230 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 ...
3
votes
2answers
283 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
107 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? ...
5
votes
0answers
547 views

Merge sort in Scheme

...
2
votes
0answers
370 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
137 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". ...
1
vote
0answers
71 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 ...
5
votes
2answers
2k views

Sorting a list of numbers in increasing order

Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function). ...
2
votes
1answer
436 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 ...
3
votes
1answer
470 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: ...
7
votes
2answers
156 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
139 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
143 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
104 views

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 ...
3
votes
0answers
117 views

Representing 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 ...
4
votes
1answer
180 views

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
251 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. ...
1
vote
1answer
196 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
127 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
423 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
275 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
513 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
504 views

Encode-symbol for Huffman tree

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. ...
2
votes
1answer
265 views

Search on a binary tree

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
748 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
267 views

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: ...
1
vote
1answer
164 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 ...
4
votes
1answer
165 views

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
576 views

Union-set operation for unordered-list representation of sets

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
281 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 ...
5
votes
0answers
335 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 ...