-
Notifications
You must be signed in to change notification settings - Fork 128
Collection manipulation
Wang Renxin edited this page Apr 11, 2016
·
32 revisions
MY-BASIC supplies a set of LIST, DICT manipulation function libraries which provide creation, accessing, iteration, etc. as below:
| Name | Description |
|---|---|
| LIST | Creates a list |
| DICT | Creates a dictionary |
| PUSH | Pushes a value to the tail of a list |
| POP | Pops a value from the tail of a list |
| PEEK | Peeks the value of a tail of a list |
| INSERT | Inserts a value at a specific position of a list |
| SORT | Sorts a list increasingly |
| EXIST | Tells whether a list contains a specific value, or whether a dictionary contains a specific key |
| INDEX_OF | Gets the index of a value in a list |
| GET | Returns the value of a specific index in a list, or the value of a specific key in a dictionary; or a member of a class instance |
| SET | Sets the value of a specific index in a list, or the value of a specific key in a dictionary |
| REMOVE | Removes the element of a specific index in a list, or the element of a specific key in a dictionary |
| CLEAR | Clears a list or a dictionary |
| CLONE | Clones a collection, each element will be duplicated |
| TO_ARRAY | Copies all elements from a list to an array |
| ITERATOR | Gets an iterator of a list or a dictionary |
| MOVE_NEXT | Moves an iterator to next position for a list or a dictionary |
Besides, it's also able to apply the LEN function to collections:
| Name | Description |
|---|---|
| LEN | Get element count of a collection |
For example:
l = list(1, 2, 3, 4)
set(l, 1, “b”)
print exist(l, 2); pop(l); peek(l); len(l);
d = dict(1, “one”, 2, “two”)
set(d, 3, “three”)
print len(d)
it = iterator(d)
while move_next(it)
print get(it);
wendIt's able to implement other collection functions with these facilities, for example a reverse function as follow:
def reversed(l)
if not l is type("list") then
return nil
endif
ret = list()
while len(l) <> 0
push(ret, pop(l))
wend
return ret
enddefRead the Stack module page to get information about how to implement a stack collection.
- Principles
- Coding
- Data types
- Standalone shell
- Integration
- Customization
- More scripting API
- FAQ