[Library] Automatic list create in PRPL

Started by kajacx, October 29, 2017, 08:09:09 AM

Previous topic - Next topic

kajacx

You know how painful is it to create a list with some values in it. You can do "a,b,c" "," Split but that only works with strings. CreateList ->list 1 2 3 <-list PrependStackToList doesn't work unless the stack is empty, and manually spamming <-list <-x AppendToList can be a lot of work.

Introducing the recursive list maker: Just put the values you want in the list on stack, with "[" for start of the list and "]" for end, and then call @MakeListRecursive. As the name suggest, it even handles recursive lists. Example:


    "["
        1 2 3 "["
            "[" "]"
            "abc" "xyz"
        "]"
    "]" @MakeListRecursive Trace
    # Result: [1,2,3,[[],abc,xyz]]


Note: this cannot add actuall "[" or "]" string into a list, since those are reserved for staring and ending the lists, and adding escaping would be way too much work. However you can easily modify the code to change it to "{}" or "<>" or anything you like, really.
Why do work yourself, when you can write a program that will do the work for you.