<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">Konrad,</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Check out some of the functional data structures found here:</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><a href="http://www.ccs.neu.edu/racket/pubs/sfp10-kth.pdf" target="_blank" style="font-family:arial,sans-serif;font-size:13px">http://www.ccs.neu.edu/racket/pubs/sfp10-kth.pdf</a><br style="font-family:arial,sans-serif;font-size:13px">
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">VLists may be of particular interest in your case.</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Sep 4, 2013 at 2:37 PM,  <span dir="ltr">&lt;<a href="mailto:users-request@racket-lang.org" target="_blank">users-request@racket-lang.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Send users mailing list submissions to<br>
        <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.racket-lang.org/users/listinfo" target="_blank">http://lists.racket-lang.org/users/listinfo</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:users-request@racket-lang.org">users-request@racket-lang.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:users-owner@racket-lang.org">users-owner@racket-lang.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of users digest...&quot;<br>
<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>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: Immutable vectors (Neil Toronto)<br>
   2. Macro design question: best way to interpret an expression<br>
      multiple ways (Neil Toronto)<br>
   3. Re: Introductory talk on Contracts and Functional Contracts,<br>
      with most examples in Racket (Daniel Prager)<br>
   4. Re: Introductory talk on Contracts and Functional Contracts,<br>
      with most examples in Racket (Robby Findler)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Wed, 04 Sep 2013 14:56:27 -0600<br>
From: Neil Toronto &lt;<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>&gt;<br>
To: <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
Subject: Re: [racket] Immutable vectors<br>
Message-ID: &lt;<a href="mailto:52279E7B.5050406@gmail.com">52279E7B.5050406@gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
On 09/04/2013 10:28 AM, Konrad Hinsen wrote:<br>
&gt; For the kind of data I am working with, immutable vectors look like<br>
&gt; just the right choice: immutable and O(1) element access. However, I<br>
&gt; am discovering that they are a real pain to work with.<br>
&gt;<br>
&gt; Pretty much any vector operation returns a mutable vector: vector-map,<br>
&gt; vector-drop, vector-split-at, etc. I have to use<br>
&gt; vector-&gt;immutable-vector afterwards to get what I want.  That&#39;s a lot<br>
&gt; of code clutter, and a lot of unnecessary object generation.<br>
&gt; Getting data from a stream into an immutable vector is the worst: it<br>
&gt; requires two intermediates: sequence-&gt;list, list-&gt;vector,<br>
&gt; vector-&gt;immutable-vector.<br>
&gt;<br>
&gt; So I am beginning to wonder if immutable vectors are some obsolete<br>
&gt; feature that is being discouraged. Is there a better choice for an<br>
&gt; immutable sequence with O(1) element access?<br>
<br>
Racket&#39;s language design philosophy encourages immutability, so I don&#39;t<br>
see them going away any time soon. Immutable vectors is one area the<br>
standard library doesn&#39;t (currently) meet its design goals, IMO.<br>
<br>
FWIW, `vector-&gt;immutable-vector&#39; is pretty fast. It&#39;s usually the least<br>
significant part of an O(n) operation. Its two biggest problems are that<br>
it allocates memory and annoys people.<br>
<br>
If you&#39;re working in Typed Racket, you might consider using the<br>
`math/array&#39; library. It provides multidimensional arrays with O(1)<br>
access, a lot of ways to slice and dice them, and less memory allocation<br>
(especially if you use nonstrict arrays). They&#39;re not necessarily faster<br>
than vectors, though. Strict immutable arrays are backed by a mutable<br>
vector, so they allow element access only via a getter, which introduces<br>
an extra function call.<br>
<br>
If you&#39;re not in Typed Racket, don&#39;t use `math/array&#39; because the<br>
contract barrier makes element access very slow. But you might be able<br>
to do something similar: have library functions operate on mutable<br>
vectors, with user-facing functions accepting and receiving immutable<br>
vectors, or some more abstract wrapper data type. The `math/matrix&#39;<br>
library does this, and it works out well enough. A lot of matrix<br>
operations are fastest when done in-place (e.g. Gaussian elimination),<br>
but *composing* matrix operations is easiest to reason about when<br>
matrices are immutable. Many matrix functions copy their arguments&#39;<br>
elements to a vector, operate destructively on it, and return the result<br>
wrapped in an array.<br>
<br>
Neil ?<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Wed, 04 Sep 2013 15:31:23 -0600<br>
From: Neil Toronto &lt;<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>&gt;<br>
To: <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
Subject: [racket] Macro design question: best way to interpret an<br>
        expression multiple ways<br>
Message-ID: &lt;<a href="mailto:5227A6AB.4080502@gmail.com">5227A6AB.4080502@gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
I have two libraries of combinators meant to be used as targets for a<br>
language semantics. I&#39;m implementing the semantics using macros; e.g.<br>
<br>
    #&#39;(interp (+ 4 5))  =&gt;  #&#39;(((const 4) . &amp;&amp;&amp; . (const 5)) . &gt;&gt;&gt; . add)<br>
<br>
where `interp&#39; is a macro and `=&gt;&#39; means macro expansion.<br>
<br>
Here&#39;s the tricky part. I have to interpret the language using *both*<br>
combinator libraries, not just one; e.g. I need #&#39;(interp (+ 4 5)) to<br>
expand to both of these:<br>
<br>
   #&#39;(((const/bot 4) . &amp;&amp;&amp;/bot . (const/bot 5)) . &gt;&gt;&gt;/bot . add/bot)<br>
   #&#39;(((const/pre 4) . &amp;&amp;&amp;/pre . (const/pre 5)) . &gt;&gt;&gt;/pre . add/pre)<br>
<br>
I could have #&#39;(interp (+ 4 5)) expand to something like<br>
<br>
   #&#39;(list (interp/bot (+ 4 5)) (interp/pre (+ 4 5)))<br>
<br>
But expanding twice is terrible manners when the expression contains macros.<br>
<br>
(Originally, I had super-combinators that did the job of both */bot and<br>
*/pre combinators. These super-combinators were complicated and messy,<br>
especially when used in recursion, which is why I&#39;m moving the<br>
&quot;interpret the language two ways&quot; job into the macro system and hoping<br>
it&#39;s nicer. It should also generate faster code, and possibly allow type<br>
checking on one of the interpretations.)<br>
<br>
The best idea I&#39;ve had so far is to have (interp e) expand to uses of<br>
generic `&amp;&amp;&amp;&#39; and `&gt;&gt;&gt;&#39; combinators, apply `local-expand&#39;, and do a<br>
syntax tree search-and-replace that does #&#39;&amp;&amp;&amp; =&gt; #&#39;&amp;&amp;&amp;/bot, etc. Is<br>
there another way, though, that doesn&#39;t run afoul of macro security?<br>
<br>
Neil ?<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Thu, 5 Sep 2013 07:33:10 +1000<br>
From: Daniel Prager &lt;<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>&gt;<br>
To: Matthias Felleisen &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt;<br>
Cc: <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
Subject: Re: [racket] Introductory talk on Contracts and Functional<br>
        Contracts, with most examples in Racket<br>
Message-ID:<br>
        &lt;CAFKxZVVrzzaw87QhkxAN9WjS22hoTV06-dhsg=<a href="mailto:GSe%2BZ_dV0zmA@mail.gmail.com">GSe+Z_dV0zmA@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-7&quot;<br>
<br>
On Wed, Sep 4, 2013 at 7:58 AM, Matthias Felleisen &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt;<br>
 wrote:<br>
<br>
You can&#39;t.  Sam has had this combination on his todo list for 7 years and<br>
&gt; he never got around to it. Perhaps I signed his dissertation too early :-)<br>
<br>
<br>
I noticed that contract support is missing from TR.  I have, however,<br>
constructed a roll-my-own contract example with TR, and it would be great<br>
if Sam (or another!) pushed forward on contract support for TR.<br>
<br>
This is from my code base. It is a function that consumes the dimensions of<br>
&gt; a (functional image) canvas and created a gridded image and an event<br>
&gt; handler that tells you on which &quot;tile&quot; a user clicked. It is highly real,<br>
&gt; higher-order, dependent, and yet not difficult to understand.<br>
<br>
<br>
Alas, I am having trouble mentally parsing this, but may still flash it up<br>
(with acknowledgement!) as a realistic example.<br>
<br>
In trying to construct a simpler (yet not easily do-able with static types)<br>
example I&#39;m running into trouble getting my subcontract right.<br>
<br>
I get an &quot;n unbound identifier&quot; error on the penultimate line:<br>
<br>
;; make-indenter: Nat -&gt; (String -&gt; String)<br>
;;<br>
;; Example: ((make-indenter 4) &quot;foo&quot;) -&gt; &quot;    foo&quot;<br>
;;<br>
(define/contract (make-indenter n)<br>
  (-&gt;i ([n natural-number/c])<br>
       [r (-&gt;i ([s string?])<br>
               [result string?]<br>
               #:post (s result) (= (string-length result)<br>
                                    (+ n (string-length s))))])<br>
  (? (s) (string-append (make-string n #\space) s)))<br>
<br>
<br>
How should I access &#39;n&#39;?<br>
<br>
<br>
Many thanks<br>
<br>
Dan<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://lists.racket-lang.org/users/archive/attachments/20130905/37e9e432/attachment-0001.html" target="_blank">http://lists.racket-lang.org/users/archive/attachments/20130905/37e9e432/attachment-0001.html</a>&gt;<br>

<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 4 Sep 2013 16:37:09 -0500<br>
From: Robby Findler &lt;<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>&gt;<br>
To: Daniel Prager &lt;<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>&gt;<br>
Cc: Racket Users &lt;<a href="mailto:users@racket-lang.org">users@racket-lang.org</a>&gt;,       Matthias Felleisen<br>
        &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt;<br>
Subject: Re: [racket] Introductory talk on Contracts and Functional<br>
        Contracts, with most examples in Racket<br>
Message-ID:<br>
        &lt;<a href="mailto:CAL3TdOMETDN4xxymcpxaC5RxJ6oM0M_14-QN-%2BtSpOD_uNuZzQ@mail.gmail.com">CAL3TdOMETDN4xxymcpxaC5RxJ6oM0M_14-QN-+tSpOD_uNuZzQ@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;utf-8&quot;<br>
<br>
You need to indicate that the contract on &#39;r&#39; needs &#39;n&#39;, ie replace &quot;[r<br>
(-&gt;i&quot;  with &quot;[r (n) (-&gt;i&quot;.<br>
<br>
Robby<br>
<br>
<br>
On Wed, Sep 4, 2013 at 4:33 PM, Daniel Prager &lt;<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>&gt;wrote:<br>
<br>
&gt; On Wed, Sep 4, 2013 at 7:58 AM, Matthias Felleisen &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt;<br>
&gt;  wrote:<br>
&gt;<br>
&gt; You can&#39;t.  Sam has had this combination on his todo list for 7 years and<br>
&gt;&gt; he never got around to it. Perhaps I signed his dissertation too early :-)<br>
&gt;<br>
&gt;<br>
&gt; I noticed that contract support is missing from TR.  I have, however,<br>
&gt; constructed a roll-my-own contract example with TR, and it would be great<br>
&gt; if Sam (or another!) pushed forward on contract support for TR.<br>
&gt;<br>
&gt; This is from my code base. It is a function that consumes the dimensions<br>
&gt;&gt; of a (functional image) canvas and created a gridded image and an event<br>
&gt;&gt; handler that tells you on which &quot;tile&quot; a user clicked. It is highly real,<br>
&gt;&gt; higher-order, dependent, and yet not difficult to understand.<br>
&gt;<br>
&gt;<br>
&gt; Alas, I am having trouble mentally parsing this, but may still flash it up<br>
&gt; (with acknowledgement!) as a realistic example.<br>
&gt;<br>
&gt; In trying to construct a simpler (yet not easily do-able with static<br>
&gt; types) example I&#39;m running into trouble getting my subcontract right.<br>
&gt;<br>
&gt; I get an &quot;n unbound identifier&quot; error on the penultimate line:<br>
&gt;<br>
&gt; ;; make-indenter: Nat -&gt; (String -&gt; String)<br>
&gt; ;;<br>
&gt; ;; Example: ((make-indenter 4) &quot;foo&quot;) -&gt; &quot;    foo&quot;<br>
&gt; ;;<br>
&gt; (define/contract (make-indenter n)<br>
&gt;   (-&gt;i ([n natural-number/c])<br>
&gt;        [r (-&gt;i ([s string?])<br>
&gt;                [result string?]<br>
&gt;                #:post (s result) (= (string-length result)<br>
&gt;                                     (+ n (string-length s))))])<br>
&gt;    (? (s) (string-append (make-string n #\space) s)))<br>
&gt;<br>
&gt;<br>
&gt; How should I access &#39;n&#39;?<br>
&gt;<br>
&gt;<br>
&gt; Many thanks<br>
&gt;<br>
&gt; Dan<br>
&gt;<br>
&gt; ____________________<br>
&gt;   Racket Users list:<br>
&gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;<br>
&gt;<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://lists.racket-lang.org/users/archive/attachments/20130904/630811d2/attachment.html" target="_blank">http://lists.racket-lang.org/users/archive/attachments/20130904/630811d2/attachment.html</a>&gt;<br>

<br>
End of users Digest, Vol 97, Issue 12<br>
*************************************<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Talk to you soon,<br><br>Scott Klarenbach<br><br>PointyHat Software Corp.<br><a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>p 604-568-4280<br>
e <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a><br><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">200-1575 W. Georgia</span><br>
Vancouver, BC <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">V6G2V3</span><br><br>_______________________________________<br>To iterate is human; to recur, divine
</div></div>