Scheme is a functional language in the Lisp family.
2
votes
0answers
22 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 ...
0
votes
0answers
23 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
(display "Enter input ...
-2
votes
0answers
29 views
Scheme language questions [closed]
Please can anyone help me with this functions as fast as possible
They are in scheme language
Write the function extraire_ieme_cartes that retrieves the i-th card of a list of cards given as a ...
0
votes
0answers
15 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 ...
2
votes
1answer
35 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 ...
4
votes
1answer
80 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
109 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".
#! /usr/bin/env racket
#lang racket
(require ...
2
votes
1answer
125 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:
Count the number of ways possible to give out a certain amount of change using
1 5 10 25 ...
3
votes
1answer
140 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 m, and doing the following algorithm. Remove the first ...
3
votes
2answers
195 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
67 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?
;; chess engine - early development
;; Alist: (cons ...
2
votes
0answers
246 views
Merge sort in Scheme
(define (merge-sort lst (lt? <))
(let sort ((lst lst)
(size (length lst))
(flip #f))
(define (merge l r (res '()))
(cond ((null? l) (append-reverse r res))
...
0
votes
0answers
50 views
The Scheme Programming Language Ex 3.4.3
Rewrite the following expression in CPS (Continuation Passing Style) to avoid using call/cc.
(define reciprocals
(lambda (ls) (call/cc
(lambda (k)
(map (lambda (x)
(if (= ...
2
votes
0answers
95 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
116 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".
(define ...
1
vote
0answers
60 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 ...
3
votes
2answers
916 views
A newbie's Program to sort a list in scheme (DrRacket)
Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function).
(define (sort-list l)
(define first-element (if (not (null? l)) (car l) 0))
(cond ...
2
votes
1answer
267 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 in-nested construct. There's the for*/... family, but ...
3
votes
0answers
73 views
A weblog, implemented in Scheme
It has been said that Lisp - family languages, though not often used to implement web applications, are actually very well-suited to that task, and that all the libraries you need already exist. To ...
3
votes
1answer
376 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:
> (utf-8->human-readable-code-points '(32 32 195 160 160))
("u+0020" "u+0020" "u+00E0" ("Error: ...
1
vote
0answers
630 views
integrating SFML and Box2D lib, and a Mass Production Shape Factory
i just wrote two new headers: one that integrates Box2D and SFML by a class called BodyRep which creates/ is a graphic representation of any body, and one that produces huge amounts of uniform shapes, ...
5
votes
1answer
125 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
128 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
123 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
99 views
(Scheme) how to create a 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 don't know loops very well in Scheme.
...
2
votes
0answers
94 views
[SICP ex. 3.22] represent 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
...
3
votes
1answer
144 views
SICP ex. 3.18 - Write a program to 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
157 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.
It's easy,'' he reasons.The
...
1
vote
1answer
149 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
99 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
355 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
236 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
...
1
vote
1answer
363 views
Huffman encoding successive-merge function [SICP ex. 2.69]
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
328 views
(Encode-symbol …) for Huffman tree [SICP ex. 2.68]
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.
(define (encode message tree)
...
2
votes
1answer
202 views
Lookup (search) on a binary tree [SICP ex. 2.66]
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
622 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
220 views
(scheme) [SICP ex. 2.62] 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:
(define (union-set set1 set2)
(cond ((null? set1) set2)
...
1
vote
1answer
132 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
...
2
votes
1answer
138 views
(scheme) [SICP ex. 2.60] Set representation allowing duplicates
From SICP:
Exercise 2.60. We specified that a
set would be represented as a list
with no duplicates. Now suppose we
allow duplicates. For instance, the
set {1,2,3} could be represented as
...
1
vote
1answer
328 views
(Scheme) [SICP ex. 2.59] union-set
One way to represent a set is as a
list of its elements in which no
element appears more than once. The
empty set is represented by the empty
list. In this representation,
element-of-set? ...
1
vote
0answers
216 views
Standard Algebraic Derivative Calculator [SICP ex. 2.58 part b]
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 ...
3
votes
0answers
281 views
On Implementing a Lisp
Background:
This began with James Colgan's Lisp-Dojo for Ruby. My implementation can be found here. I then moved on to Write yourself a scheme in 48 hours. This question has to do with one of the ...
1
vote
1answer
147 views
(Scheme) [SICP ex. 2.57] Extend sums and products functions without changing deriv function
Exercise 2.57. Extend the
differentiation program to handle sums
and products of arbitrary numbers of
(two or more) terms. Then the last
example above could be expressed as
(deriv '(* ...
0
votes
1answer
78 views
(Scheme) [SICP ex. 2.56] Extend Differentiator
Exercise 2.56. Show how to extend the
basic differentiator to handle more
kinds of expressions. For instance,
implement the differentiation rule
by adding a new clause to the deriv
...
0
votes
1answer
284 views
(Scheme) [SICP ex. 2.54] Define equal?
Exercise 2.54. Two lists are said to
be equal? if they contain equal
elements arranged in the same order.
For example,
(equal? '(this is a list) '(this is a list))
is true, but
...
1
vote
2answers
101 views
(scheme) [SICP ex. 2.46] add-vect, sub-vect, scale-vect
Exercise 2.46. A two-dimensional
vector v running from the origin to a
point can be represented as a pair
consisting of an x-coordinate and a
y-coordinate. Implement a data
abstraction ...
1
vote
1answer
110 views
(Scheme ) [SICP ex. 2.45] Write a general purpose “split” function {for SICP's imaginary language}
From SICP 2.2.4:
The textbook has already defined a function (right-split ...) as follows:
(define (right-split painter n)
(if (= n 0)
painter
(let ((smaller (right-split painter (- n ...
3
votes
4answers
422 views
(Scheme) [SICP ex. 2.42] eight-queens puzzle - help me fix my popsicle-stick-bridge solution!
Figure 2.8: A solution to the
eight-queens puzzle. The
``eight-queens puzzle'' asks how to
place eight queens on a chessboard so
that no queen is in check from any
other (i.e., no two ...
5
votes
4answers
638 views
(Scheme) [SICP ex. 2.41] Find all distinct triples less than N that sum to S
Exercise 2.41. Write a procedure to
find all ordered triples of distinct
positive integers i, j, and k less
than or equal to a given integer n
that sum to a given integer s.
(define ...
0
votes
1answer
110 views
(Scheme) [SICP ex. 2.40] unique-pairs
From the section called Nested Mappings
Exercise 2.40. Define a procedure
unique-pairs that, given an integer n,
generates the sequence of pairs (i,j)
with 1< j< i< n. Use ...