A little thing about function templates / Ruby

mike vertex at gmx.at
Mon Feb 12 15:56:28 PST 2007


Am 12.02.2007, 22:35 Uhr, schrieb Christian Kamm <kamm at nospam.de>:

> In case you don't already know: depending on what channelStrip and  
> activeDevices are, using the foreach syntax might also be worth looking  
> into:
>
> foreach(device; &channelStrip.activeDevices)
>    device.processAudio(inBuffer, outBuffer);
>
> You can do this by making activeDevices a function that follows the  
> rules for opApply.
>
> Christian

Yeah, currently I've got it like that:

' foreach (device; channelStrip.devices)
' {
'     if (device is null) continue;
'     // do stuff
' }

If I can put the null check and different other checks (isActive,  
hasGuiWindow, isStereo, receivesMidi, etc.) in different templates and use  
the template I need together with the collection I want to access  
(inputChannel, sendChannel, etc.) all becomes much easier to work with. I  
think basically that's iterators anyway. I've finally groked what's so  
nice about them in Ruby :)

On a side note it's really interesting how working in Ruby can just  
destroy some of your habits/mental blocks from C/C++ land, in this case I  
started seeing that delegates are not only function pointers but a neat  
way to handle control flow. And that's why I'm currently toying around  
with them. Note to self: now it's time to finally learn Scheme! :)

-Mike

-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list