Testing the lists_reverse, lists_sort and lists_repeat blocks
In this program we test the lists_reverse, lists_sort and lists_repeat blocks. We test the sorting in alphabetical order both ignoring case and taking case into consideration.

The blocks
XML Code of Blocks
<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="procedures_defnoreturn" id="PStd.BGn+E0xJ*KVQq[@" x="13" y="-2512"> <field name="NAME">PrintStrMyArray</field> <statement name="STACK"> <block type="variables_set" id="7cS}]x4u/cvyYp_tBXZa"> <field name="VAR">strList</field> <value name="VALUE"> <block type="text" id="LR)S3=bv15)O{+l$@qG`"> <field name="TEXT"></field> </block> </value> <next> <block type="controls_forEach" id="rVXktI7z$e=`s0?i;L~U"> <field name="VAR">i</field> <value name="LIST"> <block type="variables_get" id="El(?Ny[.U7+Bf34vs$ht"> <field name="VAR">StrMyArray</field> </block> </value> <statement name="DO"> <block type="text_append" id="|iDkP#46-Xs%U8d?_HX3"> <field name="VAR">strList</field> <value name="TEXT"> <shadow type="text" id="g3,6}b]+~nBF/Ijg*?Ya"> <field name="TEXT"></field> </shadow> <block type="variables_get" id="{QYbFe$KE/E|E(_{|2K]"> <field name="VAR">i</field> </block> </value> <next> <block type="text_append" id="ZhxS7vqi#Zd7H5Vyn%@."> <field name="VAR">strList</field> <value name="TEXT"> <shadow type="text" id="g3,6}b]+~nBF/Ijg*?Ya"> <field name="TEXT"></field> </shadow> <block type="text" id="gAUs;Ldr^k~1fuy5n*ud"> <field name="TEXT"> </field> </block> </value> </block> </next> </block> </statement> <next> <block type="text_print" id="77vBV`X{}w[y5NZF[OvW"> <value name="TEXT"> <shadow type="text" id="jAS:gWcb-.iwp2#Dy!XK"> <field name="TEXT">abc</field> </shadow> <block type="variables_get" id="%ivs+k`}MR3?0!d/#m(."> <field name="VAR">strList</field> </block> </value> </block> </next> </block> </next> </block> </statement> </block> <block type="variables_set" id="-;!v4V#?[rcuFPa;b%Zw" x="13" y="-2312"> <field name="VAR">StrMyArray</field> <value name="VALUE"> <block type="lists_create_with" id="q_5p1(BkZ9s-!7:V=~AW"> <mutation items="5"></mutation> <value name="ADD0"> <block type="text" id="Fl)[,yu8:TP,-VCnkPa~"> <field name="TEXT">First</field> </block> </value> <value name="ADD1"> <block type="text" id="Tk?~k$.O1%`x#7;H@rb["> <field name="TEXT">second</field> </block> </value> <value name="ADD2"> <block type="text" id="7=qY(M2lJ.ls8_+5}Py]"> <field name="TEXT">Third</field> </block> </value> <value name="ADD3"> <block type="text" id="T2K#txBJk(Zju+OxhnO$"> <field name="TEXT">fourth</field> </block> </value> <value name="ADD4"> <block type="text" id="(puCi?/y;()^%SxWn%,="> <field name="TEXT">Fifth</field> </block> </value> </block> </value> <next> <block type="text_print" id="#HWcPeAb88/0v{33xAM$"> <value name="TEXT"> <shadow type="text" id="jAS:gWcb-.iwp2#Dy!XK"> <field name="TEXT">abc</field> </shadow> <block type="text" id="D[[nq?%+XVJ.A:i/hj,K"> <field name="TEXT">Print StrMyArray (1) reversed (2) in alphabetical order ignoring case and (3) in alphabetical order </field> </block> </value> <next> <block type="lists_reverse" id="6yX#6xoOrkL$u]Fn$Y9="> <value name="LIST"> <block type="variables_get" id="-jq{578n3n/jAn*?W:l1"> <field name="VAR">StrMyArray</field> </block> </value> <next> <block type="procedures_callnoreturn" id="7A,Ti}he+WcwVJCjK*?Z"> <mutation name="PrintStrMyArray"></mutation> <next> <block type="lists_sort" id="jY|To8hqNY{@F8HcrMti"> <field name="TYPE">IGNORE_CASE</field> <field name="DIRECTION">1</field> <value name="LIST"> <block type="variables_get" id="}872xgI@xnq_t~aP-}vj"> <field name="VAR">StrMyArray</field> </block> </value> <next> <block type="procedures_callnoreturn" id="=(Z(eF:`-=m0t1G*zHl/"> <mutation name="PrintStrMyArray"></mutation> <next> <block type="lists_sort" id="ax`(z$yS8o9i$N4Kbs)j"> <field name="TYPE">TEXT</field> <field name="DIRECTION">1</field> <value name="LIST"> <block type="variables_get" id="u-MdrHOHvYR`Kqh)8$Z^"> <field name="VAR">StrMyArray</field> </block> </value> <next> <block type="procedures_callnoreturn" id="(Ln6)0GRh2oxP.@fgWkg"> <mutation name="PrintStrMyArray"></mutation> <next> <block type="text_print" id="}VI{Nv^y8!$xn9lo,+^)"> <value name="TEXT"> <shadow type="text" id="jAS:gWcb-.iwp2#Dy!XK"> <field name="TEXT">abc</field> </shadow> <block type="text" id=".NFtEg%pN7U9TE!Z~=^3"> <field name="TEXT">Set StrMyArray to "unset element" repeated 3 times and print all elements.</field> </block> </value> <next> <block type="variables_set" id="0de;nq|AJ~;cTc~m36V+"> <field name="VAR">StrMyArray</field> <value name="VALUE"> <block type="lists_repeat" id="ISb$|gh|x!k?0tMmT8m}"> <value name="ITEM"> <block type="text" id=":~!g0LJjoBo5Y)k[b}=9"> <field name="TEXT">unset element</field> </block> </value> <value name="NUM"> <shadow type="math_number" id="U.6Ib*ykw)4q-*|)jI;2"> <field name="NUM">3</field> </shadow> </value> </block> </value> <next> <block type="procedures_callnoreturn" id="MivZi?)1gZoz=bl15|]="> <mutation name="PrintStrMyArray"></mutation> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </next> </block> </xml>
Generated Smart Pascal Code
var strList: String; var StrMyArray: TStrArray; procedure PrintStrMyArray(); begin strList := ''; for var i in StrMyArray do begin strList += i; strList += ' '; end; Console.writeln(strList); end; var SortIntFn := function (Left, Right: Integer): Integer begin Result := Left - Right; end; var SortIntFnDesc := function (Left, Right: Integer): Integer begin Result := Right - Left; end; var SortFloatFn := function(Left, Right: Float): Integer begin Result := if (Left - Right > 0) then 1 else -1; end; var SortFloatFnDesc := function(Left, Right: Float): Integer begin Result := if (Right - Left > 0) then 1 else -1; end; var SortTextFn := function(Left, Right: String): Integer begin Result := if (Left > Right) then 1 else -1; end; var SortTextFnDesc := function(Left, Right: String): Integer begin Result := if (Right > Left) then 1 else -1; end; var SortIgnoreCaseFn := function(Left, Right: String): Integer begin Result := if (LowerCase(Left) > LowerCase(Right)) then 1 else -1; end; var SortIgnoreCaseFnDesc := function(Left, Right: String): Integer begin Result := if (LowerCase(Right) > LowerCase(Left)) then 1 else -1; end; function RepeatArray(Value: Variant; n: integer): Variant; begin var Arr := []; for var i := 0 to n - 1 do Arr[i] := Value; Result := Variant(Arr); end; StrMyArray := ['First', 'second', 'Third', 'fourth', 'Fifth']; Console.writeln('Print StrMyArray (1) reversed (2) in alphabetical order ignoring case and (3) in alphabetical order '); StrMyArray.Reverse; PrintStrMyArray(); StrMyArray.sort(SortIgnoreCaseFn); PrintStrMyArray(); StrMyArray.sort(SortTextFn); PrintStrMyArray(); Console.writeln('Set StrMyArray to "unset element" repeated 3 times and print all elements.'); StrMyArray := TStrArray(RepeatArray('unset element', 3)); PrintStrMyArray();
Copy of Output
Print StrMyArray (1) reversed (2) in alphabetical order ignoring case and (3) in alphabetical order Fifth fourth Third second First Fifth First fourth second Third Fifth First Third fourth second Set StrMyArray to "unset element" repeated 3 times and print all elements. unset element unset element unset element