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

Brute-force algorithm to solve allocation/assignment in Racket

The situation: A certain number of kids come to a library and each of them wants to borrow a book. Since there is only one copy of each book in the library, each child must say which book they would ...
0 votes
2 answers
83 views

Trie Data Structure in R7RS Scheme

Making the transition from R6RS Scheme to R7RS has been very educational and fun. Chibi Scheme is my favorite because of its close compliance with the standard. When starting a new project, I wanted ...
2 votes
1 answer
125 views

Performant Text File Reading in Scheme

I have been experimenting with methods to read large text files into a Scheme program as a single string in a performant manner. Development has been in R7RS Scheme, specifically Chibi-Scheme. After ...
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: ...
4 votes
0 answers
66 views

Scheme interpreter in QBASIC

I wrote an interpreter for Scheme which includes stop and copy garbage collection. ...
2 votes
2 answers
7k views

Remove the last occurrence of an item in a list

The objective is given a list of items, remove the last occurrence of a specified item from the list using only user-defined functions except for very basic built-in ones like car, cdr, =, - etc. For ...
3 votes
0 answers
51 views

Idiomatic PRNG in Scheme

For reasons that are too dreary to detail, I need to reproduce several pseudo random number generators in different languages. It mostly involves translating ancient C and FORTRAN code. No problems ...
1 vote
1 answer
9k 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 ...
2 votes
0 answers
54 views

Deterministic and nondeterministic finite automata in scheme

This is the implementation of both Deterministic Finite Automata (DFAs) and Nondeterministic Finite Automata (NFAs) on r7rs scheme, using only SRFI 1. The file automata.scm contains the implementation ...
3 votes
0 answers
115 views

Mini Scheme interpreter

Right now, I'm working on an interpreter for a subset of the Scheme programming language. It supports lambdas, let/let*/letrec, procedures, combinations, ...
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 ...
1 vote
0 answers
110 views

Simply Scheme book: "functions.scm", How to use basic language constructs to create interactive prompt for function application

While reading Simply Scheme by Brian Harvey and Matthew Wright: Part I: Chapter 2 Functions In this chapter you are going to use the computer to explore functions, but you are not going to use the ...
1 vote
1 answer
543 views

"filter" function in Scheme

I know this is a bit elementary, but I am highly uncomfortable writing Scheme code, and I want to make sure that what I'm doing is good practice. I know mutation is frowned upon in Scheme. I have no ...
1 vote
2 answers
372 views

Flattening a List containing Empty Lists

As part of a text buffer implemented as a piece table, there is an often called procedure to flatten a nested list of character lists. The function is part of constructing substrings of the buffer for ...
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 ...
3 votes
0 answers
123 views

Performance issue regarding Project Euler #60 in Scheme

I solved Project Euler #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 prime. For example, taking 7 ...
2 votes
0 answers
80 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. ...
1 vote
0 answers
86 views

Is this zip function ok?

A slick way to write the zip function in Scheme/Racket: (define (zip . lsts) (apply map list lsts)) (zip '(a b c) '(1 2 3)) '((a 1) (b 2) (c 3)) Is using cons ...
-1 votes
1 answer
70 views

Is this OR procedure correct? [closed]

...
1 vote
1 answer
502 views

Implementations of unzip in Racket

I've been practicing my folds and tail-call recursive programming, and I wanted to work on unzip for the general case as opposed to just pairs. This was very easy ...
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: ...
3 votes
1 answer
164 views

Lex Scheme in Rust

I'm writing a Scheme interpreter in Rust, and the first step is the parser. I've finished the lexer, and would like to see what people think of it before I go any further. ...
1 vote
0 answers
649 views

Cartesian product in racket (Is append-map okay?)

I've read several places that say it's really bad to use append, and I understand why. I read somewhere that it was never even correct to use ...
2 votes
1 answer
52 views

Calculate the sum of the square of two biggest numbers out of three

I'm reading Structure and Interpretation of Computer Programs. In the first exercise, I came across a programming problem to add the squares of the 2 bigger numbers out of 3 numbers. I came up with ...
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 (...
1 vote
1 answer
2k views

Scheme function to duplicate every element of a list a specified number of times

This code takes a list and a integer and duplicates every element in the list the specified number of times. ...
3 votes
2 answers
2k 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. ...
3 votes
1 answer
200 views

SICP 1.3 Sum of Squares of two largest numbers

Define a procedure that takes three numbers as arguments and returns the sum of squares of the two largest numbers. I'm using just the machinery that was developed so far in SICP to be true to the ...
2 votes
1 answer
5k views

Remove first occurrence 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 done ...
2 votes
1 answer
311 views

Scheme: FSM substring search

I have been working on a function that return a FSM that searches a specific word based on the argument of the constructor. The idea was to use those routines as means to learn about regular ...
0 votes
2 answers
1k views

Iterative "counting change" implementation in mit-scheme

Here is my iterative implementation of the Counting change example in SICP. Please note that I'm a beginner, which means I only know the basic syntax for the time being. Requirement: How many ...
1 vote
1 answer
3k views

Binary search tree insertion in Racket

I am learning Racket and implemented a BST insert function (insert tree n) where the format for a BST node is ...
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 ...
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 ...
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 ...
3 votes
2 answers
750 views

SICP - exercise 1.7 better end test for square root approximation

Here is exercise 1.7 from SICP: Exercise 1.7 The good-enough? test used in computing square roots will not be very effective for finding the square roots ...
1 vote
1 answer
822 views

Stack calculator in Racket

I have implemented a stack calculator based on this programming task. I wondered if a more experienced racketeer could give me feedback and tell me if I am missing anything in Racket that would enable ...
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 ...
1 vote
1 answer
180 views

Bash script that creates a local environment for CHICKEN scheme (like virtualenv for Python)

Usage To create a localenv called sicp, do $ localenv sicp Activate the localenv: $ . sicp/bin/activate Check installed eggs in ...
3 votes
0 answers
676 views

Knapsack solution in Scheme/Racket

Following is my solution to Knapsack problem using all combinations of the sent list of items (in Racket programming language). Although it is very short, I am sure it can be improved in many ways. <...
2 votes
1 answer
103 views

Structuring flat html structure into a tree

Given an html page with heading tags such h1, h2 through h6 and ...
1 vote
2 answers
96 views

Proper use of tail recursion while forming a list

As a project to better develop my understanding of functional programming, I am writing a prime number generator in Scheme. I am using a simple brute-force algorithm to detect whether a number is ...
3 votes
1 answer
1k views

equal? predicate for lists

Exercise 2.54 Two lists are said to be equal? if they contain equal elements arranged in the same order. For example, ...
3 votes
2 answers
3k views

Sudoku solver in Racket

I have written following code to solve Sudoku puzzles in Racket (a Scheme/Lisp derivative programming language). Following relatively simple code appears to work but are there any bugs in it or can it ...
1 vote
1 answer
161 views

Extending basic differentiator to handle more kinds of expressions

Exercise 2.56. Show how to extend the basic differentiator to handle more kinds of expressions. For instance, implement the differentiation rule $$ \frac{d(u^n)}{dr} = nu^{n-1}(\frac{...
2 votes
1 answer
658 views

Adding, subtracting, and multiplying a vector by a scalar

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 ...
3 votes
1 answer
922 views

A list builder or list accumulator

Imagine a UTF-8 decoder that takes a list of bytes and returns human-readable code points like: ...
2 votes
1 answer
507 views

Approximating pi/4 using Wallis Product - SICP exercise 1.31

From SICP The sum procedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures. Write an analagous procedure called product that ...
26 votes
1 answer
3k views

Merge sort in Scheme

...
1 vote
2 answers
2k views

Pascal's triangle in mit-scheme

As suggested by the name of source file (ex1.12.scm), I just started learning mit-scheme by reading SICP. In Exercise 1.12, I'm asked to "compute elements of Pascal'...