简体   繁体   中英

Which identifier am I supposed to use to close my library in R7RS/Scheme?

I'm trying to write a R7RS library which will reverse a list in a destructive manner,

I currently have written this code;

#lang r7rs


(define-library (in-place-reverse!)
  (export reverse!)
  (import (scheme base))

(ignore the code below)
;    (define (reverse! list)
;      (if (null? list)
;          '()
;          (append (reverse (cdr list))
;                  (list (car list)))))))
(begin
  
    (define (reverse! lst)
      (define (reverse-hulp! prev cur)
        (cond
          ((null? cur) prev)
          ((next) cdr cur)
          ((set-cdr! cur prev))
          (else
            (reverse-hulp! cur next))))))
              
      (reverse! '() lst))

The only thing I'm worried about is the error i'm receiving.

 define-library: expected one of these identifiers: `import', `export', `begin', `cond-expand', or `include'
  parsing context: 
   while parsing library clause in: reverse!

Is my code even working as i'm asking it to? any kind of advice is appreciated!

Tried to implement a reverse procedure as I would in R5RS only this time i'm using destructive operators.

Your error message doesn't match your code. When I run your example I get the error:

define-library: expected one of these identifiers: `import', `export', `begin', `cond-expand', or `include'
  parsing context: 
   while parsing library clause in: ignore

If I comment out the ignore form, I get your error and the expression (reverse! '() lst) is highlighted.

The problem is that the expression is outside the begin . Also, the intention was probably to make start the process in reverse! .

#lang r7rs


(define-library (in-place-reverse!)
  (export reverse!)
  (import (scheme base))

  (begin
  
    (define (reverse! lst)
      (define (reverse-hulp! prev cur)
        (cond
          ((null? cur) prev)
          ((next) cdr cur)
          ((set-cdr! cur prev))
          (else
           (reverse-hulp! cur next))))
      (reverse! '() lst))))

Then you need to figure out what to do about next .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM