Pairs, vectors, and strings are mutable. Hence, the identity (or location) of such objects matter. Procedures are immutable, so they can be copied or coalesced arbitrarily with no apparent difference in behaviour. In practice, that means that some optimising compilers can inline them, effectively making them "multiple copies". R6RS, in...

math,numbers,scheme,r5rs,exact-match

Yes. To get the numerator and denominator of a rational number you have two procedures you can use: (numerator (/ 6 4)) ⇒ 3 (denominator (/ 6 4)) ⇒ 2 As it demonstrates the values returned are the lowest terms. The report specifies the denominator is always positive and the...

There is no promise? in R5RS. The construct delay produces a value representing a promise, but it is up the implementor to decide how to represent promises. Some implementations have chosen to represent them as closures. The R5RS implementation in Racket has chosen to use a struct with the name...

Just do a substitution: (p-car (p-cons "foo" "bar")) ;substituting p-cons: (p-car (lambda (proc) (proc "foo" "bar"))) ;substituting p-car: ((lambda (proc) (proc "foo" "bar")) (lambda (p q) p)) ((lambda (p q) p) "foo" "bar") "foo" And similarly for p-cdr. Essentially p-cons just creates a lambda which expects a procedure which will...

That's because append is not a mutating function. It returns a new list with its arguments appended together. By convention in Scheme, functions that perform mutation end with an exclamation mark, such as set!. You can use set! to modify new-list so that it is updated, like this: (set! new-list...

You need to learn what a list is ang get quite intimate with it to be a good lisper. The list (1 2 3) is just visual sugar for the pairs (1 . (2 . (3 . ()))) and can be made with (cons 1 (cons 2 (cons 3 '())))...

First of all, why not use #lang racket instead of r5rs? Racket is very much built with education in mind. It even has various teaching languages for use with the How to Design Programs textbook (or its second edition, which is still being worked on). Racket's implementation of R5RS is...

It's a little trickier than it seems at first sight, but this should work: (define (last lst key) (cond ((null? lst) '()) ((member key (cdr lst)) (cons (car lst) (last (cdr lst) key))) (else '()))) The key insight is that you should use member to check if the element is...

No. This SFRI specifically requests that a filter function be added because it is not present in R5RS. There is however a filter function defined in MIT-Scheme, and in R6RS, behaving exactly as one would expect.

The problem was the call (or the missing call rather) to search-list on the last line. Since this was not wrapped in parentheses, the procedure was never recursively called, and the procedure returned (cdr list) instead of (search-list key (cdr list)). This code works as intended: (define alist '((a ....

I wrote an implementation today. Alas, R5RS has neither bytevectors nor binary I/O, so this uses the R7RS APIs for bytevectors and binary I/O. It should be easy to bridge those APIs to your Scheme implementation's native APIs (for example, I actually tested my implementation on Racket and Guile). A...

loops,recursion,lambda,scheme,r5rs

To see what happens when ((lambda (x) (x x)) (lambda (x) (x x)) is evaluated use the stepper in DrRacket. It can show you the steps an evaluation takes. Write your expression in the definition window of DrRacket. Then choose the teaching language "Intermediate Student with lambda". Then click the...