Thanks for your advice. This is why I made the code public ---
to get specific advice on how to improve.
I didn't take your advice in regard to this one however:
: show-vote ( codes -- )
[ ballot get nth . ] each ;
I think show-vote has to stay as it is. Your suggestions just print out all
of the elements in the ballot sequence. What I have is a sequence of numbers
(called codes). These numbers are indices into ballot. I only want to print
out those elements in ballot that are specified by the indices in codes.
This prints out the subset of the ballot that the voter selected rather than
the entire ballot.
Also, I didn't understand what you meant regarding with-scope. My
understanding is that with-scope allows a function to modify its own version
of a symbol, without modifying the global version of that symbol. In order
to reduce namespace clutter however, I would want to use <PRIVATE and
PRIVATE> rather than with-scope. Is this correct?
I have a new version of votsim available. I realized that plurality,
approval and borda are actually all the same. They can be implemented with
identical code, but each use a different sequence of point values.
Plurality is { 1 0 0 0 0 0 0 0 }
Approval is { 1 1 1 1 1 1 1 1 }
Borda is { 7 6 5 4 3 2 1 0 } (given eight candidates)
{ 3 2 1 0 0 0 0 0 } (given four candidates)
Double is { 128 64 32 16 8 4 2 1 } (my own invention)
Where all of this is going is that I will develop a user-interface that
allows the user to implement whatever point values he wants; he can go with
one of the famous systems (plurality, approval or borda) or invent one of
his own. He can also adjust the number of votes for the various candidate
configurations and see an immediate change in the results.
I hope to make this available to H.S. social-studies classes. Voting systems
weren't taught when I was in H.S., and I don't think they are taught today
either. Everybody just assumes that plurality voting is the end-all of
voting. People get trapped in this dichotomy of liberal/neo-con and they
fail
to see the big picture. This dichotomy didn't even exist at the time that
America was founded, and now people believe that it completely defines
politics.
BTW, I got a couple of Donald Saari's books on voting and am reading them.
Thanks for the suggestion, Justin DeVries. These books are more readable
than Brams' book. Also, Brams is promoting approval voting, and Saari is not
promoting any particular system; his book is more well-rounded.
> Message: 2
> Date: Mon, 8 Jun 2009 02:40:51 -0500
> From: Slava Pestov <[email protected]>
> Subject: Re: [Factor-talk] voting simulation
> To: [email protected]
> Message-ID:
> <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Hugh,
>
> I have some suggestions for your code.
>
> This,
>
> { } swap [ candidate? suffix ] each
>
> this could be written using map instead, ie
>
> [ candidate? ] map
>
> And this,
>
> [ ballot get nth . ] each
>
> can be simplified to
>
> ballot get [ . ] each
>
> or
>
> ballot get stack.
>
> Finally,
>
> [ count>> + ] each
>
> Can be written using the sigma combinator:
>
> [ count>> ] sigma
>
> One more piece of advice: you might want to wrap your top-level
> word(s) in a with-scope, so that the temporary dynamic variables you
> use with get/set don't clutter the namespace of the caller.
>
> Slava
>
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk