<div dir="ltr"><div><div>Printing and transparency are in fact separate:<br><br>(struct test (x)<br> #:methods gen:custom-write<br> [(define (write-proc t p m)<br> (write (format "<test ~a>" (test-x t)) p))])<br>
<br></div>The above untangles the concepts:<br><br>> (test 5)<br>"<test 5>"<br>> (struct? (test 5))<br>#f<br><br></div>But I suppose it could be useful to have a comparable default printer without struct? returning #t, like (struct test (x) #:show)<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 13, 2014 at 9:00 AM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>We need to distinguish at least two aspects of this question: </div>
<div><br></div><div>(1) structure instances are first-class values in most languages that offer structures. </div><div>Even in the context of C++ you can program as if you were dealing with structure</div><div>instances as values. </div>
<div><br></div><div>(2) structure type definitions, such as (struct posn (x y)) are pieces of syntax, so </div><div>using the terminology 'first-class' with them is inappropriate. The very idea of </div><div>first-class value means something that a program can deal with at run-time </div>
<div>w/o (m)any restrictions. [You can also define 'first-class' with respect to other </div><div>times when programs compute. Even then I have difficulties calling a definition</div><div>a first-class object.] </div>
<div><br></div><div>The next part of your question is whether we should have inheritance (everything </div><div>is a struct) and whether we should expose it in the teaching languages. The former</div><div>is a design decision that I have rarely exploited; my hunch is that a programmer </div>
<div>can live without it and that a meta-/tool-programmer needs it. The latter is a </div><div>flaw that we could probably fix easily now. </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><br><div><div><div class="h5"><div>On Mar 13, 2014, at 6:30 AM, Yi D wrote:</div><br></div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr"><div><p style="margin:1.2em 0px!important">Hi,</p><p style="margin:1.2em 0px!important">The documentation says that <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">struct</code> creates structures that are treated as first-class<br>
values. I can see the motivation for pursuing expressiveness. So what do we achieve<br>using first-class structures? On the down side, I see some problems. For example, in<br>the Beginning Student language, a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">posn</code> is both a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">posn?</code> and a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">struct?</code>.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,255);background-repeat:initial initial">> (posn? (make-posn 1 2))
#t
> (struct? (make-posn 1 2))
#t
</code></pre><p style="margin:1.2em 0px!important">I guess this is because <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">posn</code> is declared to be <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">#:transparent</code>.</p>
<p style="margin:1.2em 0px!important">In my opinion, exposing the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">struct?</code> nature of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">posn</code> undermines abstraction and breaks<br>
encapsulation. But without declaring it <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">#:transparent</code>, the printer could not echo<br>
informative response. It seems to me the two aspects: exposing the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">struct?</code> nature and<br>
informative result are unnecessarily tangled. If they can be separated, we may be able<br>to give informative result and at the same time not to expose the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">struct?</code> nature of<br>
structure types.</p><p style="margin:1.2em 0px!important">Best,</p><p style="margin:1.2em 0px!important">Yi</p>
</div></div></div></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br></blockquote></div><br></div><br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>