guile-user
[Top][All Lists]
Advanced

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

Re: syncase code issue 1.8.8 -> 2.0.11


From: Taylan Ulrich Bayirli/Kammer
Subject: Re: syncase code issue 1.8.8 -> 2.0.11
Date: Thu, 18 Sep 2014 12:20:05 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Matt Wette <address@hidden> writes:

> Hi Folks,
>
> Anyone interested in looking at my syntax-case code?  I wrote this
> several years ago under 1.8.8.  Now moving to 2.0.11: not working :(.
>
> Matt

Hi Matt,

I see your code is doing things like

(format #t "~a\n" (define mt (make-tokiz "abc=def")))

The argument to `format' there is necessarily an "expression" in the
grammar of Scheme.  Definitions like (define ...) are not a valid type
of expression in Scheme.

The only places you can use definitions are

- the top-level of a program/library

- the *beginning* of a "code body" like the body of a `lambda', the body
  of a `let', etc. can have a sequence of definitions; the first
  non-definition expression terminates that sequence

- when you have a (begin ...) form in a position where a definition
  would otherwise be allowed, then the body of this begin may also start
  with a series of definitions; again, the first non-definition
  expression terminates this sequence

The following are examples of well-formed code:

(define (foo)
  (define (helper1)
    ...)
  (define (helper2)
    ...)
  (do-something-with (helper1))
  (do-something-with (helper2)))

(let (...)
  (define (helper1)
    ...)
  ...
  (do-something-with (helper1)))

(let (...)
  (begin
    (define (helper1)
      ...)
    (define (helper2)
      ...)
    (do-something-with (helper1)))
  (do-something-with (helper2)))

The following are not well-formed:

(define (foo)
  (do-something)
  (define (helper1)
    ...)
  (do-something-with (helper1)))
;; Because the helper1 definition is in the middle of the foo lambda
;; body, with a preceding non-definition expression.

(let (...)
  (do-something)
  (begin
    (define (helper1)
      ...)
    (do-something-with (helper1)))
  (do-something)
;; Because the whole `begin' is in the middle of a let body, so the
;; begin may have no definitions at all.  The begin is "in an expression
;; context".

Hope that helps.

Taylan



reply via email to

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