i have a serious problem porting code from Racket that use immutable list to r6rs at some point i got this error i do not understand and do not know how to solve:
<- : #'parsed-args=.#<syntax:git/Scheme-PLUS-for-Racket-R6RS/assignment.sls:228:31 (list index)>
. . ../assignment.sls:236:27: mcdr: contract violation
expected: mpair?
given: #<syntax:/home/mattei/git/Scheme-PLUS-for-Racket-R6RS/assignment.sls:228:31 (list index)>
Interactions disabled: r6rs does not support a REPL (no #%top-interaction)
the error occurs in this part of code (the lines number are added in comments):
The problem you are seeing is not actually because of mutable vs. immutable pairs. You are calling (cdr #'parsed-args), but #'parsed-args is a syntax object, not a pair (neither mutable pair nor an immutable pair).
I'm not entirely clear on what you want to do, but you may want to use let instead of with-syntax, to use syntax-case instead of dispatching on (length (cdr ❓)), and/or use syntax->datum somewhere.
For R6RS, libraries §12.2 says, “Wrapped syntax objects that are not identifiers may or may not be distinct from other types of values.” In Racket, wrapped syntax objects are distinct, and syntax objects tend to be wrapped.
It's unfortunate that the error is reported using the Racket name mcdr instead of the R6RS name cdr. The “realm” mechanism developed for Rhombus might enable improving the situation, if someone wanted to take that on.
yes i do not understand why Racket complains about mcdr , i even removed the (cdr ... code and it still complain about that.
I supposed the problem comes when merging / using in the same code R6RS and Racket (GUI, stream-list, etc...) code that use immutable list
i tried to use :
(compatibility mlist)
with no success
this is really a problem, i understand you propose to refactor the code but
this code takes me many weeks to set it up in Kawa and Guile and it used to work this way. I always tried when debugging in Kawa,Guile... 'let' and other ways.
What i will do is made a Racket version to see if the problem is always here, if not i will drop R6RS support.
But i'm not sure it is a problem with my library because a simple code that do not use my library have problem running:
i have to play with mutable and immutable list at many point of the code, and as r6rs report wrongly the problem:
. . ../assignment.sls:239:27: mcdr: contract violation
expected: mpair?
given: #<syntax:/home/mattei/git/Scheme-PLUS-for-Racket-R6RS/assignment.sls:231:31 (list index)>
Interactions disabled: r6rs does not support a REPL (no #%top-interaction)
it should not say, mcdr but cdr, this bugs should be corrected in racket/r6rs but i'm not sure there is a lot of support for r6rs , if i remember the R6RS language was proposed in Racket gui "choose language" many years ago but no more now...
ok here is what's look like the code now :
(define im*data* (mlist->list *data*))
(for-racket ([datum im*data*]) ; 'for-racket' is the original 'for' of Racket but renamed
(display "index=") (display index) (newline)
{imdatum <- (mlist->list datum)}
(match-let ((`(,p ,q ,d ,x ,y ,n) imdatum))
{imlst-points <- (stream->list
(stream-take
(chaos p q d x y) n))}
(display "after imlst-points") (newline)
(display (mlist? imlst-points)) (newline)
{lst-points <- (list->mlist imlst-points)}
(define max-norm-x-y (max-list-norm-x-y lst-points)) ; maximum
(display "after max-norm-x-y") (newline)
(when graphic-mode ; no memory overloading in this mode
;; Make a frame by instantiating the frame% class
{frm[index] ← (new frame% [label (format "Chaos+ ~a" index)]
[width xws]
[height yws])})
here we are at the heart of hard problem , i rewrote the library that define <- for R6RS , so why does it complains not having those mutable list in (list index) , as you say it is syntax , not list, but why it is syntax for Racket and not R6RS..... ok ok ok.... "fichu probleme" (damn problem) as we say in France...
i simplified the code took example on other part of code ( bracket-apply for [ ] , $nfx$ for infix) and noticed a variant of code more simple used many times with success:
the important point is the simple (cons #'list (parse-square-brackets-arguments-lister-syntax #'(index ...))) instead of the complex #`(list #,@(parse-square-brackets-arguments-lister-syntax #'(index ...)))
i noticed it in the version of Kawa and Guile too:
i faced the problem with Guile and Kawa too , but it worked , i suppose should modify those code too
it is ok on some file, not on others...
i extracted the different case in another procedure as in other files: