<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>Hi,</DIV>
<DIV>Inspired by the dot notation of Jens Axel Søgaard I tried to eliminate the
need for define-accessor. See enclosure. However, I can't get rid of the error
reported at the end of my trial, reading:</DIV>
<DIV>"compile: bad syntax; reference to top-level identifier is not allowed,
because no #%top syntax transformer is bound in: acc85"</DIV>
<DIV> </DIV>
<DIV>Can anyone help me, please. Sorry that I don't send a stripped version of
the problem. I have tried many stripped versions of my code, but in these
the problem does not occur.</DIV>
<DIV> </DIV>
<DIV>Greetings, Jos Koot</DIV>
<DIV> </DIV>
<DIV>(((((lambda(x)((((((((x x)x)x)x)x)x)x)x))<BR>
(lambda(x)(lambda(y)(x(x y)))))<BR> (lambda(x)(x)x))<BR>
(lambda()(printf "Greetings, Jos~n"))))</DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jensaxel@soegaard.net href="mailto:jensaxel@soegaard.net">Jens Axel
Søgaard</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=gherson@snet.net
href="mailto:gherson@snet.net">George Herson</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">plt-scheme@list.cs.brown.edu</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, March 08, 2007 11:13
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] Dot-notation for
structure field access</DIV>
<DIV><BR></DIV>George Herson skrev:<BR><BR>> May not be the best approach
but I'm enjoying the<BR>> compactness of the resulting code (which
allows<BR>> conventional table-name.column-name notation in a<BR>>
sql-like mini-language).<BR><BR>That remark sparked inspired me to play a
little<BR>with #top in order to get the following to work:<BR><BR>(require
dot)<BR>(define-struct color (r g b) (make-inspector))<BR><BR>(define-accessor
r color-r)<BR>(define-accessor g color-g)<BR>(define-accessor b
color-b)<BR><BR>(define a (make-color 1 2 3))<BR>a.r ; evaluates to
1<BR>a.g ; evaluates to 2<BR>a.b ; evaluates to 3<BR><BR><BR>The
entire program, which by no means is well-tested, is below.<BR><BR>/Jens
Axel<BR><BR>; Put the entire program in a buffer, choose "Pretty Big"<BR>; and
click "Run".<BR><BR>(module dot-helper mzscheme<BR> (provide dot
define-accessor)<BR><BR>
(begin-for-syntax<BR> (define accessors
(list)))<BR><BR> (require-for-syntax (prefix srfi: (lib "1.ss"
"srfi")))<BR> (define-syntax (dot stx)<BR>
(syntax-case stx ()<BR> [(dot expr
accessor)<BR> #`(#,(cdr (srfi:assoc
#'accessor accessors
module-identifier=?))<BR>
expr)]))<BR><BR> (define-syntax (define-accessor
stx)<BR> (syntax-case stx
()<BR> [(define-accessor name
getter)<BR>
(begin<BR> (set!
accessors (cons (cons #'name
#'getter)<BR>
accessors))<BR>
#'(void))])))<BR><BR>(module dot mzscheme<BR> (provide (rename
my-top
#%top)<BR>
define-accessor<BR>
dot)<BR><BR> (require (lib
"pregexp.ss")<BR>
dot-helper)<BR><BR> (define-for-syntax (contains-dot?
sym)<BR> (member #\.
(string->list<BR>
(symbol->string sym))))<BR><BR> (define-for-syntax
(split-at-dot sym)<BR>
(cond<BR> [(regexp-match
#rx"^([^.]*)\\.([^.]*)$" (symbol->string
sym))<BR> =>(lambda
(result)<BR>
(values (string->symbol (list-ref result
1))<BR>
(string->symbol (list-ref result
2))))]<BR> [else #f]))<BR><BR>
(define-syntax (my-top stx)<BR> (syntax-case stx
()<BR> [(_ .
name)<BR> (and (identifier?
#'name)<BR>
(contains-dot? (syntax-e
#'name)))<BR> (let-values ([(before
after)<BR>
(split-at-dot (syntax-e
#'name))])<BR>
(with-syntax ([var (datum->syntax-object #'stx
before)]<BR>
[acc (datum->syntax-object #'stx
after)])<BR>
#'(dot var acc)))]<BR> [(_ .
name)<BR> #'(#%top .
name)])))<BR><BR><BR><BR>(require dot)<BR>(define-struct color (r g b)
(make-inspector))<BR><BR>(define-accessor r color-r)<BR>(define-accessor g
color-g)<BR>(define-accessor b color-b)<BR><BR>(define a (make-color 1 2
3))<BR>a.r<BR>a.g<BR>a.b<BR><BR>_________________________________________________<BR>
For list-related administrative tasks:<BR> <A
href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</A><BR></BLOCKQUOTE></BODY></HTML>