<div class="gmail_quote">Hi Racketeers,<div><br></div><div>Just getting started in the whole Racket thing - it seems like the nicest Lisp around at this point in time. A big reason for me wanting to get to know Lisp/Scheme/Racket was to play around with macros and it seems like Racket takes the idea to its logical conclusion going beyond hygenic macros with its whole language building features. However I have to say I have found it a little difficult to fully get my head around some of the ideas (phase levels etc) so I suppose i could at least understand why some people yearn for the simplicity of "defmacro" despite its flaws. I think i just need to plow through the references some more.</div>
<div><br></div><div>Anyway for mostly self-educational purposes I was trying to get a particular macro working and cant seem to do it. The inspiration behind it was that I was looking at the Racket Object System and I kind of felt like there was a little less typing to get a class going. I'm also a bit of a fan of light feeling OO systems like in Python that dont really care about enforcing privacy and just wanted to give the class declaration a name and then have a public variable/property available without the need to write 3 lines. In other words instead of typing all this:</div>
<div><br></div><div><table cellspacing="0" style="text-align:left;white-space:inherit;font-family:serif"><tbody><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit">
<span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._class))" style="text-decoration:none;color:black" target="_blank">class</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(def._((lib._racket/private/class-internal..rkt)._object~25))" style="text-decoration:none;color:blue" target="_blank">object%</a></span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._init))" style="text-decoration:none;color:black" target="_blank">init</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">initialization argument</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/define.html#(form._((lib._racket/private/base..rkt)._define))" style="text-decoration:none;color:black" target="_blank">define</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">current-size</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">field</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._define/public))" style="text-decoration:none;color:black" target="_blank">define/public</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">get-size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">current-size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> .............<br><br>I wanted to be able to write something like:<br>
<br> (init+ size)<br><br>that would expand to something like:<br><table cellspacing="0" style="white-space:inherit;text-align:left;font-family:serif"><tbody><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit">
<span style="font-family:monospace"><br> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._init))" style="text-decoration:none;color:black" target="_blank">init</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">initialization argument</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/define.html#(form._((lib._racket/private/base..rkt)._define))" style="text-decoration:none;color:black" target="_blank">define</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size+</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">field</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._define/public))" style="text-decoration:none;color:black" target="_blank">define/public</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size++</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size+</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)<br>
<br>even better would be an expansion of (init+ size) to:</span></td></tr></tbody></table><br><table cellspacing="0" style="white-space:inherit;text-align:left;font-family:serif"><tbody><tr style="white-space:inherit">
<td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._init))" style="text-decoration:none;color:black" target="_blank">init</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size++</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">initialization argument</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/define.html#(form._((lib._racket/private/base..rkt)._define))" style="text-decoration:none;color:black" target="_blank">define</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size+</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size++</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">;</span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(194,116,31)">field</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._define/public))" style="text-decoration:none;color:black" target="_blank">define/public</a></span><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span></td>
</tr><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span style="font-family:monospace"> </span><span style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">size+</span><span style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)<br>
<br>so that I had a public accesssor method that had the same name as the original declaration. <br><br><br></span></td></tr></tbody></table>As mentioned this is mainly a self-educational exercise. I know there is "init-field" that would pretty much take care of this and there are some prototype based Object systems in Planet but I just wanted to see if this was possible and how/why not.<br>
<br>Anyway hope its not too stupid a question.</span></td></tr></tbody></table></div>
</div><br>