<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi all,</div><div><br></div><div>I'm experimenting with syntax/parse as a way of implementing optional keyword arguments with default values.</div><div><br></div><div>I've included some test code below. I'm new to this library so I want to make sure I'm not missing anything. Is this the intended approach for this kind of thing?</div><div><br></div><div>Many thanks,</div><div><br></div><div>-- Dave</div><div><br></div><div><span class="Apple-style-span" style="font-family: Monaco; ">; keyword-test.ss =================================</span></div><div><font class="Apple-style-span" face="Monaco"><br></font></div><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; ">#lang scheme</span><br><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; ">(require (for-syntax syntax/parse))</span><br><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: medium; "><div><font class="Apple-style-span" face="Monaco">; Example macro -----------------------------------</font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div></span></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;">; (_ [#:a expr] [#:b expr])<br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;">;<br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;">; Expands to (list a b) where a and b:<br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;">; - are either specified using #:a and #:b;<br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;">; - or take on default values 'default-a and 'default-b.<br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; ">(define-syntax (test stx)</span><br><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; "> (syntax-parse stx</span><br><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; "> [(_ (~or (~optional (~seq #:a user-a) #:name "#:a keyword")</span><br><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; "> (~optional (~seq #:b user-b) #:name "#:b keyword")) ...)</span><br><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; "> (with-syntax ([a (or (attribute user-a) #''default-a)]</span><br><span class="Apple-style-span" style="font-family: Monaco; font-size: 13px; "> [b (or (attribute user-b) #''default-b)])</span><br><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"> #'(list a b))]))<br></span></font><font class="Apple-style-span" face="Monaco"><br></font><div><font class="Apple-style-span" face="Monaco">; Test code ---------------------------------------</font></div><div><font class="Apple-style-span" face="Monaco"><br></font><font class="Apple-style-span" face="Monaco">(test) ; => '(default-a default-b)<br></font><font class="Apple-style-span" face="Monaco">(test #:a 1) ; => '(1 default-b)<br></font><font class="Apple-style-span" face="Monaco"><span class="Apple-style-span" style="font-family: 'Lucida Grande'; "><font class="Apple-style-span" face="Monaco">(test #:a 1 #:b 2) ; => '(1 2)</font></span></font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div><div><font class="Apple-style-span" face="Monaco">; =================================================</font></div><div><div><div><br></div></div></div></div></body></html>