<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 23, 2013, at 12:28 AM, Alexander D. Knauth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Right now I'm using Intermediate Student Language, not Racket<div><br></div><div>I was wondering if I could define a function with optional arguments</div></div></blockquote><div><br></div><div><br></div><div>In ISL+ you cannot defined variable-arity functions. In Racket there are many mechanism for doing so (all reduced to one in the core language). You can simulate the idea in ISL+, which you might have done.&nbsp;</div><div><br></div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div> So how do I write the signature? &nbsp;</div></div></blockquote><div><br></div><div>In ISL+, that depends on how you simulate it. The best way is to define a function that consumes a list of values but expects specific kinds of values. For your flexible fold below, you could write:&nbsp;</div><div><br></div><div>;; [List (X Y -&gt; Y) (Z -&gt; X) Y [List-of Z]]&nbsp;</div><div>;; or</div><div>;; [List (X Y -&gt; Y) Y [List-of Z]]&nbsp;</div><div>;; -&gt;&nbsp;&nbsp;Y</div><div><br></div><div>If you do not like 'or', introduce a separate data definition like this:&nbsp;</div><div><br></div><div>;; [FoldArgument X Y Z] is one of:&nbsp;</div><div>;; --&nbsp;[List (X Y -&gt; Y) (Z -&gt; X) Y [List-of Z]]&nbsp;</div><div>;; --&nbsp;[List (X Y -&gt; Y) Y [List-of Z]]&nbsp;</div><div><br></div><div>and then you write&nbsp;</div><div><br></div><div>;; [FoldArgument X Y Z] -&gt; Y&nbsp;</div><div><br></div><div>In Racket, we tend to use square brackets in documentation. In contracts -- a checked form of signature for module boundaries -- we have a notation for this idea.&nbsp;</div><div><br></div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>The particular example I'm thinking of is an abstract fold function that has an optional argument (a function) for the contribution of the first: &nbsp;</div><span class="Apple-style-span" style="font-family: Monaco; "><div><span class="Apple-style-span" style="font-family: Monaco; ">(check-expect (fold + 0 (list 1 2 3)) 6) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;sum, without optional argument</span></div></span><span class="Apple-style-span" style="font-family: Monaco; "><div><span class="Apple-style-span" style="font-family: Monaco; ">(check-expect (fold + identity 0 (list 1 2 3)) 6) &nbsp;;sum, with identity as the optional argument</span></div></span><span class="Apple-style-span" style="font-family: Monaco; "><div><span class="Apple-style-span" style="font-family: Monaco; ">(check-expect (fold + string-length 0 (list "a" "bc" "def")) 6) &nbsp;;total-string-length</span></div></span><span class="Apple-style-span" style="font-family: Monaco; "><span class="Apple-style-span" style="font-family: Monaco; "></span></span><span class="Apple-style-span" style="font-family: Monaco; "><div><br></div></span></div></blockquote><div><br></div><div>I would run your example as&nbsp;</div><div><br></div><div>&nbsp; (fold (compose + string-length) 0 '("a" ...))&nbsp;</div><div><br></div><div>and be done.&nbsp;</div><div><br></div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>You could also design a weird function that does completely different things depending on what the arguments are, like this:</div></div></div></blockquote><br></div><div>For fun, you can write any kind of function you like.&nbsp;</div><div><br></div><div>As long as you design these functions to match the structure of the data definition, your fellow programmers won't mind. Otherwise, they will not like you. See my home page re 'psychopath'.&nbsp;</div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br></body></html>