Hi all,

Recently I was using the `stx-car` function from `syntax/stx`. At some
point, I had called it on a non-syntax pair and the error message came
from `car`, which is used inside the implementation of `stx-car`.

I thought it would be nice to add contracts in `syntax/stx` for better
error messages, but it turns out that the contract library depends on it
and so it's impossible to do without introducing cycles.

So I would like to propose a `syntax/syntax` library with the following:
  * provides `syntax/stx` functions with contracts attached
    (caveat: core libraries like `racket/contract` would still use
             `syntax/stx`)
  * for consistency with the rest of the language,  `stx-car` and
    friends would be renamed to use the `syntax-` prefix instead of
    `stx-`.
  * the name of the library is also consistent with the rest of the
    language.

This could replace `syntax/stx` for most users and provide both better
error messages and identifiers that follow standard Racket naming
convention.

I've attached a patch that implements this. Any comments?

Cheers,
Asumu
>From f480e8511c6f162e6a35d06861fb5dcd5a3bfb7a Mon Sep 17 00:00:00 2001
From: Asumu Takikawa <as...@ccs.neu.edu>
Date: Fri, 15 Jun 2012 15:00:20 -0400
Subject: [PATCH] Add syntax/syntax library

(aliases for syntax/stx functions with contracts)
---
 collects/syntax/syntax.rkt |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 collects/syntax/syntax.rkt

diff --git a/collects/syntax/syntax.rkt b/collects/syntax/syntax.rkt
new file mode 100644
index 0000000..73261b7
--- /dev/null
+++ b/collects/syntax/syntax.rkt
@@ -0,0 +1,24 @@
+#lang racket/base
+
+;; syntax utilities
+
+(require
+ racket/contract/base
+ (rename-in syntax/stx
+            [stx-null? syntax-null?]
+            [stx-pair? syntax-pair?]
+            [stx-list? syntax-list?]
+            [stx-car syntax-car]
+            [stx-cdr syntax-cdr]
+            [stx->list syntax->list]
+            [stx-map syntax-map]))
+
+(provide/contract
+ [syntax-null? (-> any/c boolean?)]
+ [syntax-pair? (-> any/c boolean?)]
+ [syntax-list? (-> any/c boolean?)]
+ [syntax-car (-> syntax-pair? any)]
+ [syntax-cdr (-> syntax-pair? any)]
+ [syntax->list (-> syntax-list? (or/c list? #f))]
+ [syntax-map (->* (procedure?) #:rest syntax-list? any)]
+ [module-or-top-identifier=? (-> identifier? identifier? boolean?)])
\ No newline at end of file
-- 
1.7.10

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Reply via email to