Questions tagged [scheme]
Scheme is a functional programming language in the Lisp family, closely modeled on lambda calculus with eager (applicative order) evaluation. FOR questions about URL schemes PLEASE use the tag "URL-scheme".
8,125
questions
0
votes
1
answer
41
views
How to print the value being returned before it's returned in Scheme?
I'm trying to modify this snippet from SICP:
(define (whatever x y)
(newline)
(display "called with ")
(display x)
(if (> x y)
0 ; if x <= y, return 0 ...
0
votes
2
answers
92
views
Finding an element in B+ tree using Scheme
I need to traverse the B+ tree. If i hit a list i need to deal with it and recursively keep going till i get an element. Then i compare it to the number given. If the number is more than the greatest ...
2
votes
1
answer
71
views
Encode "ä", "ö", "ü" and "ß" in scheme (get german text from file)
I'm new to scheme and try to build a simple application in scheme. I want to use simple text files as a database, so the program basically load text from a file, do something with it and save the ...
1
vote
3
answers
128
views
Need assistance with a scheme(R5RS) coding project (I feel like I'm missing something simple)
Essentially the point of the project is to define a single function sum. Sum takes in a list of integers and decides whether there are any 2 integers in the list that when added together equal any ...
2
votes
1
answer
50
views
Combination of list-ref and index-of in racket
(define code
'(
function f1 < a b >
vars x y
begin
"..."
end
)
)
(define ,(cadr code) '()) ;first method
(define ,(list-ref code (+ (index-of code '...
0
votes
0
answers
61
views
Gimp Scheme Script. How can I keep the same file name when exporting the images from Gimp
I want to keep the same file names when the script is exporting each file. Tried many things but nothing worked. When it is exporting the end file name is image00001. I want it to be the same as it is ...
1
vote
1
answer
52
views
How could I switch this program to give the option to play again or press q to quit
This is a very simple program, im just new to scheme and programming in general. I want to switch this to give the option to play again or press q to quit. The program is working normally now just ...
0
votes
1
answer
35
views
How do I seed the random integer function on Scheme's srfi 27 library?
I am writing a program on Scheme that uses the random integer library from srfi 27. However, every time I run the program on my laptop or a friend's the function returns the same value. Looking at ...
0
votes
1
answer
35
views
How to fix "read-line: undefined; cannot reference an identifier before its definition" in scheme
Im writing a Scheme guessing game and I am getting the error given in the title. There are probably more errors through out the program. Any help is appreciated. I will have the whole entire program ...
0
votes
2
answers
42
views
How is set-car! modifying my closure environment?
I am coding a meta-circular interpreter and am trying to implement closures. I have a function make-lambda which makes the closure:
(define (make-lambda parameters body env)
(list 'lambda parameters ...
0
votes
0
answers
46
views
Eval and Apply in SICP [duplicate]
What is so special about the SICP eval-apply loop? What is so enlightening about it?
I understand the process of evaluation, but do not understand what is so universal in it. Programmers also say that ...
1
vote
1
answer
88
views
Chez Scheme FFI Procedure Doesn't Work After Change to Apple Silicon
I have been using a simple piece of FFI code in Chez Scheme
to obtain the number of rows and columns of the terminal emulator where a program is running. The procedure used to work when running with ...
-1
votes
1
answer
42
views
Dr Racket Recursing Without Returning Inital Parent Node Within Function
So I have the function ancestors-names which takes an argument pers from a structure list and attempts to return all of the names of family members occurring within that structure. The intitial ...
0
votes
1
answer
51
views
Racket : Run scheme file in terminal and show result
I need to run a basic Scheme script and get his output.
Let's take this example :
test.scm
(define square ( lambda (x) (* x x)))
(square 3)
And when I run racket -f test.scm, I didn't get the ...
0
votes
0
answers
67
views
i need to write a code for the golomb sequence but i only get the answer and not the whole sequence
I need to code the golomb rank, this is my code:
(define ( golomb n)
(if (= n 1)
n
(+ 1 (golomb (- n (golomb (golomb (- n 1))))))))
(define (golomb-reeks n)
(cond ((= 1 n)...
1
vote
0
answers
67
views
In Scheme, is there a built-in function called "ref"?
In Scheme, is there a built-in function called "ref"? I am reading "The Little Learner" and came across the following code:
(define line
(lambda (x)
(lambda (θ)
(+ (* (...
2
votes
1
answer
88
views
How do we convert this Scheme (Lisp) function into C#
In "Structure and Interpretation of Computer Languages" the authors show you how you can form pairs of integers in Lisp using cons (concatenate two values), extract the first using car, and ...
3
votes
2
answers
91
views
Under any Scheme standard, is (let (x y z) x) valid code?
In both Emacs Lisp and Common Lisp, the following returns nil
(let (x y z)
x)
yet in every Scheme that I've tried, it throws an error.
Has the above been acceptable under any Scheme standard?
1
vote
0
answers
47
views
How to change the color of a button% in Racket
I'm new to racket and I'm trying to change the color of a button in the gui library. But no matter what I do I always get an error, can someone explain to me how to change the color of a button?
I ...
0
votes
1
answer
44
views
In 'The Scheme Programming Language' what is this strange 'let' form in '(reverse)'? [duplicate]
From The Scheme Programming Language, written by R. Kent Dybvig, I see this definition of reverse:
procedure: (reverse list)
returns: a new list containing the elements of list in reverse order
...
2
votes
5
answers
168
views
What do Lisp macros have over functions that optionally evaluate their arguments?
Context
I've been learning some Lisp (Scheme, primarily) over the past few days, drawn by the allure of the sheer power said to be afforded by these languages. Of course, macros are the thing that are ...
1
vote
1
answer
54
views
Is an iterative process that returns a list with size that increases by iteration any different from an one that returns a scalar?
This actually comes from me initially misreading the text of Exercise 1.12.
The request is indeed to
Write a procedure that computes elements of Pascal's triangle by means of a recursive process.
I ...
0
votes
1
answer
162
views
Implement add-leaf, a Scheme procedure that takes in a tree instance t and a number x
Implement add-leaf, a Scheme procedure that takes in a tree instance t and a number x.
This procedure will return a new tree where for each non-leaf node in the tree, append a new leaf with the label ...
0
votes
0
answers
52
views
Sheme r1rs bytecode
I have simple tree-walking interpreter for scheme r1rs. I use Rust for it. Lisp interpreter is s-expressions interpreter, that's why i have these AST nodes:
enum SExpression<'a> {
Nil,
...
1
vote
2
answers
43
views
Chicken Scheme pass on parameters to gcc
In Chicken Scheme, can I pass on certain values that will be given to gcc?
I would like to pass on the following options to the gcc but I don't know how:
-lX11 -lpthread -lXinerama -lXext -lGL -g -lm -...
0
votes
0
answers
38
views
drawing lines in a Lilypond score algorithmically
In reference to this post I would like to write a scheme function in Lilypond which would help me not to manually define the position of each point of the lines.
Here a simplified example of the ...
1
vote
3
answers
71
views
Say we have an abstract data type for cities. A city has a name, a latitude coordinate, and a longitude coordinate
Our data abstraction has one constructor:
(make-city name lat lon)
Creates a city object with the given name, latitude, and longitude.
We also have the following selectors in order to get the ...
0
votes
1
answer
38
views
Why doesn't this Scheme s-expression work when the sub expressions work?
> (equal? '(1 4) (car '('(1 4))))
#f
Whoops, the above should evaluate to #t because the pieces result in #t
As follows:
> (car '('(1 4)))
'(1 4) ; Scheme doesn't get confused by list of a ...
1
vote
1
answer
81
views
How to implement extremely high floating point precision in Scheme?
It is well known that Scheme can produce extremely large whole numbers without any further effort.
But how do I implement extremely high floating point precision, please? Thank you.
(by "...
0
votes
2
answers
65
views
Implement a procedure remove that takes in a list and returns a new list with all instances of item removed from lst
(define (filter-lst fn lst)
'YOUR-CODE-HERE
(if (null? lst)
lst
(if (fn (car lst))
(cons (car lst)
(filter-lst fn (cdr lst))
)
...
1
vote
2
answers
86
views
Why normal-order and applicative-order evaluation are not giving the same value?
I am reading this book Structure and Interpretation of Computer Programs, 2nd edition and on page 21 under the subsection "Applicative order versus normal order" it is written that -
It can ...
3
votes
1
answer
82
views
Lisp / Scheme : Evaluating nested empty list/cons : (())
I'm using this Lisp compiler for testing
There is one things that I don't get it :
If an empty list () evaluate to itself :
(format t "~:a" ())
;; => ()
why do evaluating several nested ...
0
votes
1
answer
91
views
Optimizing a CSV Parser in Scheme
I'm currently trying to learn Scheme(specifically chicken Scheme) and want to get a better idea of the performance pitfalls of the language. I've written a CSV parser and have shared it bellow. The ...
2
votes
2
answers
113
views
Scheme: local macro (let-syntax) inside global macro (define-syntax)
I'm trying to write a set of Scheme macros to simplify building simple graph structures using a declarative style, but as a beginning Schemer I'm struggling with macro hygiene.
I have defined two ...
1
vote
1
answer
70
views
Where does Scheme store its types?
The following throws an error:
Chez Scheme Version 9.5.8
Copyright 1984-2022 Cisco Systems, Inc.
> (define-record-type point (fields x y))
> point
Exception: invalid syntax point
I have ...
1
vote
1
answer
35
views
What's the relevance of make-register accepting an argument (the name of the register) at all?
In §5.2.1, the following function is presented for creating a register
(define (make-register name)
(let ((contents '*unassigned*))
(define (dispatch message)
(cond ((eq? message 'get) ...
0
votes
0
answers
48
views
cddr: contract violation expected: (cons/c any/c pair?) given: '((4))
#lang racket
(define (validar-automata automata cadena)
(define estados (car automata))
(define alfabeto (cadr automata))
(define transiciones (caddr automata))
(define estado-inicial (cadddr ...
1
vote
0
answers
36
views
Append a value to the front of a list in lisp [duplicate]
Tryin to write a single lisp/scheme expression to insert the new value 'z into the beginning of the list '(a b) to produce '(z a b).
I have tried all sorts of combinations of push, append, define and ...
0
votes
0
answers
31
views
Chezscheme says "Exception: attempt to apply non-procedure #<void>" when I tried to print a pascal triangle [duplicate]
I'm new to scheme and I'm learning sicp.
I'm working on exercise 1.12 and tried to print a pascal triangle with the code below.
Cause I don't know much about scheme IO, I only used display procedure.
(...
0
votes
1
answer
57
views
What's wrong with this Chez Scheme FFI call to user32.dll SendInput?
I've never had any trouble with Chez Scheme FFI before, it's extremely forgiving with whatever you throw at it, but I can't seem to get this function not to throw errors.
The goal is to simply ...
0
votes
2
answers
148
views
What is (Y Y), the Y-combinator applied to itself?
In Chapter 9 of The Little Schemer, the authors introduce the Y-combinator and the penultimate question asks: "What is (Y Y)". They answer: "Who knows, but it works very hard."
I ...
1
vote
0
answers
114
views
the lambda evaluation in the python implementation of scheme interpreter problem from CS61a
I am now following Berkeley 61a (version 2023) to learn computer science. I got stuck with the problem 9 of the scheme project, and I couldn't figure out where I got wrong. And this is the first time ...
0
votes
1
answer
89
views
Function definition and function call input seem coherent, but there's an error about the input when the application runs. What's wrong?
A novice in programming here (also first time posting here), trying to solve ex.91 from the htdp book (in racket - beginner student language). There's trouble with a helper function, which I named '...
0
votes
1
answer
97
views
How to return either a multiplied value in a list or boolean in Scheme (R5RS)?
So I encountered a problem where I have a list of numbers that I need to multiply out and return that value. However, if the list does not contain numbers or is an empty list, return false. Please ...
0
votes
3
answers
61
views
Is it possible to use 'append' or 'cons' to create a make-list function in Scheme that repeats values based on a given size parameter?
Is there an alternative way of writing the make-list function in Scheme (R5RS)? I am trying to create a function where the value repeats itself in the list based on the given size.
So my expected ...
0
votes
0
answers
60
views
scheme error: Error: argument 1 of map has wrong type (NoneType)
I am taking cs61a course, and I typed exactly like the one the professor typed on the screen(link: https://www.youtube.com/watch?v=0GcZKmdzPWU&list=PL6BsET-8jgYXHupEH2vUfhlvwbJddZdJM&index=4) ,...
0
votes
2
answers
58
views
Scheme lambda or define?
What's the difference between the two lines?
I want to make an adder function.
It turned out the first line works but the second not.
I'm new to scheme, thanks.
(define (make-adder num) (lambda (x) (+ ...
1
vote
1
answer
106
views
Extracting data of pairs without the data that encountered before
I have a data which inside of some pairs. But some pairs go a pair that encountered before. I don't want to extract same data again. For example I have a data like this.
So, as you see p3's first item ...
0
votes
2
answers
122
views
How is delay implemented?
I have a firm understanding of how lazy evaluation and streams work.
However I'm having some trouble simply following the book at this point. I don't really undrestand what it is trying to tell me ...
1
vote
2
answers
50
views
Are there any dialects of scheme that support multiple integer sizes?
I wish to write a program in Scheme that models the hardware registers of a hypothetical CPU. To this end, I'm going to need signed and unsigned integral datatypes that respect their intended bit ...