-1

I'm trying to write mergesort in Racket (in R5RS).

I'm not sure how I'm getting so many syntax errors.


So, I've learned from the help of those who commented that I was actually writing in R and not R5RS. I'm new to learning either language so I would appreciate any help with how to write a mergesort method in R5RS. I removed most of the causes of the syntax errors such as

Illegal use of '['

but then it didn't do anything.


This is the code I had before fixing the program

(define (merge as bs)
        (match* (as bs)
        [((list) bs) bs]
        [(as (list)) as]
        [((list a as ...) (list b bs ...))
(if (< a b)
        (cons a (merge as (cons b bs)))
        (cons b (merge (cons a as) bs)))]))
(define (mergesort vs)
        (match vs
        [(list) vs]
        [(list a) vs]
[_ (define-values (lvs rvs)
        (split-at vs (quotient (length vs) 2)))
        (merge (mergesort lvs) (mergesort rvs))]))

This is after I fixed it but it still didn't work

(define (merge as bs)
        (match* (as bs)
        ((list) bs) bs
        (as (list)) as
        ((list a as ...) (list b bs ...))
(if (< a b)
        (cons a (merge as (cons b bs)))
        (cons b (merge (cons a as) bs)))))

(define (mergesort vs)
        (match vs
        (list) vs
        (list a) vs
(define-values (lvs rvs)
        (split-at vs (quotient (length vs) 2)))
        (merge (mergesort lvs) (mergesort rvs))))

EDIT: I appreciate the help with understanding the mistake I made here. I have formatted the code better so it is indented.

DjMaxLETU
  • 41
  • 1
  • 7

1 Answers1

1

If you're using Racket's R5RS language you need to write programs which are in that language: it won't work to write programs in some other language. In this case, match at least is not R5RS, and I strongly suspect split-at and define-values are not either.

What you're doing is a bit like pointing a FORTRAN 77 compiler at a Fortran 2018 program and expecting it to cope.

(Also: indent your code!)