chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-janitors] #1309: CHICKEN allows misplaced internal defines,


From: Chicken Trac
Subject: Re: [Chicken-janitors] #1309: CHICKEN allows misplaced internal defines, which live on outside the body
Date: Thu, 24 Nov 2016 19:58:12 -0000

#1309: CHICKEN allows misplaced internal defines, which live on outside the body
---------------------------------------+--------------------------------
            Reporter:  ai-artisan      |      Owner:
                Type:  defect          |     Status:  new
            Priority:  critical        |  Milestone:  5.0
           Component:  core libraries  |    Version:  4.11.0
          Resolution:                  |   Keywords:  record type define
Estimated difficulty:  hard            |
---------------------------------------+--------------------------------

Comment (by sjamaan):

 OK, this is pretty bad. We can hack in a special case for {{{begin}}}, but
 that won't fix it in general, because something like {{{(print (define x
 1))}}} can also occur inside the body and won't be detected.
 Interestingly, this seems to be how Gauche does it, because the following
 program runs:

 {{{
 (print (define (x) 1))
 (print (x))
 ;; Prints #<undef> followed by 1
 }}}

 I had a look at how Scheme48 does it:

 Their definitions are disabled completely, except at toplevel and when
 parsing internal defines. Any other place will trigger an error.  Their
 definition of {{{define}}} is:

 {{{
 (define-expander 'define
   (lambda (op op-node exp env)
     (syntax-violation 'define
                       (if (destructure-define exp)
                           "definition in expression context"
                           "ill-formed definition")
                       exp)))
 }}}

 When toplevel is walked, they handle {{{define}}} and friends specially.
 This also allows them to treat {{{define}}} differently from {{{set!}}}.

 Gambit seems to take a similar approach:

 {{{
 (define (##comp-define cte src tail? subexpr?)
   (if (or subexpr?
           (##not ##allow-inner-global-define?))
       (##raise-expression-parsing-exception
        'ill-placed-define
        src)
       ...))
 }}}

 In other words, {{{##comp-define}}} knows if it's being processed as a
 toplevel expression or as a sub-expression. There should never be a define
 in a subexpression (internal {{{define}}}s are transformed to letrec so
 those are gone after processing a {{{lambda}}}, for example).

 Whichever approach we take, a proper fix for this will require quite a bit
 of rework and hardcoding all defining forms into the compiler (which we
 have to do already anyway, to make internal defines work).

 I have to agree with the Scheme48 authors: {{{; The horror of internal
 defines}}}

--
Ticket URL: <https://bugs.call-cc.org/ticket/1309#comment:13>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]