<!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 Sam,</DIV>
<DIV>Thanks for the tip, but it does not help.</DIV>
<DIV>Actually I sent an unnecessary complicated version, but as I think the
problem is the same one there, I wont cluther up this list with another
version.</DIV>
<DIV>Jos</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=samth@ccs.neu.edu href="mailto:samth@ccs.neu.edu">Sam TH</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jos.koot@telefonica.net
href="mailto:jos.koot@telefonica.net">jos koot</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> ;
<A title=jensaxel@soegaard.net href="mailto:jensaxel@soegaard.net">Jens Axel
Søgaard</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, March 11, 2007 2:52
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [plt-scheme] Dot-notation
for structure field access</DIV>
<DIV><BR></DIV>I haven't tested this, but you almost certainly need to
add<BR><BR>(require-for-template mzscheme)<BR><BR>to the `dot'
module.<BR><BR>Hope that helps,<BR><BR>sam th<BR><BR>On 3/11/07, jos koot
<<A href="mailto:jos.koot@telefonica.net">jos.koot@telefonica.net</A>>
wrote:<BR>><BR>><BR>> Hi,<BR>> Inspired by the dot notation of
Jens Axel Søgaard I tried to eliminate the<BR>> need for define-accessor.
See enclosure. However, I can't get rid of the<BR>> error reported at the
end of my trial, reading:<BR>> "compile: bad syntax; reference to top-level
identifier is not allowed,<BR>> because no #%top syntax transformer is
bound in: acc85"<BR>><BR>> Can anyone help me, please. Sorry that I
don't send a stripped version of<BR>> the problem. I have tried many
stripped versions of my code, but in these<BR>> the problem does not
occur.<BR>><BR>> Greetings, Jos Koot<BR>><BR>>
(((((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"))))<BR>><BR>><BR>> ----- Original Message -----<BR>> From:
Jens Axel Søgaard<BR>> To: George Herson<BR>> Cc: <A
href="mailto:plt-scheme@list.cs.brown.edu">plt-scheme@list.cs.brown.edu</A><BR>>
Sent: Thursday, March 08, 2007 11:13 PM<BR>> Subject: [plt-scheme]
Dot-notation for structure field access<BR>><BR>> 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>><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>><BR>><BR>><BR><BR><BR>--
<BR>sam th<BR><A
href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</A><BR></BLOCKQUOTE></BODY></HTML>