[racket] Take an element from a set

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Thu Sep 8 17:27:24 EDT 2011

Thanks for the answer!

For now I can go with just having "first", and if needed go for a one/rest
approach.

I couldn't find more efficient ways to take "one" though, and with your
comment I'm confident to use it as it is now.

[]'s

Rodolfo Carvalho


On Thu, Sep 8, 2011 at 00:36, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:

> This looks like a reasonable way to get an element, but thinking
> ahead, you will probably want something both like "first" (which you
> have) and a corresponding "rest".
>
> The problem is that which element you get from the "first" operation
> is nondetermistic in a set.  Therefore, you have to either
>
> - pass the returned first element to the rest operation, or
>
> - accept that
>  (set-union (set (set-item S)) (set-rest S))
>  is not the same as S
>
> A better design would be to use a different signature:
>
>  get-one/rest : (forall (A) (Set A) -> (values A (Set A)))
>
> This performs the split "atomically", so it can ensure that the
> combination of "one" and "rest" is the same as the original set.
>
> Shriram
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110908/d68020dc/attachment.html>

Posted on the users mailing list.