Dynamic variable assignment by recursion or loop?

Fernando Benavides elbrujohalcon@REDACTED
Fri Jul 3 11:56:29 CEST 2020


Or use binary comprehensions.
Something along the lines of this totally untested code…

<< << (length(Item)), (list_to_binary(Item))/binary >>  || Item <-
tuple_to_list(Input) >>.

On Fri, Jul 3, 2020 at 11:48 AM Hugo Mills <hugo@REDACTED> wrote:

> On Fri, Jul 03, 2020 at 10:43:22AM +0100, Hugo Mills wrote:
> >    There's a tuple_to_list/1 function. Use that to start with, and
> > then you can map over the list to generate a list of size/value
> > binaries, converting one at a time. Then finally fold over that list
> > to produce the final binary.
> >
> >    Alternatively, require the input to be a list in the first place,
> > and you can skip the tuple_to_list/1 part. (But the rest is still
> > necessary).
>
>    Sorry, just realised I should have added:
>
>    More fundamentally, work out how to do *one* thing (convert a
> string to a length+data binary), then use the list functions to
> map/filter/fold many of those into one result.
>
>    Occasionally, you'll have to write a recursive function directly,
> but it's rarer than you might think.
>
>    Hugo.
>
> --
> Hugo Mills             | Well, sir, the floor is yours. But remember, the
> hugo@REDACTED carfax.org.uk | roof is ours!
> http://carfax.org.uk/  |
> PGP: E2AB1DE4          |                                             The
> Goons
>


-- 
<https://about.me/elbrujohalcon?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>
Brujo Benavides
about.me/elbrujohalcon
<https://about.me/elbrujohalcon?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200703/dad95a82/attachment.htm>


More information about the erlang-questions mailing list