Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [scheme]

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

Filter by
Sorted by
Tagged with
26 votes
1 answer
3k views

Merge sort in Scheme

...
C. K. Young's user avatar
  • 2,342
23 votes
1 answer
561 views

Is this IRC bot utility library Racket-y enough?

To help myself learn Racket, I ported a simple JavaScript ircbot module I wrote for Node.js to Racket. The Racket version is built atop the Racket irc package, so ...
Alexis King's user avatar
  • 3,172
11 votes
1 answer
566 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 ...
John F. Miller's user avatar
10 votes
2 answers
5k views

Sum of squares of two largest of three numbers

Given the following problem (SICP Exercise 1.3): Define a procedure that takes three numbers as arguments and returns the sum of squares of the two largest numbers. I wrote the following (...
jaresty's user avatar
  • 2,243
10 votes
1 answer
876 views

WebSocket-based API library in Racket

I've developed a library in (typed) Racket that wraps a WebSocket-based API. The API itself is very simple—it operates via a series of three-letter commands optionally followed by a JSON-encoded ...
Alexis King's user avatar
  • 3,172
8 votes
1 answer
539 views

Find the Hardy–Ramanujan number using R5RS scheme

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 hoped it was ...
Shannon Severance's user avatar
8 votes
3 answers
936 views

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. ...
jaresty's user avatar
  • 2,243
8 votes
1 answer
294 views

Peter Norvigs' lis.py in c++17

I wanted to try convert Peter Norvigs' Python Scheme interpreter to C++. I had tried this a few years before and failed abysmally but I saw that the latest C++ standard includes several features ...
Jaldhar's user avatar
  • 409
7 votes
2 answers
539 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 ...
Racheet's user avatar
  • 217
7 votes
1 answer
1k views

Code from "Write Yourself a Scheme in 48 Hours" tutorial

I recently went through this Haskell tutorial. I'd be interested in any thoughts or comments at all, in terms of improving the structure, order, haskell conventions, or that long, kind of ugly eval ...
Irene Papakonstantinou's user avatar
7 votes
2 answers
176 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 ...
jaresty's user avatar
  • 2,243
6 votes
4 answers
682 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 ...
ArthurChamz's user avatar
6 votes
2 answers
7k views

Cube root (Newton's method)

Newton's method for finding cube roots states that for any given \$x\$ and a guess \$y\$, a better approximation is \$\dfrac{(\dfrac{x}{y^2} + 2y)}{3}\$. What do you think of this code for finding a ...
jaresty's user avatar
  • 2,243
6 votes
1 answer
1k 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 ...
cobie's user avatar
  • 447
6 votes
3 answers
2k views

Eight-queens puzzle

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 ...
jaresty's user avatar
  • 2,243
6 votes
1 answer
1k views

Seeking 5 primes such that concatenating any two of them produces another prime

I have a program which solves Project Euler problem 60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be ...
user2609980's user avatar
6 votes
1 answer
407 views

Fisher-Yates shuffle in Scheme

There are many ways to shuffle lists; for example, Racket's built-in shuffle assigns each list element with a random number as a sort key, then sorts the list, ...
C. K. Young's user avatar
  • 2,342
6 votes
1 answer
154 views

Simon Says in Scheme

Ok, it's not completely like Simon Says, since it's text-based. There is nothing about memorizing based on visual cues and/or sound here, just memorizing long sequences of numbers. I wanted to do it ...
user avatar
6 votes
1 answer
510 views

Purely functional Sieve of Eratosthenes

Many implementations of Sieve of Eratosthenes (used to find prime numbers up to a given n) use a temporary mutable array to keep track of which numbers are composites. I'm looking to write a purely ...
C. K. Young's user avatar
  • 2,342
6 votes
1 answer
1k views

All possible ways of merging two lists while keeping their order

I am writing a function gives all possible ways of merging two ordered lists such that in the merged list, the elements are still ordered according to the elements in their respective starting list. ...
samlaf's user avatar
  • 163
6 votes
3 answers
2k views

Insertion sort in Scheme

Inspired by my merge sort in Scheme, I thought I'd try my hand at implementing other sorting algorithms, starting with simple ones (like insertion sort) and working my way up. So, here we go: ...
C. K. Young's user avatar
  • 2,342
6 votes
1 answer
478 views

Redefine count-leaves as an accumulation

Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: ...
jaresty's user avatar
  • 2,243
5 votes
2 answers
12k 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). ...
Rajesh Bhat's user avatar
5 votes
1 answer
199 views

Schemey - lexer

1Note: This is the first post in - hopefully - a series of posts I plan to make. Project background Schemey is a project I've been working on for the past 3-4 weeks. It is an implementation of a ...
Chris's user avatar
  • 1,026
5 votes
1 answer
312 views

Extend sums and products functions

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 ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
199 views

Finding next perfect number - brute force

A “perfect number” is defined as a number equal to the sum of all its factors less than itself. For example, the first perfect number is 6, because its factors are 1, 2, 3, and 6, and 1+2+3=6. The ...
lightning_missile's user avatar
5 votes
1 answer
305 views

Simple evaluator of Scheme-like expressions in Haskell

This is my first nontrivial Haskell program: ...
Richard Cook's user avatar
5 votes
2 answers
3k views

Insert-everywhere function

This is HtDP Excercise 12.4.2: 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 first ...
Rajesh Bhat's user avatar
5 votes
1 answer
547 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 ...
jaresty's user avatar
  • 2,243
5 votes
2 answers
3k views

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: ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
5k views

Matrix multiplication and dot-product

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 ...
jaresty's user avatar
  • 2,243
5 votes
1 answer
442 views

Sieve of Eratosthenes in Scheme (R7RS)

I've seen many implementations of Sieve of Eratosthenes in Scheme, but I thought I'd try to write one that is both space- and time-efficient: Space-efficient: I use R7RS bytevectors as a bitset, ...
C. K. Young's user avatar
  • 2,342
5 votes
1 answer
224 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 ...
jaresty's user avatar
  • 2,243
5 votes
0 answers
611 views

Standard Algebraic Derivative Calculator

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 ...
jaresty's user avatar
  • 2,243
4 votes
4 answers
16k views

Splitting a list in Racket

I am working my way into learning a bit of Scheme (actually, Racket) with the help of a few practical problems to solve. In this case, I want to split a flat list of symbols at a certain delimiter ...
Stefano Sanfilippo's user avatar
4 votes
2 answers
889 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 ...
cobie's user avatar
  • 447
4 votes
2 answers
471 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 ...
ithisa's user avatar
  • 141
4 votes
1 answer
195 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 ...
jaresty's user avatar
  • 2,243
4 votes
1 answer
2k views

GCD - is this solution iterative?

Using the property that GCD(a, b) = GCD(b, r) where r is the remainder when you compute (a / b), you can write a recursive function as follows: ...
jaresty's user avatar
  • 2,243
4 votes
1 answer
167 views

RPN calculator in Chicken Scheme

My first attempt at Scheme (Chicken Scheme) - a simple RPN calculator. Please comment on exception handling as well as the general coding style. Here is the code: ...
Anonimista's user avatar
4 votes
1 answer
286 views

SICP - exercise 2.69 - generate a huffman tree from a set of ordered leaves

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 tree ...
lightning_missile's user avatar
4 votes
1 answer
2k views

String Concatenation in Scheme

As plain r5rs is lacking in useful string processing utilities, such as string-split and string-join (I'm using MIT/GNU Scheme), I decided to implement my own. My procedure, string-join, works just ...
Christopher Matthews's user avatar
4 votes
2 answers
2k views

Converting English Measurements to Metric and vice versa

I finished answering Exercise 3.3.1 of How to Design Programs where: Exercise 3.3.1. The United States uses the English system of (length) measurements. The rest of the world uses the metric ...
exilyte's user avatar
  • 41
4 votes
1 answer
131 views

Recamán's Sequence in Racket

I just started learning Racket as my first lisp dialect so after getting used to the syntax I implemented the Recamán's sequence. Apart from the style, I'd also like to know if my code is a linear ...
xenthreaded's user avatar
4 votes
1 answer
87 views

Standalone GNU Makefile tracking `@import` statements in Sass

The following is a (working) excerpt from the Makefile I want to use in web projects. I wanted this Makefile to contain all the necessary code and not rely on other self-written files. Partly, because ...
Oliver Scholz's user avatar
4 votes
1 answer
1k views

Abstract tree-map function

Exercise 2.31. Abstract your answer to exercise 2.30 to produce a procedure tree-map with the property that square-tree could be defined as ...
jaresty's user avatar
  • 2,243
4 votes
1 answer
198 views

Is this a good way to implement let-with?

I've implemented a let-with macro that takes an association list, keyed by symbols, that enables code to bind their corresponding values to local variables. It's ...
C. K. Young's user avatar
  • 2,342
4 votes
1 answer
77 views

Merging list tails in Scheme

In my last post, I wrote a long, non-general tail-merging† facility for insertion sort. I thought I should instead write a general-purpose tail-merging function, that works even when the two lists are ...
C. K. Young's user avatar
  • 2,342
4 votes
0 answers
67 views

Scheme interpreter in QBASIC

I wrote an interpreter for Scheme which includes stop and copy garbage collection. ...
Dean Menezes's user avatar
4 votes
0 answers
353 views

Solving Sudokus in Scheme Using Simulated Annealing

This program's purpose is to solve sudokus using simulated annealing. It first fills all the 3x3 blocks in the sudoku such that every block is filled with 1-9. It also builds a list of pairs of ...
Lara's user avatar
  • 195