Questions tagged [scheme]

Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.

29 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
572 views

Standard Algebraic Derivative Calculator

I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP: Exercise 2.58 Suppose we want to modify the differentiation program so that it ...
4
votes
0answers
297 views

Quick Insert Merge Sort

I have written this code to sort a list of numbers, in increasing order. It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go ...
4
votes
0answers
177 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 ...
4
votes
0answers
474 views

Search on a binary tree

From SICP: Exercise 2.66. Implement the lookup procedure for the case where the set of records is structured as a binary tree, ordered by the numerical values of the keys. I wrote the ...
3
votes
0answers
263 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. <...
3
votes
0answers
194 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
0answers
122 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 ...
3
votes
0answers
172 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 ...
3
votes
0answers
186 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
0answers
67 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: ...
2
votes
0answers
33 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 ...
2
votes
0answers
98 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 ...
2
votes
0answers
93 views

`multiple-value-call` in Scheme

Common Lisp has a "special operator" called multiple-value-call, which does something similar to Scheme's call-with-values but ...
2
votes
0answers
402 views

Coercion with multiple arguments

From SICP: Exercise 2.82 Show how to generalize apply-generic to handle coercion in the general case of multiple arguments. One strategy is to attempt to coerce all the arguments to ...
2
votes
0answers
1k views

Union-set intersection-set for a binary-tree implementation of sets

From SICP: Exercise 2.65 Use the results of exercises 2.63 and 2.64 to give (n) implementations of union-set and intersection-set for sets implemented as (balanced) binary trees.41 I ...
1
vote
0answers
69 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 ...
1
vote
0answers
402 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-...
1
vote
0answers
119 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 ...
1
vote
0answers
55 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 ...
1
vote
0answers
98 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 ...
1
vote
0answers
43 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, ...
1
vote
0answers
107 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
73 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
0answers
249 views

SICP ex. 2.42 “eight queens puzzle”

The problem can be found online here. In short, we're given the following function definition, that will recursively generate all the possible solutions for the "eight-queen-problem". ...
1
vote
0answers
97 views

Implementing buffered channels in Guile

I was looking for a way of doing simple message passing in Guile and found some references to the module (ice-9 occam-channel) which is a pretty nifty, but undocumented, module for occam-like channels....
1
vote
0answers
180 views

Write a definition of a semaphore in terms of test-and-set! operations

From SICP: Exercise 3.47. A semaphore (of size n) is a generalization of a mutex. Like a mutex, a semaphore supports acquire and release operations, but it is more general in that up to n ...
1
vote
0answers
201 views

Write a definition of a semaphore in terms of mutexes

From SICP: Exercise 3.47. A semaphore (of size n) is a generalization of a mutex. Like a mutex, a semaphore supports acquire and release operations, but it is more general in that up to n ...
1
vote
0answers
573 views

Correctly count the number of pairs in an irregular list structure

From SICP: For background, here is exercise 3.16: Exercise 3.16 Ben Bitdiddle decides to write a procedure to count the number of pairs in any list structure. ...
1
vote
0answers
165 views

Coercion of arguments using successive raising

From SICP: Exercise 2.84 Using the raise operation of exercise 2.83, modify the apply-generic procedure so that it coerces its arguments to have the same type by the method of ...