[chuck-users] how to mickey-mouse a 'switch' statement into chuck?

Forrest Curo treegestalt at gmail.com
Mon Oct 12 14:22:34 EDT 2015


It looks far prettier than a mess of logical spaghetti!

But is this documented with examples for the help & understanding of
object-challenged geezers from the days of punch-card boxes converted
twice/day to error-message listings?

On Mon, Oct 12, 2015 at 10:37 AM, Michael Heuer <heuermh at gmail.com> wrote:

> Forrest Curo <treegestalt at gmail.com> wrote
>
>> Since switches have so far not been included, is there a way around this?
>>
>> An array of Events?
>>
>> An array of functions, either numbered or associative? How to declare and
>> call such an array?
>>
>
> ChucK doesn't have function pointers or similar, so I've resorted to
> functors
>
> https://github.com/heuermh/lick/blob/master/lick/fn
>
> E.g.
>
> class DoSomething extends Procedure {
>   fun void run() { ... }
> }
> class DoSomethingElse extends Procedure {
>   fun void run() { ... }
> }
>
> DoSomething doSomething;
> DoSomethingElse doSomethingElse;
>
> ArrayList procedures;
> procedures.add(doSomething);
> procedures.add(doSomethingElse);
>
> while (true) {
>   procedures.sample() $ Procedure @=> Procedure procedure;
>   procedure.run();
>   1::second => now;
> }
>
>
> Yeah, it ain't pretty.
>
>    michael
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151012/838104f8/attachment.html>


More information about the chuck-users mailing list