Extending a list in Softanza

11 views
Skip to first unread message

Mansour Ayouni

unread,
May 13, 2022, 4:16:29 PM5/13/22
to The Ring Programming Language
Hello All,

In Softanza you can extend a list to a given position, by a given value, in many ways...

See the following code:

load "stzlib.ring"


# Extending a list of numbers to a given position


o1 = new stzList([ 1, 2, 3 ])
o1.ExtendTo(5)
? @@( o1.Content() )
#--> [ 1, 2, 3, 0, 0 ]


# Extending a list of strings to a given position


o1 = new stzList([ "A", "B", "C" ])
o1.ExtendTo(5)
? @@( o1.Content() )
#--> [ "A", "B", "C", "", "" ]


# Extending a list by a given item


o1 = new stzList([ "A", "B", "C" ])
o1.ExtendToXT(5, :With = "♥")
? @@( o1.Content() )
#--> [ "A", "B", "C", "♥", "♥" ]


# Extending a list by its own items


o1 = new stzList([ "A", "B", "C" ])
o1.ExtendToXT(5, :With@ = "@items" )
? @@( o1.Content() )
#--> [ "A", "B", "C", "A", "B" ]


# Extending a list by the items of another list


o1 = new stzList([ "A", "B", "C" ])
o1.ExtendToXT(8, :With@ = [1, 2, 3] )
? @@( o1.Content() )
#--> [ "A", "B", "C", 1, 2, 3, 0, 0 ]


Here is a snapshot the code working on my machine:

image.png

PS: you will be able to try it in the next upgrade of the library package by the end of this week.


Best,

Mansour

Mahmoud Fayed

unread,
May 14, 2022, 5:00:45 AM5/14/22
to The Ring Programming Language
Hello Mansour

Thanks for sharing the sample :D
Keep up the GREAT WORK :D

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages