<div dir="ltr"><div>Check out some of the functional data structures found here:</div><div><br></div><a href="http://www.ccs.neu.edu/racket/pubs/sfp10-kth.pdf">http://www.ccs.neu.edu/racket/pubs/sfp10-kth.pdf</a><br><div><br>
</div><div>VLists may be of particular interest in your case.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 2:37 PM, <span dir="ltr"><<a href="mailto:users-request@racket-lang.org" target="_blank">users-request@racket-lang.org</a>></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 'help' 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 "Re: Contents of users digest..."<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'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 <<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>><br>
To: <a href="mailto:users@racket-lang.org">users@racket-lang.org</a><br>
Subject: Re: [racket] Immutable vectors<br>
Message-ID: <<a href="mailto:52279E7B.5050406@gmail.com">52279E7B.5050406@gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
On 09/04/2013 10:28 AM, Konrad Hinsen wrote:<br>
> For the kind of data I am working with, immutable vectors look like<br>
> just the right choice: immutable and O(1) element access. However, I<br>
> am discovering that they are a real pain to work with.<br>
><br>
> Pretty much any vector operation returns a mutable vector: vector-map,<br>
> vector-drop, vector-split-at, etc. I have to use<br>
> vector->immutable-vector afterwards to get what I want. That's a lot<br>
> of code clutter, and a lot of unnecessary object generation.<br>
> Getting data from a stream into an immutable vector is the worst: it<br>
> requires two intermediates: sequence->list, list->vector,<br>
> vector->immutable-vector.<br>
><br>
> So I am beginning to wonder if immutable vectors are some obsolete<br>
> feature that is being discouraged. Is there a better choice for an<br>
> immutable sequence with O(1) element access?<br>
<br>
Racket's language design philosophy encourages immutability, so I don't<br>
see them going away any time soon. Immutable vectors is one area the<br>
standard library doesn't (currently) meet its design goals, IMO.<br>
<br>
FWIW, `vector->immutable-vector' is pretty fast. It'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're working in Typed Racket, you might consider using the<br>
`math/array' 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'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're not in Typed Racket, don't use `math/array' 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'<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'<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 <<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>><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: <<a href="mailto:5227A6AB.4080502@gmail.com">5227A6AB.4080502@gmail.com</a>><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'm implementing the semantics using macros; e.g.<br>
<br>
#'(interp (+ 4 5)) => #'(((const 4) . &&& . (const 5)) . >>> . add)<br>
<br>
where `interp' is a macro and `=>' means macro expansion.<br>
<br>
Here's the tricky part. I have to interpret the language using *both*<br>
combinator libraries, not just one; e.g. I need #'(interp (+ 4 5)) to<br>
expand to both of these:<br>
<br>
#'(((const/bot 4) . &&&/bot . (const/bot 5)) . >>>/bot . add/bot)<br>
#'(((const/pre 4) . &&&/pre . (const/pre 5)) . >>>/pre . add/pre)<br>
<br>
I could have #'(interp (+ 4 5)) expand to something like<br>
<br>
#'(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'm moving the<br>
"interpret the language two ways" job into the macro system and hoping<br>
it'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've had so far is to have (interp e) expand to uses of<br>
generic `&&&' and `>>>' combinators, apply `local-expand', and do a<br>
syntax tree search-and-replace that does #'&&& => #'&&&/bot, etc. Is<br>
there another way, though, that doesn'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 <<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>><br>
To: Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>><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>
<CAFKxZVVrzzaw87QhkxAN9WjS22hoTV06-dhsg=<a href="mailto:GSe%2BZ_dV0zmA@mail.gmail.com">GSe+Z_dV0zmA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-7"<br>
<br>
On Wed, Sep 4, 2013 at 7:58 AM, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>><br>
wrote:<br>
<br>
You can't. Sam has had this combination on his todo list for 7 years and<br>
> 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>
> a (functional image) canvas and created a gridded image and an event<br>
> handler that tells you on which "tile" a user clicked. It is highly real,<br>
> 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'm running into trouble getting my subcontract right.<br>
<br>
I get an "n unbound identifier" error on the penultimate line:<br>
<br>
;; make-indenter: Nat -> (String -> String)<br>
;;<br>
;; Example: ((make-indenter 4) "foo") -> " foo"<br>
;;<br>
(define/contract (make-indenter n)<br>
(->i ([n natural-number/c])<br>
[r (->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 'n'?<br>
<br>
<br>
Many thanks<br>
<br>
Dan<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<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>><br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Wed, 4 Sep 2013 16:37:09 -0500<br>
From: Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>><br>
To: Daniel Prager <<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>><br>
Cc: Racket Users <<a href="mailto:users@racket-lang.org">users@racket-lang.org</a>>, Matthias Felleisen<br>
<<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>><br>
Subject: Re: [racket] Introductory talk on Contracts and Functional<br>
Contracts, with most examples in Racket<br>
Message-ID:<br>
<<a href="mailto:CAL3TdOMETDN4xxymcpxaC5RxJ6oM0M_14-QN-%2BtSpOD_uNuZzQ@mail.gmail.com">CAL3TdOMETDN4xxymcpxaC5RxJ6oM0M_14-QN-+tSpOD_uNuZzQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
You need to indicate that the contract on 'r' needs 'n', ie replace "[r<br>
(->i" with "[r (n) (->i".<br>
<br>
Robby<br>
<br>
<br>
On Wed, Sep 4, 2013 at 4:33 PM, Daniel Prager <<a href="mailto:daniel.a.prager@gmail.com">daniel.a.prager@gmail.com</a>>wrote:<br>
<br>
> On Wed, Sep 4, 2013 at 7:58 AM, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>><br>
> wrote:<br>
><br>
> You can't. Sam has had this combination on his todo list for 7 years and<br>
>> 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<br>
>> of a (functional image) canvas and created a gridded image and an event<br>
>> handler that tells you on which "tile" a user clicked. It is highly real,<br>
>> 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<br>
> types) example I'm running into trouble getting my subcontract right.<br>
><br>
> I get an "n unbound identifier" error on the penultimate line:<br>
><br>
> ;; make-indenter: Nat -> (String -> String)<br>
> ;;<br>
> ;; Example: ((make-indenter 4) "foo") -> " foo"<br>
> ;;<br>
> (define/contract (make-indenter n)<br>
> (->i ([n natural-number/c])<br>
> [r (->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 'n'?<br>
><br>
><br>
> Many thanks<br>
><br>
> Dan<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>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<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>><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>