Hi Martin! 2011/6/15 Martin Hamant <[email protected]>: > Le 15/06/2011 10:48, David Baelde a écrit : >> >> Hi Martin, >> >> Using your terminology to clarify, you could write: >> >> On Wed, Jun 15, 2011 at 10:37 AM, Martin Hamant<[email protected]> wrote: >>> >>> out = output.icecast( >>> fallible=true, >>> start=false >>> ) >> >> out = >>> >>> if stream_format == "mp3" then >>> out(%mp3) >>> end >> >> # here you also need the else branch to say what out becomes if >> stream_format != "mp3". > > Yes, as I am using mp3 for testing purpose, I haven't wrote further. > > >> Perhaps one way to clarify things is to avoid calling "outputs" a >> "global variable" that is "initialized". A definition has only one >> value over the course of its life, it never changes. You may hide it >> in some part of the script with another definition, but this is really >> different: >> x = 1 >> if true then >> x = 2 >> # here x is 2 >> print(x) >> end >> # x is 1 again >> print(x) >> # in the if-then-block, you could as well replace all occurrences of "x" >> by "y" >> >> Your "dyn_sources" is closer to what is usually called a (global) >> variable. It has an initial value (dyn_source = ref<initial value>) >> but its value can change over time (dyn_source :=<new value>). >> >> I know these differences can be confusing. I hope that my explanations >> help you see the difference, which should be useful when writing >> scripts. >> > Gasp this is very hard to me. I understand the life of x in the little snip > you provided. > I think the confusing is about the partial construction. > here, we speak about a definition "out = icecast.output()", that gives a > function out() which is precisely designed to deffer some parameters > definition. (isn't it ?). Which is called "partial application". > > I am sorry, you are certainly going to repeat yourself :( > > Here is the full first part of my script, I have annotated examples which > works and some don't: > > ========== > # First, we create a list referencing the dynamic sources: > dyn_sources = ref [] > > # This is our icecast output. > # It is a partial application: the source needs to be given! > out = output.icecast( > fallible=true, > start=false > ) > > # Now we write a function to create > # a playlist source and output it. > def create_playlist(uri) = > # The playlist source > > param = string.split(separator="\|",uri) > source_device = list.nth(param,0) > stream_host = list.nth(param,1) > stream_port = list.nth(param,2) > stream_password = list.nth(param,3) > stream_id = list.nth(param,4) > stream_genre = list.nth(param,5) > stream_url = list.nth(param,6) > stream_description = list.nth(param,7) > #stream_format = list.nth(param,8) > > s = input.alsa(device="#{source_device}") > > # metadata telnet handler > s = server.insert_metadata(id="#{stream_id}-meta", s) > > > > # the following doesn't work. > # for testing purpose > #stream_format = "mp3" > > #out = > #if stream_format == "mp3" then > # out(%mp3) > #end > > # the following works but hey why ? > > out = > out(%mp3) > > #The following don't work > > #out(%mp3)
I think you can try to see this in terms of types. Here's a simplified presentation. At first: out = output.icecast() will be of type format -> source -> source, i.e. its a partial application which needs at least a format and a source. Then you do: out = output.icecast(%mp3) Now out is of type source -> source, i.e. you have applied one more argument, thus the type has changed. But if you do: out(%mp3) Then the variable out is still of type format -> source -> source because the above was not kept.. Thus, if later you want to do: out(source) Then this will only work if out is of type source -> source, i.e. in the first case above.. Romain ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Savonet-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/savonet-users
