Hi Romain!

Thanks you very much for help! Yes, I have seen the difference. But thare
is some problem: if function returns not {true} or {false} but true or
false to a switch, liquidsoap
generate an error, like:

--------------------------------------
At line 27, char 73-109:
  this value has type
    ((()->_)*_)
  but it should be a subtype of (the type of the value at line 27, char
42-70)
    (bool*_)
--------------------------------------

I tried many variants:
nonstop = switch(track_sensitive=false, [(stop_after_current, nonstop),
({true}, blank(id="", duration=20.0))])
nonstop = switch(track_sensitive=false, [({stop_after_current}, nonstop),
({true}, blank(id="", duration=20.0))])
nonstop = switch(track_sensitive=false, [(stop_after_current(), nonstop),
({true}, blank(id="", duration=20.0))])

As I see, there are something wrong in ({true}, blank(id="",
duration=20.0)). But what? I wasn't do any changes
in this segment of code.

I'm sorry if I ask stupid questions, but I have very small experience in
functional programming, so please, don't kick me =)

I hope I have not take too much of your time.

Best regards,
Azat


2013/2/5 Romain Beauxis <[email protected]>

> Hi Azat!
>
> 2013/2/1 Azat Galiev <[email protected]>:
> > Thanks for answer!
> >
> > Here is full script:
> >
> > -------------------------------------------
> > #!/usr/bin/env liquidsoap
> >
> > set("init.daemon", true)
> > set("init.daemon.change_user", true)
> > set("init.daemon.change_user.user", "liquidsoap")
> > set("init.daemon.change_user.group", "liquidsoap")
> > set("server.telnet", true)
> >
> > def stop_after_current =
> >         raw_output = get_process_lines("./stop_after_current.py")
> >         stop = list.hd(raw_output)
> >         if stop == "true" then
> >                 {false}
> >         else
> >                 {true}
> >         end
> > end
>
> You're having a case of wrong functional scope here.. :-) Let me explain:
>
> {true} is a shortcut for the simply function fun () -> true, i.e. a
> function that takes no argument and always returns true.
>
> Now, in the code above, the body of your function is only executed
> once, at startup, and returns either {true} or {false}.
>
> This means that your switching function will be fixed and one of
> {true} or {false} during the execution of the script, which is not
> what you want to..
>
> Instead, you just need to change the scope of your function as follows:
>
> def stop_after_current() =
>         raw_output = get_process_lines("./stop_after_current.py")
>         stop = list.hd(raw_output)
>         if stop == "true" then
>                 false
>         else
>                 true
>         end
> end
>
> Do you see the difference?
>
> Hope this helps!
> Romain
>



-- 
С уважением, Азат Галиев
http://www.crazyradio.net/
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to