Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Block manipulation: help!

From: mat:plothatching at: 13-Jun-2002 14:05

Hello folks, Here's another newbish type question. I've never really gotten my head around block/series manipulation in Rebol. As a result of this my code is full of silly hacks that keep building temporary data structures to get the results I want. I was hoping that someone may help my cog drop into place so I can write some decent Rebol at last. Here's a typical problem; Let's say we have a file which is full of cars and the colours they are available in; Saloon "Red" Coupe "Red" Coupe "Yellow" Pickup Truck "Red" Pickup Truck "Yellow" Pickup Truck "Orange" Pickup Truck "Blue" Now what if I want to scan through this file and build up a list of cars but then just state which colours they are available in after in the structure. I'll assuming an elegant format is this; FinalData: make block! [ "Saloon" ["Red"] "Coupe" ["Red" "Yellow"] "Pickup Truck" ["Red" "Yellow" "Orange" "Blue"] ] So, reading the file is easy enough. CarLines: read/lines %file foreach CarLine CarLines [ Car: pick (parse CarLine none) 1 Colour: pick (parse CarLine none) 2 ; ; ??? ; ] The question is, how do I create final data? I can do a find on the FinalData to see if a car is there already. But all this does is return the data after. I've always been puzzled about the lack of a word/function to return the position in a series/block of a find, if found. So anyhow, here's the best I can think of; either found? find FinalData Car [ ; Already have an entry for this car... ; Select at least allows retrieving of the block following our ; found element easily... ; existingcolours: select FinalData Car ; ; Great so add the new colour to the existing colours ; append existingcards Car ; ; But how do we poke it back? We don't have a position to do a poke? ; ???? ][ ; ; Plug in the new car, plug in the block which has the colour in it ; append FinalData Car append FinalData reduce[reduce[Colour]] ] I don't really understand the block navigation issues to solve this problem or to somehow poke more data in without having a position. As usual any stupid stuff I've missed and elegant solutions gratefully received. Regards, Mat Bettinson