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

[REBOL] Re: REBOL Enhancement Proposals (REPs)

From: joel:neely:fedex at: 26-Sep-2001 18:17

Hi, Ladislav and all, Ladislav Mecir wrote:
> Hi Andrew, > > they actually "have" such feature: > > b: make path! 3 > insert tail :b 'a > insert tail :b "a test" > insert/only tail :b first [(12 + i)] > :b ; == a/"a test"/(12 + i) > > :-) >
Well... One may be able to make a value of datatype PATH! with that "spelling", but it doesn't quite have the semantics one would hope/expect. ;-)
>> bb: make block! 10
== []
>> repeat i 10 [append bb i * i - i]
== [0 2 6 12 20 30 42 56 72 90]
>> bp: make path! 2
==
>> append :bp 'bb
== bb
>> i: 0
== 0
>> insert/only tail :bp first [(i + 1)]
==
>> :bp
== bb/(i + 1)
>> bp
** Script Error: Invalid path value: i + 1 ** Near: bp
>> i + 1
== 1 So here's an open puzzle/challenge/question: Given a block of numbers, what's the simplest way in REBOL to write a smoothing operation that averages each interior value (i.e., all but the first and last) with the two values on either side of it? That is, the equivalent of the Perl for (my $i = 1; $i < $#a; ++$i) { $a[$i] = ($a[$i-1] + $a[$i] + $a[$i+1])/3; } or the Language Which Must Not B Named /* assuming double a[N]; */ for (int i = 1; i < sizeof(a)/sizeof(double) - 2; ++i) { a[i] = (a[i-1] + a[i] + a[i+1])/ 3.0; } (other languages may be imagined... ;-) One could, of course, define "simplest" in a variety of interesting ways: shortest overall code, fewest variables, fewest subexpressions, etc. A related issue would be to identify the fastest solution. -jn- -- Heavier-than-air flying machines are impossible. -- Lord Kelvin, president, Royal Society, 1895 joel#dot#neely#at#fedex#dot#FIX#PUNCTUATION#com