Hi polemon,
You guessed the problem, the global variable is more of a global
constant in your script. Liquidsoap is a purely functional scripting
language. Citing its documentation
(http://savonet.sourceforge.net/doc-0.9.0/language.html):
<<
No assignation, only definitions.
x = expr doesn't modify x, it just defines a new x. The expression (x
= s1 ; def y = x = s2 ; (x,s3) end ; (y,x)) evaluates to
((s2,s3),s1)."
>>
Liquidsoap is implemented in OCaml but liquidsoap's script language is
not OCaml. It's a much simpler language with a different syntax. And
currently no references.
Now, the solution. You need to convert a list of pairs (key,value)
into a string. First, we need to convert the pairs:
def pair2string(pair)
"#{fst(pair)}=#{snd(pair)}"
end
Using iter(), you can write separately the results of pair2string, but
you can't progressively build a string, passing the intermediate
string to the next step. We have list.fold() for that, but it's not
the simple solution here.
With list.map(), you can apply a transformation to each element of a
list. So, string.map(pair2string, metadata) is the list of
representations of (key,value) bindings. Now we just need to
concatenate this, we can even insert newlines:
string.concat(separator="\n", string.map(pair2string,metadata)) and
you're done!
I know that it's a new way of thinking for many people. But you'll get
used to it. And it makes our life simpler building a solid tool.
> Oh, and if you were to say just to use string_of(mdata), that doesn't quite
> work.
> My metadata contains UTF-8 characters, that get mingled by string_of() into
> things like "\194\184" (the actual byte representation of the character).
I'm afraid this might still be a problem even without string_of()...
Please confirm and we'll look more into that.
Cheers,
--
David
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users