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

2
votes
1answer
42 views

SICP exercise 1.3 - sum of squares of two largest of three numbers

From SICP Exercise 1.3: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. Square is: ...
1
vote
1answer
44 views

Functional coffee dispenser [closed]

Inspired by this question, I decided to rewrite this code in Scheme, as I'm working through SICP right now. Any feedback welcome. ...
4
votes
1answer
46 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 ...
3
votes
1answer
50 views

SICP exercise 2.28 - counting leaves in a tree (recursive process)

From SICP Exercise 2.28: Write a procedure fringe that takes as argument a tree (represented as a list) and returns a list whose elements are all the leaves of the tree arranged in ...
2
votes
2answers
48 views

SICP - exercise 2.27 - reversing elements of a list and sublists

From SICP Exercise 2.27: Modify your deep-reverse procedure of Exercise 2.18 to produce a deep-deep-reverse procedure that takes a list as argument and returns as its value the list with its ...
1
vote
1answer
42 views

SICP - exercise 2.5 - representing pairs of nonnegative integers using only numbers and arithmetic operations

From SICP Exercise 2.5: Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product ...
2
votes
1answer
21 views

Replacing elements from a list and its sublists - part II

This is sort of a follow-up to Replacing elements from a list and its sublists but now there are arbitrary numbers of words that would be replaced stored in a list. Now write substitute2 that takes ...
1
vote
2answers
34 views

SICP - exercise 2.20 - same-parity

Exercise 2.20.   The procedures +, *, and list take arbitrary numbers of arguments. One way to define such procedures is to use define with dotted-tail notation. In a procedure definition, a ...
3
votes
1answer
40 views

Reversing a list without (append)

I would like to reverse a list using cdr, car and cons. Since lists in lisp are asymmetrical (can only insert at the beginning), I am interested on how one would write a procedure to do that without ...
3
votes
1answer
44 views

Replacing elements from a list and its sublists

Write a procedure substitute that takes three arguments: a list, an old word, and a new word. It should return a copy of the list, but with every occurrence of the old word replaced by the new word, ...
5
votes
1answer
46 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 ...
3
votes
1answer
49 views

Replacing words from a sentence

I am extremely new at scheme and I am doing this problem from here: Write a procedure switch that takes a sentence as its argument and returns a sentence in which every instance of the words I ...
1
vote
1answer
23 views

Looping in Scheme

(define loop (lambda (x proc) (when (not (= x 0)) (eval proc) (loop (- x 1) proc)))) Is this the best way to create a loop function in Scheme?
4
votes
1answer
38 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 ...
6
votes
3answers
71 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: ...
2
votes
1answer
55 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 ...
3
votes
1answer
50 views

Another Scheme Mergesort

Here's a merge sort I wrote trying to learn Scheme. ...
3
votes
1answer
68 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 ...
2
votes
0answers
26 views

A scheme macro that defines the "where“ syntax

A new scheme user trying to use syntax-rules to define something like the Haskell where keyword. Sometimes this is useful since ...
1
vote
1answer
144 views

Is there something wrong with my remove-duplicates implementation in Scheme?

For an assignment I handed in this code to remove duplicates from a stream. ...
2
votes
3answers
1k 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 ...
6
votes
1answer
93 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, ...
3
votes
3answers
230 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 ...
3
votes
1answer
52 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
0answers
126 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 ...
10
votes
1answer
313 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 ...
3
votes
2answers
151 views

split-string for R7RS

A split-string function seems to be missing in R7RS. I came up with the following implementation today: ...
4
votes
1answer
128 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, ...
1
vote
1answer
63 views

Extracting values from a list

I had already solved this problem, but in an unnecessarily convoluted way that seems too specific. Can this be done better? From a list: (8 "layer-name" 10 x1 20 y1 10 x2 20 y2 10 x3 20 y3) 8, ...
6
votes
1answer
87 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
1answer
136 views

Simple evaluator of Scheme-like expressions in Haskell

This is my first nontrivial Haskell program: ...
2
votes
0answers
94 views

Calculating continued fraction expansions (without requiring arbitrary precision decimals)

I'm writing a program that will compute a continued fraction expansion of a number. I've been learning Racket/Scheme for a few weeks and I wanted to see what I can do better. Usage: This program ...
2
votes
1answer
260 views

Finding the subsets of a set

I am trying to write a procedure that finds the power set of a list, that is, the set of 2n subsets (where n is the number of elements in the list). I simply quite find all the subsets. I feel my code ...
1
vote
1answer
156 views

Reading/writing null-terminated strings from socket

I need to handle C style ('\0' delimited) strings from/to a socket and came up with this as a first attempt: ...
16
votes
1answer
300 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 ...
2
votes
1answer
446 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 ...
4
votes
2answers
282 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 ...
5
votes
1answer
568 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 ...
3
votes
2answers
99 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
331 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 ...
7
votes
2answers
396 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 ...
6
votes
4answers
361 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 ...
1
vote
0answers
27 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
83 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
73 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 ...
1
vote
1answer
690 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
2k 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 ...
4
votes
2answers
329 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 ...
1
vote
0answers
98 views

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 the sequences that pass before the next occurrence of itself. Some questions ...
1
vote
0answers
37 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 ...