|
|
Line 554: |
Line 554: |
|
Sleep</syntaxhighlight> |
|
Sleep</syntaxhighlight> |
|
{{out}} |
|
{{out}} |
⚫ |
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
|
|
|
⚫ |
==={{header|FutureBasic}} === |
|
⚫ |
|
|
⚫ |
<syntaxhighlight lang="futurebasic"> |
|
⚫ |
local fn FlattenList( list as Str255 ) as Str255 |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
if ( instr$( 0, "[] ,", mid$( list, i, 1 ) ) === 0 ) |
|
⚫ |
flatStr += commaStr + mid$( list, i, 1 ) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
window 1, @"Flatten a list", ( 0, 0, 350, 150 ) |
|
|
|
|
⚫ |
print "["; fn FlattenList( "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]" ); "]" |
|
|
|
|
⚫ |
HandleEvents</syntaxhighlight> |
|
⚫ |
|
|
⚫ |
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
|
|
|
⚫ |
Modern and a little outside the box. |
|
⚫ |
<syntaxhighlight lang="futurebasic"> |
|
⚫ |
void local fn FlattenAList |
|
⚫ |
CFStringRef listStr = @"[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]" |
|
⚫ |
CFArrayRef listArr = fn StringComponentsSeparatedByCharactersInSet( listStr, fn CharacterSetWithCharactersInString( @"\"[ ]," ) ) |
|
⚫ |
CFMutableArrayRef mutArr = fn MutableArrayWithArray( listArr ) |
|
⚫ |
MutableArrayRemoveObject( mutArr, @"" ) |
|
⚫ |
CFStringRef flatStr = fn ArrayComponentsJoinedByString( mutArr, @", " ) |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
|
|
|
Line 1,908: |
Line 1,866: |
|
println[flatten[a]] |
|
println[flatten[a]] |
|
</syntaxhighlight> |
|
</syntaxhighlight> |
|
|
|
|
⚫ |
=={{header|FutureBasic}}== |
|
⚫ |
|
|
⚫ |
<syntaxhighlight lang="futurebasic"> |
|
⚫ |
local fn FlattenList( list as Str255 ) as Str255 |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
if ( instr$( 0, "[] ,", mid$( list, i, 1 ) ) === 0 ) |
|
⚫ |
flatStr += commaStr + mid$( list, i, 1 ) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
window 1, @"Flatten a list", ( 0, 0, 350, 150 ) |
|
|
|
|
⚫ |
print "["; fn FlattenList( "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]" ); "]" |
|
|
|
|
⚫ |
HandleEvents</syntaxhighlight> |
|
⚫ |
|
|
⚫ |
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
|
|
|
⚫ |
Modern and a little outside the box. |
|
⚫ |
<syntaxhighlight lang="futurebasic"> |
|
⚫ |
void local fn FlattenAList |
|
⚫ |
CFStringRef listStr = @"[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]" |
|
⚫ |
CFArrayRef listArr = fn StringComponentsSeparatedByCharactersInSet( listStr, fn CharacterSetWithCharactersInString( @"\"[ ]," ) ) |
|
⚫ |
CFMutableArrayRef mutArr = fn MutableArrayWithArray( listArr ) |
|
⚫ |
MutableArrayRemoveObject( mutArr, @"" ) |
|
⚫ |
CFStringRef flatStr = fn ArrayComponentsJoinedByString( mutArr, @", " ) |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
<pre>[1, 2, 3, 4, 5, 6, 7, 8]</pre> |
|
|
|
|
|
=={{header|GAP}}== |
|
=={{header|GAP}}== |