On occasion the datatype as constructor does get in the way.<div><br></div><div>(struct: MyDataType (...))</div><div><br></div><div>One needs to export the MyDataType identifier for type declarations. But entailed is a constructor function and match deconstruction as well. i.e. I can't provide the type without providing the ctor as well when maybe all I wanted was the type. </div>
<div><br></div><div>For 95% of all Typed structs: isn't a problem. For the remaining 5% one wants some sort of detailed control of the ctor function, which leads to public/private fields, default init values ....</div>
<div><br></div><div>Support for some sort of case-lambda ctors as well as default field values would go far and avoids potential multiple make-Mytype and new-Mytype.</div><div><br></div><div>(struct: Person ([name: String] [age: Integer #default 21]) )</div>
<div><br></div><div>then </div><div><br></div><div>(Person "Joe")</div><div>(Person "Joe" 35) </div><div><br></div><div><div class="gmail_quote">On Thu, May 31, 2012 at 12:21 PM, Neil Toronto <span dir="ltr"><<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 05/31/2012 09:50 AM, Sam Tobin-Hochstadt wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thu, May 31, 2012 at 11:42 AM, Neil Toronto<<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a><u></u>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Currently, the floating-point bitmap type is defined so that its size fields<br>
are Integer, and a guard assures that they're really Nonnegative-Fixnum:<br>
<br>
(struct: flomap ([values : FlVector]<br>
[components : Integer]<br>
[width : Integer]<br>
[height : Integer])<br>
#:transparent<br>
#:guard<br>
(λ (vs c w h name)<br>
(with-asserts ([c nonnegative-fixnum?]<br>
[w nonnegative-fixnum?]<br>
[h nonnegative-fixnum?])<br>
[...] ; elided length check on vs<br>
(values vs c w h))))<br>
<br>
<br>
What I'd *really* like, though, is to have the fields be Nonnegative-Fixnum<br>
in the first place, and simply have a more permissive constructor. Is there<br>
a way to do that? As it is, `flomap-components' always returns an Integer,<br>
but no flomap instance can actually have an integer-valued `components'<br>
field.<br>
</blockquote>
<br>
Could you just structure the program this way?<br>
<br>
(struct: flomap ([values : FlVector]<br>
[components : Nonnegative-Fixnum]<br>
[width : Integer]<br>
[height : Integer])<br>
#:transparent)<br>
<br>
(: make-flomap : FlVector Integer Integer Integer -> flomap)<br>
(define (make-flomap v c w h)<br>
(with-asserts ... (flomap v c w h)))<br>
</blockquote>
<br></div></div>
I could, but `make-flomap' is already defined and used extensively (it's an analogue of make-flvector). Also, not using the structure name to create instances from their field values now makes me feel dirty. :D<span class="HOEnZb"><font color="#888888"><br>
<br>
Neil ⊥</font></span><div class="HOEnZb"><div class="h5"><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
</div></div></blockquote></div><br></div>