<div dir="ltr">Hi Stephen,<div><br></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">&gt; As an educational side project, I&#39;ve been toying around with a</span></div><div>&gt; <span style="font-family:arial,sans-serif;font-size:15.555556297302246px">different way of organizing all the binding forms. What I wanted to do</span></div>
<div>&gt; <span style="font-family:arial,sans-serif;font-size:15.555556297302246px">is remove the need to manually combine current (and future) binding</span></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">&gt; f</span><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">orms by moving the binding &quot;logic&quot; to the binding site itself.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">Your goals seem similar to the ones I had for &quot;bind&quot;.</span></div>
<div><font face="arial, sans-serif" size="1">The different binding forms all have binding clauses.</font></div><div><font face="arial, sans-serif" size="1">I introduced binding clause transformers that decide what</font></div>
<div><font face="arial, sans-serif" size="1">to do with a given binding clause.</font></div><div><font face="arial, sans-serif" size="1"><br></font></div><div><font face="arial, sans-serif" size="1">The binding clause transformer :delay can for example</font></div>
<div><font face="arial, sans-serif" size="1">be used like this (where bind is my name for a let that understands</font></div><div><font face="arial, sans-serif" size="1">binding clause transformers).</font></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px"><br>
</span></div><div><table cellspacing="0" class="" style="font-family:monospace;white-space:nowrap;color:rgb(0,0,0)"><tbody><tr style="white-space:inherit"><td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit">
<span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._bind%2Fmain..rkt%29._bind%29%29" class="" style="text-decoration:none;color:black">bind</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">[</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._bind%2Fmain..rkt%29._~3adelay%29%29" class="" style="text-decoration:none;color:black">:delay</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(34,139,34)">1</span><span class="" 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 class="" style="font-family:monospace">  </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28def._%28%28quote._~23~25kernel%29._%2B%29%29" class="" style="text-decoration:none;color:blue">+</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span></td>
</tr></tbody></table></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">At macro expansion time this is expanded into</span></div>
<div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">   </span></div><table cellspacing="0" class="" style="font-family:monospace;white-space:nowrap;color:rgb(0,0,0)"><tbody><tr style="white-space:inherit">
<td style="padding-left:0px;padding-right:0px;vertical-align:baseline;white-space:inherit"><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29" class="" style="text-decoration:none;color:black">let</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">[</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%29%29" class="" style="text-decoration:none;color:black">delay</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(34,139,34)">1</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">]</span><span class="" 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 class="" style="font-family:monospace">  </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let-syntax%29%29" class="" style="text-decoration:none;color:black">let-syntax</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">[</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">clause</span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29" class="" style="text-decoration:none;color:black">...</a></span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">]</span><span class="" 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 class="" style="font-family:monospace">    </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">(</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html&amp;https://github.com/soegaard/bind/blob/master/scribblings/bind.html=false#%28def._%28%28quote._~23~25kernel%29._%2B%29%29" class="" style="text-decoration:none;color:blue">+</a></span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace"> </span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(38,38,128)">x</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)</span><span class="" style="font-family:monospace;white-space:inherit;color:rgb(132,60,36)">)<br>
<br></span></td></tr></tbody></table><div><span style="font-family:arial,sans-serif;font-size:15.555556297302246px">where clause ... introduce a syntax binding such that x in the body</span></div><div><font face="arial, sans-serif" size="1">expands to a use of x. </font></div>
<div><font face="arial, sans-serif" size="1"><br></font></div><div><font face="arial, sans-serif" size="1">This is just an example though. The key concept is the binding clause transformer.</font></div><div>Here is the documentation for bind and def (let and define):</div>
<div><span style="font-family:arial,sans-serif;font-size:x-small"><a href="http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html">http://htmlpreview.github.io/?https://github.com/soegaard/bind/blob/master/scribblings/bind.html</a></span><br>
</div><div><span style="font-family:arial,sans-serif;font-size:x-small"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:x-small">Here is the Github repository:  </span><span style="font-family:arial,sans-serif;font-size:x-small"><a href="https://github.com/soegaard/bind">https://github.com/soegaard/bind</a></span></div>
<div><span style="font-family:arial,sans-serif;font-size:x-small"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:x-small">Another small example:</span></div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:13px;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(221,221,221);line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">
<span class="" style="color:rgb(0,128,128)">Example:</span>                                                       
<span class="" style="color:rgb(0,128,128)">&gt;</span> <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">bind</span> <span class="">([</span><span class="" style="color:rgb(153,0,0);font-weight:bold">v</span> <span class="" style="color:rgb(0,128,128)">:vector</span> <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">for/vector</span> <span class="">([</span><span class="" style="color:rgb(153,0,0);font-weight:bold">i</span> <span class="" style="color:rgb(0,153,153)">5</span><span class="">])</span> <span class="">(</span><span class="" style="color:rgb(0,134,179)">random </span><span class="" style="color:rgb(0,153,153)">10</span><span class="">))])</span>         
    <span class="">(</span><span class="" style="color:rgb(0,134,179)">displayln </span><span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">~a</span> <span class="" style="color:rgb(221,17,68)">&quot;The vector &quot;</span> <span class="" style="color:rgb(0,128,128)">v</span> <span class="" style="color:rgb(221,17,68)">&quot; contains &quot;</span> <span class="" style="color:rgb(0,128,128)">v</span><span class="">))</span>            
    <span class="">(</span><span class="" style="color:rgb(0,134,179)">displayln </span><span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">~a</span> <span class="" style="color:rgb(221,17,68)">&quot;The first element is: &quot;</span> <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">v</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)))</span>            
    <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">v!</span> <span class="" style="color:rgb(0,153,153)">0</span> <span class="" style="color:rgb(0,153,153)">42</span><span class="">)</span>                                                  
    <span class="">(</span><span class="" style="color:rgb(0,134,179)">displayln </span><span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">~a</span> <span class="" style="color:rgb(221,17,68)">&quot;The first element is now: &quot;</span> <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">v</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)))</span>        
    <span class="">(</span><span class="" style="color:rgb(0,134,179)">displayln </span><span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">~a</span> <span class="" style="color:rgb(221,17,68)">&quot;The middle three elements are: &quot;</span> <span class="">(</span><span class="" style="color:rgb(153,0,0);font-weight:bold">v</span> <span class="" style="color:rgb(0,153,153)">1</span> <span class="" style="color:rgb(0,153,153)">4</span><span class="">))))</span></pre>
</div><div><font face="arial, sans-serif" size="1"><br></font></div><div><font face="arial, sans-serif" size="1">This expands into uses of vector-ref and vector-set! so there is no runtime penalty</font></div><div><font face="arial, sans-serif" size="1">for using this shorthand.</font></div>
<div><font face="arial, sans-serif" size="1"><br></font></div><div><font face="arial, sans-serif" size="1">/Jens Axel</font></div><div><font face="arial, sans-serif" size="1"><br></font></div><div><br></div><div class="gmail_extra">
<div class="gmail_quote">2013/8/26 Stephen Chang <span dir="ltr">&lt;<a href="mailto:stchang@ccs.neu.edu" target="_blank">stchang@ccs.neu.edu</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi dev,<br>
<br>
I&#39;ve noticed that Racket has a lot of convenient binding forms but<br>
they don&#39;t fit together unless someone does it manually (for example<br>
there&#39;s match-let and match-let-values, but no match-for).<br>
<br>
As an educational side project, I&#39;ve been toying around with a<br>
different way of organizing all the binding forms. What I wanted to do<br>
is remove the need to manually combine current (and future) binding<br>
forms by moving the binding &quot;logic&quot; to the binding site itself.<br>
<br>
Inspired by the in-vogue generics movement in the Racket world, I&#39;ve<br>
hacked together a sort of &quot;generic interface&quot; for bindings (in<br>
reality, it&#39;s just a bunch of syntax properties right now), and<br>
implemented alternate versions of some of the main binding forms that<br>
support &quot;instances&quot; of these generic bindings.<br>
<br>
To illustrate, here are some test cases for a generic define I<br>
implemented (~define). I also implemented binding &quot;instances&quot; for<br>
match and values (which I arbitrarily named $ and ~v below) and I can<br>
use these forms in (mostly) any binding position that supports generic<br>
bindings.<br>
<br>
;; functions<br>
&gt; (~define (f1 x y) (+ x y))<br>
&gt; (f1 10 20)<br>
30<br>
&gt; (~define (f2 ($ (list x y))) (+ x y))<br>
&gt; (f2 (list 10 20))<br>
30<br>
<br>
;; non-functions<br>
&gt; (~define a1 100)<br>
&gt; a1<br>
100<br>
&gt; (~define (~v a2 a3) (values 134 456))<br>
&gt; a2<br>
134<br>
&gt; a3<br>
456<br>
<br>
You can nest bind instances too:<br>
<br>
&gt; (~define (~v ($ (list b1 b2)) b3) (values (list 22 33) 44))<br>
&gt; b1<br>
22<br>
&gt; b2<br>
33<br>
&gt; b3<br>
44<br>
<br>
Does anyone think this is useful? Or is it just a lot of work to save<br>
a little bit of typing? Has anyone tried something like this before?<br>
<br>
It&#39;s still very much a work in progress but I figure I would ask for<br>
some feedback earlier rather than too later, in case there is<br>
something that makes this infeasible.<br>
<br>
Brave souls can look at the hackery here:<br>
<a href="https://github.com/stchang/generic-bind/blob/master/generic-bind.rkt" target="_blank">https://github.com/stchang/generic-bind/blob/master/generic-bind.rkt</a><br>
(Warning: I&#39;m still trying to figure out all the toys in the Racket<br>
macro toolbox. For the most part, everything still looks like a<br>
syntax-rule/case/parse/-&gt;datum nail to my hammer.)<br>
<br>
Technical question: I couldn&#39;t figure out a nice way to implement<br>
~let. Essentially, I want a let form where some clauses are let-values<br>
and some are match-let, but I need to bind them all at the same time,<br>
like let. I can&#39;t define a ~lambda that works with values because<br>
functions in racket can&#39;t receive values. Anyone have any ideas?<br>
<br>
Side observation: Trying to get things to work with multiple return<br>
values was a pain because they don&#39;t compose (as in, functions can<br>
produce them but can&#39;t receive them). Not sure if anything can be done<br>
about this though.<br>
_________________________<br>
  Racket Developers list:<br>
  <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>-- <br>Jens Axel Søgaard<br><br>
</div></div>