Hi Romain; David and the list
Le 16/06/2011 18:07, Romain Beauxis a écrit :
> Howdy all!
>
> I agree 100% with david. I would like to give a complement to his nice
> remarks :)
>
> In functional languages, there is an important different between
> "mutable" and "immutable" variables.
> mutable variables are variables that can be modified in place while
> immutable variables cannot be modified (they are static)
>
> Most of the usual languages, such as C, php, etc. have mutable
> variables by default. For instance, the following code (which will not
> work in liquidsoap):
> -----
> x = 2
>
> if (some condition) then
> x = 3
>
> # This prints: x value is 3
> print("x value is #{x}")
> -----
> In this code, x is mutable and its value is changed in-place inside
> the conditional call.
>
> On the contrary, immutable variables cannot be modified. In C, this
> could be though as a const type declaration for instance.
>
> In functional languages most variables are immutable. Thus, in order
> to change the value of x, the above code would rewrite as:
> -----
> x = 2
>
> x =
> if (some condition) then
> 3
> else
> x
> fi
>
> # This prints x value is 3
> print("x value is #{x}")
> -----
>
> In this case, since x cannot be modified in-place, its value is
> changed by redefining a new x with the updated value.
>
Okay, I understand mutable / immutable aspect, with "x".
btw, I don't want to "change" out, I want to "update" it. This is my
understanding of how partial out() works and maybe this is what I don't
understand.
> 2011/6/16 David Baelde<[email protected]>:
>>
>> # initial def
>> out = output.icecast(...)
>> # new definition
>> out = (if ... then out(%mp3) else ... end)
>> # at this point out may actually be out(%mp3)
>> # so it only expects a source now
>>
>> The important point is to write the if-then-else inside the second
>> definition, and not the other way around. This may seem unusual, but
>> the key is to realize that if-then-else is an expression constructor
>> like another. This is unlike in language like C/Java/Python/etc where
>> if-then-else only forms statements/instructions (something like x :=
>> 1, print(x)) but not expressions (something like x+1, x<=3, etc). In
>> fact, everything is an expression in liquidsoap (and more generally in
>> functional languages).
I Tried the following non-working code, but I am not sure how to
"write the if-then-else inside the second definition, and not the other
way around."
Is there a parenthesis / indent trick ?
# initial def with some properties
out = output.icecast(...)
# new def
out =
if stream_format == "mp3"
then
out(%mp3)
else
# I will write something else when I get the existing
to work :D
print ("not mp3")
end
# out should now expect the source
Now... Even if it works and if I have a "new" out with format inside
expecting the source, what becomes by first partial out def properties ?
Thanks !!
------------------------------------------------------------------------------
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