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

16
votes
1answer
242 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 ...
10
votes
1answer
403 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 ...
9
votes
1answer
207 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 ...
8
votes
0answers
778 views

Merge sort in Scheme

...
7
votes
2answers
382 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 ...
7
votes
3answers
834 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. ...
7
votes
2answers
164 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 ...
6
votes
4answers
297 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 ...
6
votes
1answer
3k 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 ...
6
votes
1answer
419 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 ...
6
votes
1answer
56 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, ...
6
votes
1answer
72 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 ...
5
votes
2answers
4k 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). ...
5
votes
2answers
2k 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 ...
5
votes
1answer
439 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 ...
5
votes
1answer
107 views

Simple evaluator of Scheme-like expressions in Haskell

This is my first nontrivial Haskell program: ...
5
votes
2answers
644 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 ...
4
votes
1answer
435 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 ...
4
votes
2answers
298 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 ...
4
votes
1answer
178 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 ...
4
votes
1answer
879 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: ...
4
votes
2answers
131 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 ...
4
votes
1answer
239 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 ...
4
votes
3answers
952 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 ...
4
votes
1answer
875 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 ...
4
votes
1answer
171 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 ...
4
votes
1answer
94 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, ...
4
votes
2answers
947 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: ...
4
votes
1answer
2k 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 ...
4
votes
1answer
366 views

Redefine count-leaves as an accumulation

Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: ...
4
votes
0answers
152 views

Quick Insert Merge Sort

I have written this code to sort a list of numbers, in increasing order. It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go ...
3
votes
2answers
95 views

This snippet of scheme calculates a value in pascal's triangle

I'm working through SICP and have implemented exercise 1.11 (Pascal's Triangle). What I'm curious about here is performance considerations by defining functions within the main function. I would ...
3
votes
2answers
554 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 ...
3
votes
2answers
105 views

split-string for R7RS

A split-string function seems to be missing in R7RS. I came up with the following implementation today: ...
3
votes
2answers
261 views

Rosalind's 3rd problem in Scheme

I have an imperative programming background and I've decided to study functional programming by applying it to problems found on sites such as Project Euler and Rosalind. My language of choice is ...
3
votes
1answer
794 views

Iterative exponentiation process

From SICP's 1.24: (Exponentiation) (you may need to click through and read ~1 page to understand) Exercise 1.16. Design a procedure that evolves an iterative exponentiation process that ...
3
votes
1answer
249 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 ...
3
votes
1answer
34 views

Digit Summing Function

I'm working through the common divisibility tests, and implementing them in Racket. I'm working on divisible by three, for which I thought it'd be nice to keep summing until I got to a single digit ...
3
votes
1answer
427 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
1answer
243 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". ...
3
votes
1answer
345 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
1answer
581 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: ...
3
votes
0answers
105 views

Graphical editor with geometric intersection

If it is possible I would like some comments on the overall style of the program. It feels like I am writing the whole program as one big script and I'm not sure how to break it down into several ...
3
votes
0answers
135 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 ...
3
votes
3answers
80 views

Sum of squares of 2 largest numbers out of a list of 3 numbers

The problem is: Define a procedure that takes 3 number arguments and returns the sum of the squares of the 2 largest numbers. I am a CS graduate and I am revising my university notes. This is my ...
2
votes
3answers
249 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 ...
2
votes
2answers
1k views

Use Newton's Method to compute sqrt(x)

Given the following task: Use Newton's method to compute the square root of a number. Newton's method involves successive approximation. You start with a guess, and then continue averaging ...
2
votes
1answer
595 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 ...
2
votes
1answer
2k views

Pascal's triangle

1 1 1 1 2 1 1 3 3 1 What do you think of this solution for computing Pascal's triangle? ...
2
votes
1answer
351 views

Solving the N-queens puzzle the Racket or Scheme way

My final version is a direct translation from Python. Thanks to build-in support for generator, its speed is almost the same as Python. As I quite like using generator and list comprehension in ...