Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take 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
3 votes
0 answers
32 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 ...
user avatar
  • 195
2 votes
0 answers
30 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 ...
user avatar
  • 854
2 votes
0 answers
54 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, ...
user avatar
1 vote
0 answers
46 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 ...
user avatar
0 votes
2 answers
103 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 ...
user avatar
  • 195
1 vote
1 answer
109 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 ...
user avatar
3 votes
0 answers
83 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 ...
user avatar
  • 151
1 vote
0 answers
50 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 ...
user avatar
  • 119
-1 votes
1 answer
58 views

Is this OR procedure correct? [closed]

...
user avatar
  • 119
1 vote
1 answer
388 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 ...
user avatar
  • 809
3 votes
1 answer
127 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. ...
user avatar
1 vote
0 answers
526 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 ...
user avatar
  • 809
2 votes
1 answer
49 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 ...
user avatar
  • 31
2 votes
1 answer
243 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 ...
user avatar
1 vote
0 answers
131 views

SICP exercise 3.47 - implementing a semaphore in terms of mutexes

Can anyone check my solution to the first part of exercise 3.47 in SICP? Thanks. Exercise 3.47: A semaphore (of size n) is a generalization of a mutex. Like a mutex, a semaphore supports acquire and ...
user avatar
4 votes
1 answer
141 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: ...
user avatar
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 ...
user avatar
1 vote
1 answer
1k 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. ...
user avatar
  • 33
8 votes
1 answer
219 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 ...
user avatar
  • 357
4 votes
1 answer
113 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 ...
user avatar
4 votes
1 answer
76 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 ...
user avatar
1 vote
1 answer
674 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 ...
user avatar
1 vote
0 answers
494 views

Solution to N-queens problem in Racket

I am using following method to solve N-queens problem for all possible solutions for a board. It seems to be smaller as well as faster than many commonly mentioned method. Also, since it is tail-...
user avatar
  • 221
1 vote
0 answers
246 views

Racket - temperature value converter

I'm giving myself programming challenges in various languages so that I can become a better problem solver i.e. focusing on problem abstraction and algorithm design, using various programming ...
user avatar
3 votes
2 answers
548 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 ...
user avatar
1 vote
1 answer
157 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 ...
user avatar
3 votes
0 answers
640 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. <...
user avatar
  • 221
2 votes
1 answer
85 views

Structuring flat html structure into a tree

Given an html page with heading tags such h1, h2 through h6 and ...
user avatar
  • 151
1 vote
2 answers
87 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 ...
user avatar
5 votes
1 answer
178 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 ...
user avatar
1 vote
0 answers
85 views

SICP - exercise 2.5 - Represent pairs of nonnegative integers

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 ...
user avatar
  • 551
1 vote
0 answers
128 views

SICP - exercise 2.3 - Implement a representation for rectangles in a plane

Exercise 2.3. Implement a representation for rectangles in a plane. (Hint: You may want to make use of exercise 2.2.) In terms of your constructors and selectors, create procedures that compute the ...
user avatar
  • 551
2 votes
2 answers
2k 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 ...
user avatar
  • 221
2 votes
1 answer
419 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 ...
user avatar
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 ...
user avatar
  • 551
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'...
user avatar
  • 551
3 votes
1 answer
296 views

Simplifying Macro-Generating Racket Macro

I'm trying to write a small macro library in Racket that extends a few of the racket/match functions I use, by printing which clause was expanded. While this seems ...
user avatar
4 votes
0 answers
258 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 ...
user avatar
  • 175
3 votes
0 answers
290 views

Converting a sentence string to a number in Scheme

I wrote a scheme procedure that converts strings such as "Two hundred and fifty" into a number like "250" that I can use in math calculations (It's for some Natural Language Processing project). Is ...
user avatar
1 vote
2 answers
129 views

Function that tests whether all items in a list are the same

The program consists of two functions: the helper predicate function singleton-list? that checks whether a given list contains only one item and the function that ...
user avatar
  • 297
2 votes
2 answers
6k 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 ...
user avatar
  • 297
3 votes
1 answer
444 views

Church Numerals

Here is exercise 2.6 from SICP: Exercise 2.6: In case representing pairs as procedures wasn’t mind-boggling enough, consider that, in a language that can manipulate procedures, we can get by ...
user avatar
3 votes
1 answer
194 views

SICP exercise 1.28 - miller-rabin primality test part II

This is a follow-up to SICP exercise 1.28 - miller-rabin primality test. Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; ...
user avatar
2 votes
1 answer
87 views

Find common factor of numbers in a list

This program calculates common factor for given numbers. The original use case is to find a possible resolution for pixel games that scale well with new screen resolutions (that's why I don't have any ...
user avatar
  • 121
2 votes
1 answer
243 views

SICP exercise 1.28 - miller-rabin primality test

From SICP Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; Rabin 1980). This starts from an alternate form of Fermat’s ...
user avatar
6 votes
1 answer
475 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 ...
user avatar
3 votes
1 answer
170 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 ...
user avatar
  • 232
2 votes
1 answer
689 views

SICP - exercise 1.12 - pascal's triangle

From SICP: Exercise 1.12: The following pattern of numbers is called Pascal’s triangle. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 . . . The numbers at the ...
user avatar
2 votes
1 answer
281 views

SICP - exercise 1.11 - tree recursion

From SICP Exercise 1.11: A function \$f\$ is defined by the rule that: \$f(n) = n\$ if \$n < 3\$, and \$f(n) = f(n-1)+2f(n-2)+3f(n-3)\$ if \$n >= 3\$. Write a procedure ...
user avatar
3 votes
1 answer
198 views

Square root calculation in Scheme (SICP Exercise 1.7)

I have done exercise 1.7 in SICP (calculate square root precision when change in guesses is under a certain value), but I am calling the change-in-precision function twice in each iteration, which ...
user avatar
  • 133