Anonymous user
VList: Difference between revisions
m
→{{header|REXX}}: changed comments and whitespace, moved documentation to its own window, used a template for output.
(Added Kotlin) |
m (→{{header|REXX}}: changed comments and whitespace, moved documentation to its own window, used a template for output.) |
||
Line 836:
This classic REXX version uses (mostly) the same "input" and operations as the ooRexx version,
except that the (stack) queue isn't changed or used.
<lang rexx>/*REXX pgm demonstrates VList operations: add/update/delete/insert/show.*/▼
║ ║
║ ┌────────────┬───────────────────────────┐ ║
Line 883:
║ to the end of the VList. Any non-zero decimal fraction may be ║
║ used. I.E.: 63.01 63.5 63.63 63.9 ║
╚════════════════════════════════════════════════════════════════════╝
▲<lang rexx>/*REXX
/*could use: q = 1 2 3 4 */▼
call q 2, 'Fred' /*update (or add) the
say q(2) q(4) /*show
/*
call q 0, 'Mike' /*insert item in front of the list. */
say q(1) q(2) q(4) /*show
/*any negative number is deleted. */
call q -1 /*delete the first item in the list. */
say q(1) q(2) q(4) /*show the 1st, 2nd, and 4th items.
/*Fractional
call q 3.5, '3½' /*insert the item after the
say q , /*show all the VList items. */
/*Put on a dog and pony show. */
say 'number of items in Vlist:' q() /*show and tell time for the Vlist. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
q: parse arg n 1 na 1 ni,!; w=words(q); $= /*
if symbol('Q')=='LIT' then q= /*var Q may not be defined. */
if arg()==0 then return words(q) /*return the VList item count*/
if arg(1, 'O')
if arg()==1 & n>0 then return word(q,n) /*1 positive arg? Return it.*/
if n==0 then do; q=! q; return q; end /*insert in front of the list*/
if n> w then do; q=q !; return q; end /*add it to end. " " " */
na=abs(n) /*we might need use of ABS. */
if \datatype(ni, 'W') & ni>0 then ni=trunc(na)
else ni=0
do j=1 for w /* [↓] rebuild the Vlist. */
if j==na then do; if na==n then $=$ !; end /*replace the item in list. */
else $=$ word(q, j) /*an easy-peasy
if j==ni then $=$ ! /*handle the "insert". */
end /*j*/
q=space($);
{{out|output|text= when using the default input:}}
<pre>
4
|