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
0 votes
0 answers
19 views

Parser for Context-Free Languages in Scheme

...
4 votes
0 answers
34 views

Scheme interpreter in QBASIC

I wrote an interpreter for Scheme which includes stop and copy garbage collection. ...
1 vote
0 answers
20 views

Scheme Procedure for Permuting Characters in a String

The following is a Scheme procedure to permute the characters in an input string. It outputs permutations of all lengths from 1 character up to the number of characters in the input string. ...
  • 215
3 votes
0 answers
37 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 ...
  • 215
2 votes
0 answers
33 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 ...
  • 854
3 votes
0 answers
63 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, ...
1 vote
0 answers
53 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 ...
0 votes
2 answers
127 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 ...
  • 215
1 vote
1 answer
153 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 ...
3 votes
0 answers
88 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 ...
  • 151
1 vote
0 answers
52 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 ...
  • 119
-1 votes
1 answer
62 views

Is this OR procedure correct? [closed]

...
  • 119
1 vote
1 answer
396 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 ...
  • 819
3 votes
1 answer
137 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
548 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 ...
  • 819
2 votes
1 answer
50 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 ...
  • 31
2 votes
1 answer
248 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 ...
's user avatar
1 vote
0 answers
133 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 ...
4 votes
1 answer
147 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: ...
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 ...
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. ...
  • 33
8 votes
1 answer
223 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 ...
  • 397
4 votes
1 answer
119 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
78 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 ...
1 vote
1 answer
699 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 ...
1 vote
0 answers
497 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-...
  • 241
1 vote
0 answers
255 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 ...
3 votes
2 answers
576 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
164 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
648 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. <...
  • 241
2 votes
1 answer
89 views

Structuring flat html structure into a tree

Given an html page with heading tags such h1, h2 through h6 and ...
  • 151
1 vote
2 answers
88 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 ...
5 votes
1 answer
185 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
0 answers
88 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 ...
  • 551
1 vote
0 answers
141 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 ...
  • 551
3 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 ...
  • 241
2 votes
1 answer
441 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 ...
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 ...
  • 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'...
  • 551
3 votes
1 answer
300 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 ...
's user avatar
4 votes
0 answers
265 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 ...
  • 175
3 votes
0 answers
300 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 ...
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 ...
  • 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 ...
  • 297
3 votes
1 answer
446 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 ...
3 votes
1 answer
206 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; ...
2 votes
1 answer
89 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 ...
  • 121
2 votes
1 answer
248 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 ...
6 votes
1 answer
483 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 ...
  • 2,322
3 votes
1 answer
182 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 ...
  • 232