AltME: REBOL3

Messages

Bo
I don't understand why my above solution wouldn't work.
Ah, maybe find/any might be the trick.
Pekr
I was never succesfull in using fin/only/match etc refinements, especially with blocks ... What about using Parse and its block parsing capabilities? Could be fast ...
>> parse a [any [pos: into [quote 2 any-type!] (print mold pos) | skip]]
[[2 "b"] [3 "c"]]
== true
Just experimenting, not sure how to break/return from parse, to prevent it unnecessiraly going to the end, maybe just issue an end then :-)
Bo
Thanks for the ideas. 'find is a great tool in Rebol, but it could be even more powerful!
I seem to remember something that would take a block of blocks and return a "flattened" series. Like this:
flatten [[1 "a"][2 "b"][3 "c"]]
[1 "a" 2 "b" 3 "c"]
I know 'flatten isn't a function, but is there one like it?
Pekr
Well, maybe there is somewhere, as there was a split function. But those were the mezzanines. I think that parse solution might be faster in the end, if you somehow wrap it inside the function?
Rebolek
Bo, I wrote one some time ago: http://r.mraky.net/flatten.reb

Endo
I wrote as follow;
flatten: func [b [block!] /local r][
    r: make block! length? b
    head any [foreach v b [insert tail r v] r]
]
Endo
Rebolek: Just a small note, in your function "value" word changed in global. And it looks like my version runs twice faster in 300'000 iteration.
Pekr
It depends, how big your block is - you are effectively building a new block, hence consume memory, just as a preparation to make it 'find friendly ...
Endo
"you are effectively building a new block", that part same as Rebolek's function.
For bigger blocks the difference is more:
>> benchmark2/iteration [Endo x] [Rebolek x] 1000  ; x has 10000 items block
Execution time for the #1 job: 0:00:02.438
Execution time for the #2 job: 0:00:08.243
The difference is, Rebolek's version is more general, my version is flattens just one level:
>> endo [ [2 [3 4] [ [ 5 ] 6]]]
== [2 [3 4] [[5] 6]]
>> Rebolek [ [2 [3 4] [ [ 5 ] 6]]]
== [2 3 4 5 6]
I merged them and added /DEEP refinement.
flatten: func [b [block!] /deep /local r value rule] [
    either deep [
        local: make block! length? b
        rule: [
            into [some rule]
        |   set value skip (append local value)
        ]
        parse b [some rule]
        local
    ] [
        r: make block! length? b
        head any [foreach v b [insert tail r v] r]
    ]
]
DocKimbel
Endo, could you benchmark this one?
flatten: func [blk][load form blk]
It's probably fast but wouldn't work well for all datatypes.
Endo
Hi, yes it is faster;
>> benchmark2/iteration [flatten x] [flatten2 x] 1000
Execution time for the #1 job: 0:00:02.969
Execution time for the #2 job: 0:00:01.625  <-- Ladislav's version
But it has some undesired effects like:
>> flatten [ "3 4"  "5 6" ]
== [3 4 5 6]
And fails on non-loadable values:
>> flatten [ " '3 " ]
** Syntax Error: Invalid word-lit -- '3

Bo
So, I'm fighting with 'call and other stuff for a project. I'm trying to launch FLITE which is a TTS engine. It works perfectly fine if I run it from a shell, like follows:
    flite "this is a test"
But if I try to run it from Rebol that was launched in that exact same shell, I get:
    >> call/wait [{flite} {"this is a test"}]
    Home directory not accessible: Permission denied
    audio_open_alsa: failed to set sample rate near 8000. Invalid argument.
Also, if I try:
    call/wait/shell {flite "this is a test"}
same error. Any ideas?
Ashley
call/wait/output {cmd /C "c:\Program Files\flite\flite.exe" "this is a test"}
Oops ... sans the /output refinement
Also, I'm assuming Windows here

Last message posted 166 weeks ago.