'What is the difference between of code written in DrRacket in "R5RS" vs "#lang racket"?

Is there a difference between in syntax of coding or code will same in both language types?

I wrote a program in #lang racket language but I was supposed to do it in the "R5RS" type.



Solution 1:[1]

The short answer is that it depends on the program.

#lang racket and #lang r5rs share the same basic syntax but smaller things may change between the two, e.g. [ can be used in place of ( in racket but not in r5rs.

There may be other differences between the semantics or racket and r5rs scheme. This means that the same program may behave differently when running as a racket program or as a r5rs scheme program.

This is usually not the case because both racket and r5rs scheme share a lot of semantic but two different implementations of r5rs scheme are allowed to have different semantics in some special and agreed upon cases.

Solution 2:[2]

The most visible difference is in the Dr. Racket REPL. The canonical list in Racket is immutable, while the canonical list in R5RS is mutable. And the REPL treats immutable and mutable lists differently.

In #lang racket, the Dr. Racket REPL responds this way (with an immutable list):

> '(a b)
'(a b)

In #lang r5rs, the Dr. Racket REPL responds this way (because mutable lists are displayed by the REPL this way):

> '(a b)
(mcons 'a (mcons 'b '()))

I believe that is the reason for its different REPL behavior from more typical Schemes. Typical Scheme REPLs respond this way (without the quote in the response):

> '(a b)
(a b)

Interestingly, with #lang r5rs, display and write behave in Dr. Racket in the expected manner:

> (define x '(a b))
> x
(mcons 'a (mcons 'b '()))
> (display '(a b))
(a b)
> (display x)
(a b)
> (write '(a b))
(a b)
> (write x)
(a b)
> x
(mcons 'a (mcons 'b '()))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 edoput
Solution 2 hs takeuchi