Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: block-to-object and reverse function
Pages: [1] Print
Author Topic: block-to-object and reverse function  (Read 586 times)
Philippe
Newbie
*
Offline Offline

Posts: 34


View Profile WWW
block-to-object and reverse function
« on: June 06, 2007, 06:03:56 PM »

Hello,

I search a way to "objectify" a block like :
blk: [ a none [b [ c 3 d [ e 5] ] ] ]

in :

obj-blk: make object! [
a: none
b: make object! [
  c: 3
  d: make object! [ e: 5]
 ]
]
]

with any embedded blocks transformed in an embedded object.


And the reverse function : blockify object (with any embedded objects or defs) in a block of embedded blocks.

any idea ?  Huh

thx,

===Philippe
Logged

===Philippe
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: block-to-object and reverse function
« Reply #1 on: June 07, 2007, 01:46:36 AM »

Code:
; modifies the passed block, use COPY/DEEP on it before
; passing it if you don't want it to be modified
block2obj: func [block] [
    parse block [
        some [
            block: word! skip (
                block/1: to set-word! block/1
                if block? block/2 [block/2: block2obj block/2]
            )
            |
            skip (make error! rejoin ["Expected word!, not " type? block/1 ": " mold/only copy/part block 3])
        ]
    ]
    construct head block
]

obj2block: func [object] [
    object: third object
    forskip object 2 [
        object/1: to word! object/1
        if object? object/2 [
            object/2: obj2block object/2
        ]
    ]
    object
]

HTH.
Logged
Philippe
Newbie
*
Offline Offline

Posts: 34


View Profile WWW
Re: block-to-object and reverse function
« Reply #2 on: June 07, 2007, 03:24:18 PM »

Thanks Gabriele, I will try it.
Where do you find some time to work to R3 alpha, make answsers here and discussions on altme ??  Wink

Thx, Philippe (first lunch Devcon2007, with Dockimbel)
Logged

===Philippe
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: block-to-object and reverse function
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 30, 2008, 07:00:02 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2235 Posts in 583 Topics by 1757 Members
Latest Member: Xzycdysz

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc