I've written some code but it's not working because the add1
function I used in Scheme is not working with R5RS. What can replace add1
in R5RS?
Asked
Active
Viewed 2,187 times
2

C. K. Young
- 219,335
- 46
- 382
- 435

Sahil Gadimbayli
- 21
- 3
-
R5RS **is** Scheme. The S is for Scheme. Do you mean the add1 from Racket? – Joshua Taylor Jun 19 '15 at 02:56
2 Answers
6
The procedure add1
is very simple, you can implement it yourself:
(define (add1 x)
(+ x 1))

Óscar López
- 232,561
- 37
- 312
- 386
0
late answer but an alternative is (making use of lambdas)..
(define add1
(lambda (x)
(+ x 1)))

iKlsR
- 2,642
- 6
- 27
- 45
-
I cannot imagine any Scheme implementation where the two forms would be treated differently at all, assuming we are talking about the implementation's default implementation of `define`. Thus, your answer is exactly equivalent to Óscar's answer, so it's not an alternative per se. – C. K. Young Jun 19 '15 at 04:10
-
@ChrisJester-Young I meant alternate way of writing. Arguably useless but who doesn't want to show off their newfound Scheme skills. – iKlsR Jun 19 '15 at 04:20
-
1Here's a showoff answer for you (it macro-expands to exactly the same thing, but looks cooler; requires [SRFI 26](http://srfi.schemers.org/srfi-26/srfi-26.html)): `(define add1 (cut + <> 1))` :-D – C. K. Young Jun 19 '15 at 04:22