<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">&lt;<a href="mailto:philipp@dikmann.de" target="_blank">philipp@dikmann.de</a>&gt;</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 &quot;Fear of
    Macros&quot; 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-&gt;syntax at one point, but I had put the
        quotesyntax on datum-&gt;syntax, not on id directly. I don&#39;t
        understand why that would make a difference, it seems like it is
        similar to doing (list &#39;a &#39;b) instead of &#39;(a b)... oh, nope, now
        I get it. It specifically *is* similar, except my second example
        should have been &#39;(list a b).</p>
      <div class="gmail_quote">On May 2, 2013 10:38 PM, &quot;Sean McBeth&quot;
        &lt;<a href="mailto:sean.mcbeth@gmail.com" target="_blank">sean.mcbeth@gmail.com</a>&gt;
        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, &quot;Jay
            McCarthy&quot; &lt;<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>&gt;
            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&#39;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 #&#39;id &quot;~a-1&quot; #&#39;id)]<br>
                                 [id-2 (datum-&gt;syntax<br>
                                        #&#39;id<br>
                                        (string-&gt;symbol<br>
                                         (format &quot;~a-2&quot;<br>
                                                 (syntax-&gt;datum<br>
                                                  #&#39;id))))])<br>
                     #&#39;(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 &lt;<a href="mailto:sean.mcbeth@gmail.com" target="_blank">sean.mcbeth@gmail.com</a>&gt;
              wrote:<br>
              &gt; Hi there!<br>
              &gt;<br>
              &gt; I&#39;m pretty new to Racket, though not the basic
              concepts of functional<br>
              &gt; programming [1] Maybe I don&#39;t need macros here at
              all, but it seemed like<br>
              &gt; the right sort of lever when I first started, but now
              I&#39;m pretty stuck[2]<br>
              &gt; and I don&#39;t understand enough about the macro system
              yet to be able to<br>
              &gt; figure this out.<br>
              &gt;<br>
              &gt; Basically, I&#39;m trying to make a database migration
              tool + relational mapper.<br>
              &gt; I&#39;d like to be able to define my tables in an
              abbreviated Racket syntax and<br>
              &gt; use the definition to generate everything from the
              create-table SQL scripts,<br>
              &gt; a few, basic CRUD-scripts-for-all-columns to structs
              that will mirror a full<br>
              &gt; table row when processing the query results.<br>
              &gt;<br>
              &gt; Right now, the table definition looks like this:<br>
              &gt;<br>
              &gt; (define-table tickets get-all-tickets<br>
              &gt;  ([ticket_id serial primary-key]<br>
              &gt;   [priority int nullable] ;; I believe in making
              not-null the default case<br>
              &gt;   [description (varchar max)]<br>
              &gt;   [finished_on datetime (default &quot;9999-12-31
              23:59:59.999&quot;)])<br>
              &gt;<br>
              &gt; And this is pretty easy to parse into some &quot;table&quot;
              structs that describe<br>
              &gt; everything fairly sufficiently[3]:<br>
              &gt; <a href="https://gist.github.com/capnmidnight/5506674" target="_blank">https://gist.github.com/capnmidnight/5506674</a><br>
              &gt;<br>
              &gt; Now, my sticking point is that I don&#39;t want to have
              explicitly define that<br>
              &gt; &quot;get-all-tickets&quot; identifier. I notice that, in my
              creating the &quot;column&quot;<br>
              &gt; struct, I&#39;ve received a number of procedures for the
              constructor and field<br>
              &gt; accessors, all given a prefix of &quot;column&quot; for their
              identifier. So at first<br>
              &gt; glance, it seems like there are forms like struct
              that are capable of<br>
              &gt; dynamically defining identifiers.<br>
              &gt;<br>
              &gt; So, I stepped into the definition for struct and
              tried to make sense of it,<br>
              &gt; but the best I could figure out was that struct used
              syntax-case instead of<br>
              &gt; syntax-rules. It was a bit of a hair-ball for me, I
              couldn&#39;t suss out the<br>
              &gt; cross references, and at least at this late of an
              hour I&#39;m having trouble<br>
              &gt; understanding the documentation on syntax-case.<br>
              &gt;<br>
              &gt; Specifically, I tried to do something like:<br>
              &gt;<br>
              &gt; (define-syntax (double-define stx)<br>
              &gt;   (syntax-case stx (double-define)<br>
              &gt;     [(_ id val1 val2)<br>
              &gt;      #`(begin (define id-1 val1)<br>
              &gt;               (define id-2 val2))]))<br>
              &gt;<br>
              &gt; (double-define id 3 7)<br>
              &gt; (displayln id-1) ;; error &quot;id-1 unbound identifier&quot;<br>
              &gt; (displayln id-2)<br>
              &gt;<br>
              &gt; I then tried something like:<br>
              &gt;<br>
              &gt; (define-syntax (double-define stx)<br>
              &gt;   (syntax-case stx (double-define)<br>
              &gt;     [(_ id val1 val2)<br>
              &gt;      (with-syntax ([id-1 #&#39;(string-&gt;symbol (format
              &quot;~a-1&quot; id))] ;; error<br>
              &gt; &quot;define: not an identifier, identifier with default,
              or keyword for<br>
              &gt; procedure argument&quot;<br>
              &gt;                    [id-2 #&#39;(string-&gt;symbol (format
              &quot;~a-2&quot; id))])<br>
              &gt;        #&#39;(begin (define id-1 val1)<br>
              &gt;                 (define id-2 val2)))]))<br>
              &gt;<br>
              &gt; (double-define id 3 7)<br>
              &gt; (displayln id-1)<br>
              &gt; (displayln id-2)<br>
              &gt;<br>
              &gt; Clearly, not correct.<br>
              &gt;<br>
              &gt; I could make the table struct into a table class and
              then just define a<br>
              &gt; get-all method that does what I want, but that kind
              of feels like giving up<br>
              &gt; and I&#39;m more interested in using this to learn more
              about using macros, as<br>
              &gt; it has already done for me.<br>
              &gt;<br>
              &gt;<br>
              &gt;<br>
              &gt; [1] Functional C# is something of a job safety
              program of mine :P<br>
              &gt;<br>
              &gt; [2] i.e. been banging my head against the desk for
              the last 6 hours. I have<br>
              &gt; gotten pretty comfortable with syntax-rules though,
              so it wasn&#39;t a complete<br>
              &gt; waste.<br>
              &gt;<br>
              &gt; [3] This isn&#39;t the final form, but I&#39;m just pushing
              some code around to try<br>
              &gt; to get the basic concepts working. For example, the
              get-all-tickets<br>
              &gt; procedure wouldn&#39;t just return the query, it&#39;d
              eventually execute it and<br>
              &gt; return the results.<br>
              &gt;<br>
              &gt; ____________________<br>
              &gt;   Racket Users list:<br>
              &gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
              &gt;<br>
              <br>
              <br>
              <br>
              --<br>
              Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>&gt;<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>
              &quot;The glory of God is Intelligence&quot; - D&amp;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>