Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative-order) evaluation.
2
votes
1answer
26 views
2
votes
0answers
34 views
Seeking 5 primes such that concatenating any two of them produces another prime
I have a program which solves Project Euler problem 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 ...
2
votes
0answers
21 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 ...
1
vote
1answer
76 views
Is there something wrong with my remove-duplicates implementation in Scheme?
For an assignment I handed in this code to remove duplicates from a stream.
...
2
votes
3answers
254 views
Splitting a list in Racket
I am working my way into learning a bit of Scheme (actually, Racket) with the help of a few practical problems to solve. In this case, I want to split a flat list of symbols at a certain delimiter ...
6
votes
1answer
56 views
Fisher-Yates shuffle in Scheme
There are many ways to shuffle lists; for example, Racket's built-in shuffle assigns each list element with a random number as a sort key, then sorts the list, ...
3
votes
3answers
81 views
Sum of squares of 2 largest numbers out of a list of 3 numbers
The problem is:
Define a procedure that takes 3 number arguments and returns the sum of the squares of the 2 largest numbers.
I am a CS graduate and I am revising my university notes. This is my ...
3
votes
1answer
34 views
Digit Summing Function
I'm working through the common divisibility tests, and implementing them in Racket. I'm working on divisible by three, for which I thought it'd be nice to keep summing until I got to a single digit ...
3
votes
0answers
105 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 ...
9
votes
1answer
210 views
WebSocket-based API library in Racket
I've developed a library in (typed) Racket that wraps a WebSocket-based API. The API itself is very simple—it operates via a series of three-letter commands optionally followed by a JSON-encoded ...
3
votes
2answers
105 views
split-string for R7RS
A split-string function seems to be missing in R7RS.
I came up with the following implementation today:
...
4
votes
1answer
94 views
Sieve of Eratosthenes in Scheme (R7RS)
I've seen many implementations of Sieve of Eratosthenes in Scheme, but I thought I'd try to write one that is both space- and time-efficient:
Space-efficient: I use R7RS bytevectors as a bitset, ...
1
vote
1answer
57 views
Extracting values from a list
I had already solved this problem, but in an unnecessarily convoluted way that seems too specific. Can this be done better?
From a list:
(8 "layer-name" 10 x1 20 y1 10 x2 20 y2 10 x3 20 y3)
8, ...
6
votes
1answer
73 views
Simon Says in Scheme
Ok, it's not completely like Simon Says, since it's text-based. There is nothing about memorizing based on visual cues and/or sound here, just memorizing long sequences of numbers. I wanted to do it ...
5
votes
1answer
108 views
Simple evaluator of Scheme-like expressions in Haskell
This is my first nontrivial Haskell program:
...
2
votes
0answers
80 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
121 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 ...
1
vote
1answer
130 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:
...
16
votes
1answer
242 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
351 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
132 views
Converting English Measurements to Metric and vice versa
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 ...
4
votes
1answer
438 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
95 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
262 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
383 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 ...
6
votes
4answers
299 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
24 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
72 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
56 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 ...
1
vote
1answer
472 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
2k 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 ...
4
votes
2answers
298 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
92 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
32 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
70 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 ...
1
vote
1answer
48 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
152 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
53 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
239 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
430 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 ...
6
votes
1answer
419 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
243 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
642 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
345 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
554 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
166 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?
...
8
votes
0answers
778 views
5
votes
2answers
644 views
Insert-everywhere function
This is HtDP Excercise 12.4.2:
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 first ...
1
vote
0answers
148 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
83 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 ...