[REBOL] Re: Building an Associate List from a string
From: tomc:darkwing:uoregon at: 20-Oct-2003 23:24
On Mon, 20 Oct 2003, Tim Johnson wrote:
> Hello REBOLS:
> I need some advice :-)
> I've written a function that converts a delimited string into
> an associative list.
> Code and example console session is below:
> ;; > make-al: function[ {Builds an associative list from a delimited string}
> str[string!] {delimited string}
> /with delimiter[string! char!] {custom delimiter (TAB is default)}
> /default _dval[any-type!] {custom default value (NONE is default)}
> ][tmp al-block sep dval][
> sep: either with[to-string delimiter][to-string TAB]
> dval: either default[_dval][none]
> al-block: copy []
> tmp: parse/all str sep
> if not even? length? tmp[append tmp dval]
> foreach [name value] tmp[
> append al-block to-word name
> append al-block value
> ]
> al-block
> ]
> test: "age^-54^-name^-Tim Johnson^-occuptation^-coder"
> probe make-al test
> ;; = Console session > == [age "54" name "Tim Johnson" occuptation "coder"]
> ;; Now, so far it is a piece of cake, but this is where
> ;; I falter:
> I would like to employ a strategy that converts any value
> to the best guess for a rebol datatype. IOWS, "54"[string!]
> would become 54[integer!]
>
> It occurs to me that a brute-force method would be to process
> via a nested attempt[any[]] loop.
>
> Any more "elegant" ideas?
> thanks
> tim
> --
> Tim Johnson <[tim--johnsons-web--com]>
> http://www.alaska-internet-solutions.com
> --
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
could try
append al-block load value