Dynamic variable assignment by recursion or loop?

Papa Tana papa.tana101@REDACTED
Fri Jul 3 14:31:53 CEST 2020


@Hugo:
 I wanted to escape binary initially and that's why I converted my
Input as a List, and  worked with List and Tuple, but after many many
fastidious lines with no valuable  result, I gave up.

@Fernando:

  You did it with ONLY ONE SINGLE LINE with your Binary comprehensions.
  I still have definitely a lot to learn!!
  Thanks a ton.

Really appreciated,


2020-07-03 12:56 UTC+03:00, Fernando Benavides <elbrujohalcon@REDACTED>:
> 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>
>


More information about the erlang-questions mailing list