[Top][All Lists]

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

syncase code issue 1.8.8 -> 2.0.11

From: Matt Wette
Subject: syncase code issue 1.8.8 -> 2.0.11
Date: Wed, 17 Sep 2014 18:18:05 -0700

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 :(.


This uses syntax-case.  It works in 1.8.8, but I get errors in 2.0.11.   I'm 
guessing I don't understand something about syntax-case in R6RS.  I learned (or 
mislearned) syntax-case from the papers by Kent Dybvig, not from the R6RS spec.

Here is what I'm trying to do:
@item define-tokenizer name (rex1 tok1) (rex2 tok2) ...
Define tokenizer for which one can build string tokenizers.

(define-tokenizer tokiz ("[0-9]+" #\1) ("[a-z]+" #\a))
(define mt (make-tokiz "abc=def"))
(tokiz-latok mt) -> #\a
(tokiz-laval mt) -> "abc"
(tokiz-match mt #\a)
(tokiz-latok mt) -> #\=

In 1.8.8, I get the above output.   In 2.0.11 I get

Syntax-case macros are now a part of Guile core; importing (ice-9 syncase) is 
no longer necessary.   <=(no issue here)
ice-9/psyntax.scm:1274:12: In procedure dobody:
ice-9/psyntax.scm:1274:12: Syntax error:
u1.scm:106:18: definition in expression context, where definitions are not 
allowed, in form
    (define make-tokiz
      (lambda (string)
        (let ((pobj (vector string 0 (string-length string) #\nul "")))
          (tokiz-match pobj #\nul) pobj)))

Here is synopsis of the code (see attached for all of it):

(define-syntax define-tokenizer
  ;; pobj = parse object = #(string ix nd latok laval)
  (lambda (x)
    (syntax-case x ()
      ((_ name (c1 r1) ...)
       (with-syntax ((maker (sc-gen-id (syntax name) "make-" (syntax name)))
            (define maker
              (lambda (string)
                (let ((pobj (vector string 0 (string-length string) #\nul "")))
                  (match pobj #\nul)  ; prime latok/laval in parse-object

(define sc-gen-id  ;; (gc-gen-id (syntax name) "make-" (syntax name)) where 
name=foo -> make-foo 
  (lambda (template-id . args)
    (datum->syntax-object template-id
       (apply string-append
              (map (lambda (x) 
                     (if (string? x) x
                         (symbol->string (syntax-object->datum x))))

Attachment: u1.scm
Description: Binary data

reply via email to

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