Ring Documentation Walkthrough #7 – Lists

We will learn today the basics of lists.

NOTE: that the index in ring starts from 1 not 0 like the other languages.


Create a list :

Method 1 :

new_list = [ 2010, 2011, 2012, 2013, 2014, 2015, 2016 ]
see new_list

Method 2 :

new_list = 1997:2016
see new_list
new_list = "a":"z"
see new_list
new_list = list(10) #list(size)
see new_list

Adding items :

Method 1 :

list = [ "ocean 11", "ocean 12" ]
add(list, "ocean 13")
see list

Method 2 :

list = [ "ocean 11", "ocean 12" ]
list + "ocean 13"
see list

Deleting items :

Method 1:

list = [ 'we', 'are', 'together'] 
del(list, 1) #del(list, index)
see list

NOTE: that the index in ring starts from 1 not 0 like the other languages.


Get the length of a list :

#do it just like in python
list = 1:6 #length is 6
see len(list) #output is 6

Get & Set items in lists :

#set an item :list[index] = value
list = ["Steve", ""]
list[2] = "Jobs"
#get an item : list[index]
see list[2]

This is it for this post.

There are two more posts about the lists, see you in the next post.

amrESSAM.

Advertisements
Ring Documentation Walkthrough #7 – Lists

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s