Questions tagged [scheme]
Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.
172
questions
0
votes
2
answers
73
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
92
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 ...
2
votes
1
answer
70
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 ...
4
votes
0
answers
57
views
Scheme interpreter in QBASIC
I wrote an interpreter for Scheme which includes stop and copy garbage collection.
...
1
vote
0
answers
29
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.
...
3
votes
0
answers
50
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 ...
2
votes
0
answers
47
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
106
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
88
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
2
answers
335
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 ...
1
vote
1
answer
443
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
113
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 ...
1
vote
0
answers
74
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
67
views
1
vote
1
answer
478
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 ...
3
votes
1
answer
159
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
646
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 ...
2
votes
1
answer
294
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 ...
4
votes
1
answer
164
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.
...
8
votes
1
answer
241
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
128
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
86
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
807
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
556
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-...
3
votes
2
answers
709
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
177
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
671
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
101
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
95
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
196
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 ...
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 ...
2
votes
1
answer
497
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 ...
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'...
3
votes
1
answer
326
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 ...
4
votes
0
answers
329
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 ...
3
votes
0
answers
321
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
136
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 ...
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
1
answer
470
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
221
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
96
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 ...
2
votes
1
answer
292
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
507
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 ...
3
votes
1
answer
198
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 ...
3
votes
1
answer
969
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 ...
2
votes
1
answer
420
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 ...