Questions tagged [r5rs]

The 5th Revised Report on the Algorithmic Language Scheme

The 5th Revised Report on the Algorithmic Language Scheme, R5RS is a de facto standard for Scheme implementations. Schemers take pride in the fact that at 50 pages the specification is shorter than the index for books on some other languages.

225 questions
0
votes
2 answers

Assigning variables in Scheme without using set

I am trying to create a global score in my scheme program and it will either increase by 1, decrease by 1 or not change for each iteration of my function. For example, I have this in my function when I want the score to increase by 1: (set! score (+…
Sbean
  • 21
  • 2
0
votes
1 answer

Recursive Definitions

I'm currently learning about recursion in Scheme. I found this recursive definition but I don't understand what it is trying to do. If someone could explain it to me, I would appreciate it. Here is the definition: (define (function ls) (if…
SarahCaw
  • 11
  • 2
0
votes
2 answers

Why is my Reverse Function Reversing All my Pairs BESIDES One?

i.e. I am given this (all possible combinations to make change for 11): (list 1 1 1 1 1 1 1 5 5 5 5 1 1 1 10 10 10 1 1 25 25 25 25 25 25) My code should return: ((7 . 1) (4 . 5) (3 . 1) (3 . 10) (2 . 1) (6 . 25)) so it is more readable. However,…
0
votes
1 answer

Scheme:R5RS:: Make it ten-thousandth place value

(define m (expt 2 32)) (define a 22695477) (define c 1.0) (define (integers-starting-from n) (stream-cons n (integers-starting-from (+ n 1)))) (define (prng seed) (define xn (remainder (+ c (* a seed)) m)) (define prn (/ (remainder (+ c (*…
Honolulu
  • 23
  • 3
0
votes
2 answers

Replaces occurrences in a list - Racket

I am writing a function called ptyper that takes a nested list, nl. This function replaces all occurrences of a number with n and all occurrences of a symbol with s. This is what I have now: (define (ptyper nl) (cond ((null? nl) '()) ((list? nl) …
SarahCaw
  • 11
  • 2
0
votes
1 answer

Counting number of occurrences of elements in a list

I am writing a function called count-if, which takes in a predicate, p?, and a list, ls. The function returns the number of occurrences of elements in the nested list that satisfy p? For example: (count-if (lambda (x) (eq? 'z x)) '((f x) z (((z x c…
SarahCaw
  • 11
  • 2
0
votes
2 answers

Remove second occurrence of given item from list - Racket

I need to write a function called remove-2nd, which removes the second top-level occurrence of a given item from a list of items. This is what I have right now: (define (remove-2nd item list) (cond ((null? list) '()) ((equal? item (car list)) …
SarahCaw
  • 11
  • 2
0
votes
2 answers

Scheme and R5RS questions about eq

Can you explain why the first one is false and the second one is true? And how this works? Thanks. (eq? '(1 2 3) '(1 2 3)) ;False (eq? '() '()) ;True
Honolulu
  • 23
  • 3
0
votes
1 answer

SCHEME::R5RS Recursive using map

;; Write the code to fill in the missing part (???) of the below statement) ;;(map ??? (list 1 2 3 4 5 6 7 8 9 10)) => (2 4 6 16 10 36 14 64 18 100) ;; *2 ^2 *2 ^2 (define (mapp list item) (cond ((odd? (car item)) (* (car item) 2)) (cons…
Honolulu
  • 23
  • 3
0
votes
2 answers

Scheme::R5RS. Trying to make the absolute value procedure

I'm trying to make the absolute value procedure and code got an error. I don't know why :/ (define (abs x) (cond ((> x 0) x) ((= x 0) 0) ((< x 0) (- x)))) Error message: define-values: assignment disallowed; cannot change…
Honolulu
  • 23
  • 3
0
votes
1 answer

'error' procedure is undefined in plt-r5rs

I have this file named myprog.scm: (error "Not found!") Running the program using plt-r5rs myprog.scm gives an error: error: undefined; cannot reference undefined identifier context...: /usr/share/racket/pkgs/r5rs-lib/r5rs/run.rkt: [running…
Flux
  • 9,805
  • 5
  • 46
  • 92
0
votes
1 answer

R5RS - How to test procedures that use `read` operation

Is it possible to test procedures that use the read operation? ex. (define (foo prompt) (display prompt) (read)) I tried to use write but read seems to create a block so that the write is only run after I enter something manually
Alter
  • 3,332
  • 4
  • 31
  • 56
0
votes
3 answers

Applying operations on Scheme (R5RS) with a condition

I'm trying to create a Scheme program (Language R5RS) which applies an operation to a set of lists, depending on how big a number is on a list. So the function looks like (apply-function f g) The condition is, if f(a b) where a < 5, then apply…
dracogale
  • 13
  • 3
0
votes
1 answer

Calling list function with Dr Racket R5RS undefined error for '( 1 2 3) for the list

I have function setup as (define function (lambda (lst s1 s2 s3) ...... ))) when calling it - (function '(1 2 3) 0 0 0) - I am getting this error because of the ' ? What do I need to add into my code for it to understand the list " 1 2 3 " ? I have…
0
votes
0 answers

Adding user input, very simple

I need to use user input to run a program. I don't understand this program completely. How do I get an error of 4 inputs while I'm only asking for 2 inputs? ; Q4: Please enter test values 2 and 5. It should return 32. (5 …
Reddi nav
  • 19
  • 1
  • 6