manipulating values in blocks
[1/11] from: hugues::moisy::geosignal::fr at: 27-Nov-2002 20:06
Hi List,
I manage to manipulate a block like [1 17 23 36 49 58], representing limits off segments,
ie, if i have 6 values in the block, it seems that the block contains 5 segments (1-17,
17-23, 23-36 ...)
is there anyone who knows how to manipulate the block into getting start and end values
of each segment ? I've tried, but don't know how to do this job.
Thanks a lot for your help.
Hugues
[2/11] from: sunandadh:aol at: 27-Nov-2002 14:34
Hugues
> is there anyone who knows how to manipulate the block into getting start
and
> end values of each segment ? I've tried, but don't know how to do this job.
Apologies if this isn't what you mean.....
segment-limit: func [b [block!] s [integer!]] [
;; trap out-of-range errors
if any [s > length? b
s < 1 ][
return [none none]]
return reduce [b/:s pick b (s + 1)]
] ;; func
;; test driver for segment limit function
myblock1: [1 17 23 36 49 58]
for nn -1 (2 + length? myblock1) 1 [
print [nn segment-limit myblock1 nn]
]
Sunanda.
[3/11] from: joel:neely:fedex at: 27-Nov-2002 14:03
Hi, Hugues,
Here's one way, below...
Hugues Moisy wrote:
> Hi List,
>
> I manage to manipulate a block like [1 17 23 36 49 58], representing limits off segments,
ie, if i have 6 values in the block, it seems that the block contains 5 segments (1-17,
17-23, 23-36 ...)
>
> is there anyone who knows how to manipulate the block into getting start and end values
of each segment ? I've tried, but don't know how to do this job.
>
bounds-to-segs: func [b [block!] /local left result] [
result: make block! (length? b) - 1
left: first b
foreach right next b [
insert/only tail result reduce [left right]
left: right
]
result
]
... which behaves as ...
>> bounds-to-segs [1 17 23 36 49 58]
== [[1 17] [17 23] [23 36] [36 49] [49 58]]
... or can be used as ...
>> foreach seg bounds-to-segs [1 17 23 36 49 58] [
[ print head insert next copy seg "-"
[ ]
1 - 17
17 - 23
23 - 36
36 - 49
49 - 58
HTH!
-jn-
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446
[4/11] from: greggirwin:mindspring at: 27-Nov-2002 13:13
Hi Hugues,
HM> I manage to manipulate a block like [1 17 23 36 49 58],
HM> representing limits off segments, ie, if i have 6 values in the
HM> block, it seems that the block contains 5 segments (1-17, 17-23, 23-36 ...)
HM> is there anyone who knows how to manipulate the block into getting
HM> start and end values of each segment ? I've tried, but don't know
HM> how to do this job.
If I understand you correctly, you want to say "give me the start and
end values of segment 2" and receive 17 and 23 in response.
You could write functions to do this, like so:
>> b: [1 17 23 36 49 58]
== [1 17 23 36 49 58]
>> seg-start: func [block segment] [block/:segment]
>> seg-start b 3
== 23
>> seg-end: func [block segment] [pick block add 1 segment]
>> seg-end b 3
== 36
or you could extract a "segment" and then use that:
>> segment: func [block segment] [copy/part at block segment 2]
>> segment b 3
== [23 36]
and then use FIRST and LAST to get each value. You can also use these
techniques inline if that suits your needs better. Hmmm. You could
also "segmentize" your block if you wanted.
>> segmentize: func [block /local result][
[ result: make block! length? block
[ repeat i subtract length? block 1 [
[ append/only result copy/part at block i 2
[ ]
[ result
[ ]
>> segmentize b
== [[1 17] [17 23] [23 36] [36 49] [49 58]]
HTH!
-- Gregg
[5/11] from: anton:lexicon at: 28-Nov-2002 13:11
Try this:
blk: [1 17 23 36 49 58]
repeat n (subtract length? blk 1) [
print rejoin [blk/:n "-" pick blk (n + 1)]
]
Anton.
[6/11] from: lmecir:mbox:vol:cz at: 28-Nov-2002 8:44
Hi Hugues,
> > I manage to manipulate a block like [1 17 23 36 49 58],
> > representing limits off segments, ie, if i have 6 values in the
<<quoted lines omitted: 4>>
> > getting start and end values of each segment ? I've tried, but
> > don't know how to do this job.
the most natural way seems to be:
block: [1 17 23 36 49 58]
foreach [start end] block [
print [start " - " end]
]
is that what you wanted?
-L
[7/11] from: hugues:moisy:geosignal at: 28-Nov-2002 9:43
Hi all,
Thanks a lot for your responses.
it's a real preasure working with this language, and with such a list of
users. If all people would work like that ...
Hugues
[8/11] from: ronaldoff:free at: 28-Nov-2002 11:12
Hello Ladislav,
Thursday, November 28, 2002, 8:44:00 AM, you wrote:
LM> Hi Hugues,
>> > I manage to manipulate a block like [1 17 23 36 49 58],
>> > representing limits off segments, ie, if i have 6 values in the
<<quoted lines omitted: 4>>
>> > getting start and end values of each segment ? I've tried, but
>> > don't know how to do this job.
LM> the most natural way seems to be:
LM> block: [1 17 23 36 49 58]
LM> foreach [start end] block [
LM> print [start " - " end]
LM> ]
Try it with block: [1 17 23 36 49 58 66]
and you get
** Script Error: block has no value
** Where: do-boot
** Near: foreach [start end] block [
print [start " - " end]
]
Anton's script works anyway.
--
Best regards,
Ronald
[9/11] from: lmecir:mbox:vol:cz at: 28-Nov-2002 10:35
Hi Ronald,
you wrote:
> Try it with block: [1 17 23 36 49 58 66]
> and you get
<<quoted lines omitted: 3>>
> print [start " - " end]
> ]
, actually not. I get this:
1 - 17
23 - 36
49 - 58
66 - none
-L
[10/11] from: ronaldoff:free at: 28-Nov-2002 12:08
Hello Ladislav,
Thursday, November 28, 2002, 10:35:39 AM, you wrote:
LM> Hi Ronald,
LM> you wrote:
>> Try it with block: [1 17 23 36 49 58 66]
>>
<<quoted lines omitted: 5>>
>> print [start " - " end]
>> ]
LM> , actually not. I get this:
LM> 1 - 17
LM> 23 - 36
LM> 49 - 58
LM> 66 - none
LM> -L
All my apologizes, I don't know how I've got this error...
I just wanted to show that the script did'nt work the same manner as
Anton's : your's give one more start-end segment when block length is
unpair and the biggest difference, script outputs that isn't what
hugues was searching for...
Anton's script Your's
1-17 1 - 17
17-23 23 - 36
23-36 49 - 58
36-49 66 - none
49-58
58-66
Anyway, this ML is really fantastic and makes learn a lot every day.
Thanks to all of you.
--
Best regards, ronald
[11/11] from: hugues:moisy:geosignal at: 29-Nov-2002 11:12
Hello All, Thanks for all your responses.
I've found another way to solve my problem, thanks to you all
>> blk: [1 17 63 113 145]
== [1 17 63 113 145]
>>
>> for i 1 ((length? blk) - 1) 1 [
[ startseg: first blk
[ endseg: second blk
[ print [startseg endseg]
[ blk: next blk
[ ]
1 17
17 63
63 113
113 145
== [145]
>>
i'm a beginner in rebol, and rebol is amazing !
Hugues
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted