Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert set-words in a block to words

Tags:

rebol

rebol3

I want to convert a block from block: [ a: 1 b: 2 ] to [a 1 b 2]. Is there an easier way of than this?

map-each word block [ either set-word? word [ to-word word ] [ word ] ]

like image 290
johnk Avatar asked May 10 '13 05:05

johnk


2 Answers

Keeping it simple:

>> block: [a: 1 b: 2]
== [a: 1 b: 2]
>> forskip block 2 [block/1: to word! block/1]
== b
>> block
== [a 1 b 2]
like image 85
DocKimbel Avatar answered Sep 30 '22 09:09

DocKimbel


I had same problem so I wrote this function. Maybe there's some simpler solution I do not know of.

flat-body-of: function [
    "Change all set-words to words"
    object [object! map!]
][
    parse body: body-of object [
        any [
            change [set key set-word! (key: to word! key)] key 
            | skip
        ]
    ]
    body 
]
like image 25
rebolek Avatar answered Sep 30 '22 09:09

rebolek