<div dir="ltr">Wow, section 4 is exactly, almost word for word, what I was trying to do. This is a great resource.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 3, 2013 at 7:35 AM, Philipp Dikmann <span dir="ltr"><<a href="mailto:philipp@dikmann.de" target="_blank">philipp@dikmann.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    You might have already read it, but I also found the guide "Fear of
    Macros" by Greg Hendershott incredibly helpful in understanding
    them, especially considering things like with-syntax and format-id:<br>
    <a href="http://www.greghendershott.com/fear-of-macros/index.html" target="_blank">http://www.greghendershott.com/fear-of-macros/index.html</a><div><div class="h5"><br>
    <br>
    <div>On 03.05.13 04:57, Sean McBeth wrote:<br>
    </div>
    <blockquote type="cite">
      <p dir="ltr">I think I get it just from reading it (in bed,  on
        the phone, annoying the wife). I had tried to do almost this
        very thing with datum->syntax at one point, but I had put the
        quotesyntax on datum->syntax, not on id directly. I don't
        understand why that would make a difference, it seems like it is
        similar to doing (list 'a 'b) instead of '(a b)... oh, nope, now
        I get it. It specifically *is* similar, except my second example
        should have been '(list a b).</p>
      <div class="gmail_quote">On May 2, 2013 10:38 PM, "Sean McBeth"
        <<a href="mailto:sean.mcbeth@gmail.com" target="_blank">sean.mcbeth@gmail.com</a>>
        wrote:<br type="attribution">
        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <p dir="ltr">Aaah, man. Thanks. Shutdown the pc for the night
            so u will try tomorrow.</p>
          <div class="gmail_quote">On May 2, 2013 10:35 PM, "Jay
            McCarthy" <<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>>
            wrote:<br type="attribution">
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              You were close to what you want. Here's a version with a
              nice utility<br>
              and then the underlying machinery that makes it:<br>
              <br>
              #lang racket<br>
              (require (for-syntax racket/syntax))<br>
              <br>
              (define-syntax (double-define stx)<br>
                (syntax-case stx (double-define)<br>
                  [(_ id val1 val2)<br>
                   (with-syntax ([id-1 (format-id #'id "~a-1" #'id)]<br>
                                 [id-2 (datum->syntax<br>
                                        #'id<br>
                                        (string->symbol<br>
                                         (format "~a-2"<br>
                                                 (syntax->datum<br>
                                                  #'id))))])<br>
                     #'(begin (define id-1 val1)<br>
                              (define id-2 val2)))]))<br>
              <br>
              (double-define id 3 7)<br>
              (displayln id-1)<br>
              (displayln id-2)<br>
              <br>
              On Thu, May 2, 2013 at 8:29 PM, Sean McBeth <<a href="mailto:sean.mcbeth@gmail.com" target="_blank">sean.mcbeth@gmail.com</a>>
              wrote:<br>
              > Hi there!<br>
              ><br>
              > I'm pretty new to Racket, though not the basic
              concepts of functional<br>
              > programming [1] Maybe I don't need macros here at
              all, but it seemed like<br>
              > the right sort of lever when I first started, but now
              I'm pretty stuck[2]<br>
              > and I don't understand enough about the macro system
              yet to be able to<br>
              > figure this out.<br>
              ><br>
              > Basically, I'm trying to make a database migration
              tool + relational mapper.<br>
              > I'd like to be able to define my tables in an
              abbreviated Racket syntax and<br>
              > use the definition to generate everything from the
              create-table SQL scripts,<br>
              > a few, basic CRUD-scripts-for-all-columns to structs
              that will mirror a full<br>
              > table row when processing the query results.<br>
              ><br>
              > Right now, the table definition looks like this:<br>
              ><br>
              > (define-table tickets get-all-tickets<br>
              >  ([ticket_id serial primary-key]<br>
              >   [priority int nullable] ;; I believe in making
              not-null the default case<br>
              >   [description (varchar max)]<br>
              >   [finished_on datetime (default "9999-12-31
              23:59:59.999")])<br>
              ><br>
              > And this is pretty easy to parse into some "table"
              structs that describe<br>
              > everything fairly sufficiently[3]:<br>
              > <a href="https://gist.github.com/capnmidnight/5506674" target="_blank">https://gist.github.com/capnmidnight/5506674</a><br>
              ><br>
              > Now, my sticking point is that I don't want to have
              explicitly define that<br>
              > "get-all-tickets" identifier. I notice that, in my
              creating the "column"<br>
              > struct, I've received a number of procedures for the
              constructor and field<br>
              > accessors, all given a prefix of "column" for their
              identifier. So at first<br>
              > glance, it seems like there are forms like struct
              that are capable of<br>
              > dynamically defining identifiers.<br>
              ><br>
              > So, I stepped into the definition for struct and
              tried to make sense of it,<br>
              > but the best I could figure out was that struct used
              syntax-case instead of<br>
              > syntax-rules. It was a bit of a hair-ball for me, I
              couldn't suss out the<br>
              > cross references, and at least at this late of an
              hour I'm having trouble<br>
              > understanding the documentation on syntax-case.<br>
              ><br>
              > Specifically, I tried to do something like:<br>
              ><br>
              > (define-syntax (double-define stx)<br>
              >   (syntax-case stx (double-define)<br>
              >     [(_ id val1 val2)<br>
              >      #`(begin (define id-1 val1)<br>
              >               (define id-2 val2))]))<br>
              ><br>
              > (double-define id 3 7)<br>
              > (displayln id-1) ;; error "id-1 unbound identifier"<br>
              > (displayln id-2)<br>
              ><br>
              > I then tried something like:<br>
              ><br>
              > (define-syntax (double-define stx)<br>
              >   (syntax-case stx (double-define)<br>
              >     [(_ id val1 val2)<br>
              >      (with-syntax ([id-1 #'(string->symbol (format
              "~a-1" id))] ;; error<br>
              > "define: not an identifier, identifier with default,
              or keyword for<br>
              > procedure argument"<br>
              >                    [id-2 #'(string->symbol (format
              "~a-2" id))])<br>
              >        #'(begin (define id-1 val1)<br>
              >                 (define id-2 val2)))]))<br>
              ><br>
              > (double-define id 3 7)<br>
              > (displayln id-1)<br>
              > (displayln id-2)<br>
              ><br>
              > Clearly, not correct.<br>
              ><br>
              > I could make the table struct into a table class and
              then just define a<br>
              > get-all method that does what I want, but that kind
              of feels like giving up<br>
              > and I'm more interested in using this to learn more
              about using macros, as<br>
              > it has already done for me.<br>
              ><br>
              ><br>
              ><br>
              > [1] Functional C# is something of a job safety
              program of mine :P<br>
              ><br>
              > [2] i.e. been banging my head against the desk for
              the last 6 hours. I have<br>
              > gotten pretty comfortable with syntax-rules though,
              so it wasn't a complete<br>
              > waste.<br>
              ><br>
              > [3] This isn't the final form, but I'm just pushing
              some code around to try<br>
              > to get the basic concepts working. For example, the
              get-all-tickets<br>
              > procedure wouldn't just return the query, it'd
              eventually execute it and<br>
              > return the results.<br>
              ><br>
              > ____________________<br>
              >   Racket Users list:<br>
              >   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
              ><br>
              <br>
              <br>
              <br>
              --<br>
              Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>
              Assistant Professor / Brigham Young University<br>
              <a href="http://faculty.cs.byu.edu/%7Ejay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
              <br>
              "The glory of God is Intelligence" - D&C 93<br>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>____________________
  Racket Users list:
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>
</blockquote></div><br></div>