Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.
4
votes
1answer
33 views
Simple evaluator of Scheme-like expressions in Haskell
This is my first nontrivial Haskell program:
...
2
votes
0answers
11 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
1answer
36 views
Finding the subsets of a set
I am trying to write a procedure that finds the power set of a list, that is, the set of 2n subsets (where n is the number of elements in the list). I simply quite find all the subsets. I feel my code ...
0
votes
1answer
62 views
Reading/writing null-terminated strings from socket
I need to handle C style ('\0' delimited) strings from/to a socket and came up with this as a first attempt:
...
13
votes
1answer
143 views
Is this IRC bot utility library Racket-y enough?
To help myself learn Racket, I ported a simple JavaScript ircbot module I wrote for Node.js to Racket. The Racket version is built atop the Racket irc package, so ...
2
votes
1answer
163 views
Solving the N-queens puzzle the Racket or Scheme way
My final version is a direct translation from Python. Thanks to build-in support for generator, its speed is almost the same as Python. As I quite like using generator and list comprehension in ...
4
votes
2answers
53 views
Is there a better way to document this or is this good enough?
I finished answering Exercise 3.3.1 of How to Design Programs where:
Exercise 3.3.1. The United States uses the English system of
(length) measurements. The rest of the world uses the metric ...
0
votes
0answers
47 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
144 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
74 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
156 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
365 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
172 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 ...
1
vote
0answers
20 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
60 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
46 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
221 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
666 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
242 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 ...
1
vote
0answers
75 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
26 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
56 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
39 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 ...
4
votes
0answers
106 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 ...
1
vote
0answers
40 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
170 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
287 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
315 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
206 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
465 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
281 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
349 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
130 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
633 views
2
votes
0answers
496 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
140 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
75 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
500 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
525 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
161 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
146 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
148 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
105 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
120 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
198 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
296 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
1answer
228 views
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
145 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 ...
5
votes
1answer
436 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 ...