Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.
0
votes
0answers
33 views
Is my implementation of a merge sort correct?
I tried to get into programming several times but never did and never got very far past "Hello, World.", until recently when I found and read (most of, still don't get parts of it) "The Little ...
4
votes
1answer
73 views
Code from “Write Yourself a Scheme in 48 Hours” tutorial
I recently went through this Haskell tutorial.
I'd be interested in any thoughts or comments at all, in terms of improving the structure, order, haskell conventions, or that long, kind of ugly eval ...
3
votes
2answers
59 views
This snippet of scheme calculates a value in pascal's triangle
I'm working through SICP and have implemented exercise 1.11 (Pascal's Triangle). What I'm curious about here is performance considerations by defining functions within the main function. I would ...
3
votes
2answers
100 views
Rosalind's 3rd problem in Scheme
I have an imperative programming background and I've decided to study functional programming by applying it to problems found on sites such as Project Euler and Rosalind. My language of choice is ...
7
votes
2answers
354 views
My first accumulators
Notes
I'm working my way through SICP, and as I got very confused by the section on folds, I decided to try to implement foldr in scheme and javascript to understand how it works differently with ...
4
votes
4answers
102 views
Project Euler 1 (sum of multiples of 3 or 5 under 1000)
I solved this a while ago. In the moment I solved it I was learning Scheme and, well, I still am. I'm not looking at the best solution (I searched for it and coded it already, in Python), what I want ...
2
votes
0answers
18 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, ...
2
votes
1answer
55 views
lexical scope v let in scheme functions
I've been chewing through a bit of The Little Schemer and the Peano examples got me thinking about operation size and time.
I got some help on making Peano Multiplication linear -- however ...
1
vote
1answer
41 views
Linear Peano multiplication in Scheme?
I've been running through The Little Schemer, and have hit the example of Peano multiplication. The solution is given in TLS (reproduced below) -- however what interests me is the order of the ...
0
votes
1answer
130 views
remove first occurance 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 ...
1
vote
1answer
278 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 ...
3
votes
2answers
216 views
Why is this RC4 code in Racket so slow?
According to shootout.alioth.debian.org, Racket is not much slower than C#, at least in the same order of magnitude due to its JIT compiler.
However, I'm seeing at least two degrees of magnitude ...
0
votes
0answers
66 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
25 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 ...
1
vote
0answers
51 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 ...
0
votes
1answer
36 views
Check if element is a member of all sets in Scheme
Here is a function that checks whether an alement a is a member of every set in list l-set.
I don't like the fact that it ...
3
votes
0answers
95 views
Quick Insert Merge Sort
I have written a code for sorting a list of numbers in increasing order. It is a combination of quick sort, insertion sort and merge sort. I take the first element of the list as Pivot. Then I go ...
1
vote
0answers
38 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
...
0
votes
1answer
119 views
Numeric Value for a Date, dateAdd and dateDiff
In MS excel, a date is also represented as a numeric value, with 1-Jan-1900 as the first day. Also in VBA there are dateAdd and dateDiff functions. dateAdd adds a given unit (day, month quarter or a ...
3
votes
1answer
216 views
Scheme/Racket: idiomatic infix math evaluator
Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an ...
5
votes
1answer
258 views
Improving a priority queue sketch in Racket/Scheme
I just put together the skeletons for a priority queue using a binary heap in racket/scheme. Using racket/scheme is all about the educational experience and I was wondering if anyone wants to ...
3
votes
1answer
188 views
A Simple Unix Filter in Racket - Learning the Racket Way
I've written the following simple filter in Racket as my first Racket program and am wondering if I am writing it in an "idiomatic Racket style".
...
2
votes
2answers
400 views
Counting Ways to Make Change — Is this good functional/Lisp style?
I have just started learning some Scheme this weekend. I recently solved a problem that goes something like:
...
3
votes
1answer
246 views
Scheme, first timer first program, simple list removal technique
I have started my hand at writing some scheme code. I am trying to get the first n primes. I plan to do so but first getting a list from 2 to ...
3
votes
2answers
301 views
A little scheme programming challenge
I am learning scheme to get something new from a programming language and this code below is the solution to Project Euler question 21 but the code runs 10x slower than the listed Python code when I ...
1
vote
1answer
117 views
Optimize this Scheme-written chess engine module
I'd like to know how to optimize this by shadowing symbols 'lo and 'hi inside nested function f. I guess CPS conversion would solve this but how?
...
5
votes
0answers
566 views
2
votes
0answers
409 views
Insert-everywhere
This is HTDP Excercise 12.4.2 :- Page 161
Develop a function insert-everywhere. It consumes a symbol and a list
of words. The result is a list of words like its second argument, but
with the ...
1
vote
0answers
138 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
74 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 ...
5
votes
2answers
3k views
Sorting a list of numbers in increasing order
Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function).
...
2
votes
1answer
449 views
An in-nested sequence generator for racket scheme
I've been learning about racket sequences and noticed a hole where nested iteration is concerned. We have the in-parallel construct but no ...
3
votes
1answer
484 views
A list builder or list accumulator
Imagine a UTF-8 decoder that takes a list of bytes and
returns humman readable code points like:
...
7
votes
2answers
159 views
Write a procedure stream-limit that finds
From SICP:
Exercise 3.64. Write a procedure
stream-limit that takes as arguments a
stream and a number (the tolerance).
It should examine the stream until it
finds two successive elements ...
1
vote
0answers
143 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
146 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
...
0
votes
1answer
104 views
Function that multiplies all numbers between “a” and “b” with do loop
I'm making a function that multiplies all numbers between an "a" input and a "b" input with do loop. If you please, check my function and say what's wrong since I ...
3
votes
0answers
118 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
1answer
191 views
Examine a list for cycles
From SICP:
Exercise 3.18. Write a procedure that
examines a list and determines whether
it contains a cycle, that is, whether
a program that tried to find the end
of the list by taking ...
1
vote
0answers
268 views
[SICP ex. 3.17] 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
1answer
205 views
[SICP ex. 3.8] order of evaluation of function arguments
From SICP:
Exercise 3.8. When we defined the
evaluation model in section 1.1.3, we
said that the first step in evaluating
an expression is to evaluate its
subexpressions. But we never ...
1
vote
0answers
135 views
[SICP ex. 2.84] 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 successive
...
5
votes
1answer
430 views
Find the Hardy–Ramanujan number using R5RS scheme. Please suggest improvements in idiom and calculations.
I remember once going to see
[Srinivasa Ramanujan] when he was ill
at Putney. I had ridden in taxi cab
number 1729 and remarked that the
number seemed to me rather a dull one,
and that I ...
1
vote
0answers
293 views
(scheme [SICP ex. 2.82] 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 the
...
2
votes
1answer
551 views
Huffman encoding successive-merge function
From SICP:
Exercise 2.69. The following
procedure takes as its argument a list
of symbol-frequency pairs (where no
symbol appears in more than one pair)
and generates a Huffman encoding ...
1
vote
1answer
597 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.
...
2
votes
1answer
278 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 ...
2
votes
0answers
767 views
Union-set intersection-set for a binary-tree implementation of sets [SICP ex. 2.65]
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
1answer
279 views
Union-set for ordered representation
From SICP:
Exercise 2.62. Give a (n)
implementation of union-set for sets
represented as ordered lists.
I wrote this answer:
...
1
vote
1answer
169 views
(scheme) [SICP ex. 2.61] adjoin-set for an ordered set representation
From SICP:
Exercise 2.61. Give an implementation
of adjoin-set using the ordered
representation. By analogy with
element-of-set? show how to take
advantage of the ordering to produce a
...