simple icon indicating copy to clipboard operation
simple copied to clipboard

Data Types Modules.

Open Thecarisma opened this issue 7 years ago • 25 comments

Author : @Youngestdev

I'll be working on building data type modules such as List.sim and Number.sim.

Reason.

Modules will enable us carry out basic operations in data type.

Example

A list will be able to add, delete, reverse once the module is built.

list = ["a", "b", test] 

display list +crlf
// Displays *a, b and test*
list.push("a")
// Undefined

Result from this ?

Well, we'll have methods that arrays ( as in JavaScript ) or Lists ( as in Python ).

example :

.push()
.pop()
.reverse()
And so many more.

Thecarisma avatar Jun 20 '18 04:06 Thecarisma

Author : @Youngestdev

Pheew. Update.

The push method.

The push method has been built into two ways.

1. addToList(list, value).

This above, is a function to add a value to the List / Array. This function cannot be appended to the list variable directly. In this case, the list argument in the array stand for the array that an element will be added to and the value is that element ( number, string, list ) that'll be added to the array. I'll give an example.

call "simple/core/List.sim"
myList = ["a", "b"] # List containing two elements.
# Add the element `c` to the list / array.
addToList(myList, "c")
# `c` has been added to the list.
display myList // a, b, c

2. .push (x)

This is binded to the List class. To use this, you'll have to declare list using a class declaration structure. Take a look at the Example below:

call "simple/core/List.sim"

myList = new List(["a", "b"])
# Let's add another value to the array..
myList.push("c")
display myList # a, b and c.

Unfortunately, I'm still working on the display of the keys in the list when called .

Other methods

I've worked on other methods but are currently in function state, I'm rewriting them to fit the class structure type so they can be appended to the variable e.g myList.reverse() I'll be sending a PR soon !

Thecarisma avatar Jun 20 '18 04:06 Thecarisma

Author : @Youngestdev

Update.

I've written some new methods.

  • .indexOf()
  • .keys()
  • An uncomplete .sort() and .slice() method - still under development.

And Yes ! :tada:

The List module has been pushed to the repo so it can be used from now on. More functionalities will be added soon.

Thecarisma avatar Jun 20 '18 04:06 Thecarisma

Another Update.

The .slice() method has been added to the List module, so we can now have an instance of something like this:

myList.slice(1,3)

But, the .slice() method doesn't support the use of one argument. If you intend to use it with one parameter, use the .indexOf().

Youngestdev avatar Jun 25 '18 17:06 Youngestdev

Well, I think i'll be closing the issue now. The issue will be re-opened only when another data type module is built.

Cheers :tada:

Youngestdev avatar Jun 28 '18 12:06 Youngestdev

Update on The Data Types Modules

__ Double Dash

Using double dash as the beginning of class variable in the simple-lang standard modules should be implored to make the variables unique and also avoid developers to create a variable identifier that will clash with identifiers in the modules

Private object and blocks

In the standard modules objects and blocks that is not to be touched outside the class should be declared private to prevents data manipulation to avoid breaking the class. The private objects will not be accessible from outside the class, all the private objects and blocks can be declared with the keyword private follow by all the blocks and objects e.g

class Test
         ...
         private 
             attributes = "test private atrribute"
             block testPrivateBlock()

__OBJECT variable

All the classes that will be inheriting the class Object should have it primary elements declared as __OBJECT. this will make all the general blocks very effective in the Object class, simple-lang don't force implementation of abstract classes but the development should be strictly adhere to

Type Safe

There should be very clear different in term of security, certainty, safe implementations between low level declaration and high level declaration with classes. A low level declaration such as str = "this is a string" and high level declaration str = new String("this is a string") The later str = new String("this is a string") should be very safe and satisfying for use such that at production it is not prone to any type of error or issue. This can be achieved by checking the parameter type in block in the Core classes e.g the constructor of String class


class String : Object
     ...
     block String(str)
          if isString(str) 
            #do all the needs
            ...
         else
             throw(__NOT_A_STRING_ERROR)
        end

with the isString(str) condition the integrity of the parameter is checked while just str = "" does not, other method can include confirming the length of parameter and object, defining limit and types, using an internal definition of variable to be different from global variable

Thecarisma avatar Jun 30 '18 23:06 Thecarisma

Keeping this issue open is advised

Thecarisma avatar Jun 30 '18 23:06 Thecarisma

Erh cool..Keeping it open will be better.. since new additions might be included.

Youngestdev avatar Jul 01 '18 23:07 Youngestdev

Is there a dictionary implementation? I want to attempt that.

appcypher avatar Jul 13 '18 13:07 appcypher

Dictionary in what sense ?

On Jul 13, 2018 14:52, "Steve Akinyemi" [email protected] wrote:

Is there a dictionary implementation? I want to attempt that.

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/simple-lang/simple/issues/15#issuecomment-404839795, or mute the thread https://github.com/notifications/unsubscribe-auth/Adkrj7Un3TzbgSAx-cfi2aH7Ln2PO_FHks5uGKYNgaJpZM4Uumky .

Youngestdev avatar Jul 13 '18 13:07 Youngestdev

@appcypher a dictionary implementation will be great due to it possibilities and it possible uses, eager for your pull request

Thecarisma avatar Jul 13 '18 13:07 Thecarisma

@Youngestdev If you are familiar with hashmaps, that's what a dictionary is. It's an associative array that stores key-value pairs and can be indexed by their keys. I believe you already know what it is by now, otherwise, I can go into more details.

@Thecarisma I've not had enough time to grok around the language because of work. I will take a deeper dive soon. However, I'd like to know the syntax suggestions you may have as I don't think there is a syntax for dictionary yet.

Currently, I'm going with the following:

map = new Map(
    ['name', 'James'],
    ['age', 45],
    ['gender', 'male']
)

map.get('name') # 'James'
map.put('job', 'Gardener')
map.size() # 4
map.keys() # ['name', 'age', 'gender', 'job']
map.values() # ['James', 45, 'male', 'Gardener']

appcypher avatar Jul 13 '18 14:07 appcypher

Just figured that the above idea won't work without varargs. So it has to be done this way.

map = new Map([
    ['name', 'James'],
    ['age', 45],
    ['gender', 'male']
])

appcypher avatar Jul 13 '18 16:07 appcypher

Okay, I get it @appcypher. It'll be great to have such feature in simple-lang as @Thecarisma said.

Youngestdev avatar Jul 13 '18 17:07 Youngestdev

@appcypher the list literal error is not intentional display list[0][0] should work perfectly but i found out it erroneous on my System too i fix it immediately and update too.
for now assigning to variable should work as a replacement as in

tempList = list[0]
display tempList[0]

that should not temper with performance and weigh on the memory as it is garbage collected after block execution

Varargs

sensing your usage of the Map block it should accept unlimited number of parameter similar to list. That will be implemented into simple-lang after this release. we will have a parameter like

block Map(varargs) 
    ....
//parameter can be passed to the block like
map = new Map(2,3,4,5,"a",[2,"are"])

Thecarisma avatar Jul 14 '18 07:07 Thecarisma

@Thecarisma Varargs would definitely be nice.

You may notice that I've deleted the message abt nested list. I later found that it works in a different way.

For a list

list = [[1, 2], [3, 4]]

It appears the index of the inner list starts at 1, so while list[0][0] won't work. This will.

list[0][1]

appcypher avatar Jul 14 '18 09:07 appcypher

Why do I feel like the index should start at 0. I thought we discussed this @Thecarisma ?

On Jul 14, 2018 10:10, "Steve Akinyemi" [email protected] wrote:

@Thecarisma https://github.com/Thecarisma Varargs would be definitely be nice.

You may notice that I've deleted the message abt nested list. I later found that it works in a different way.

For a list

list = [[1, 2], [3, 4]]

It appears the index of the inner list starts at 1, so while list[0][0] won't work. This will.

list[0][1]

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/simple-lang/simple/issues/15#issuecomment-405010547, or mute the thread https://github.com/notifications/unsubscribe-auth/Adkrj9W8t-UoHH14QGkdJwTSh9sFPXjYks5uGbWHgaJpZM4Uumky .

Youngestdev avatar Jul 14 '18 09:07 Youngestdev

The list index definitely start from zero but and one two but it should not clash in which ever way. The support of index starting from 1 is resolving to the error of accesing index withing index [0][0]. for now till the error is resolve we can assign the first index to a variable and get the index at zero

#instead of 
list[0][1]
#use 
tList = list[0]
tList[0]

till error is resolved

Thecarisma avatar Jul 14 '18 10:07 Thecarisma

Well, we better try fix the error because the above method situated isn't recommended.

Youngestdev avatar Jul 14 '18 10:07 Youngestdev

Just found out that there is a dictionary data structure in Simple already.

dict = [:name = 'john', :age = 5]

My map impl is kinda useless unless I change it to HashMap. Well I was thinking of learning some cryptography. So I think I will turn the Map into HashMap.

BTW, we need to document things more to prevent duplication of effort.

appcypher avatar Jul 17 '18 22:07 appcypher

Well. I just thought of that too @appcypher. I'll try write a list of already written modules to avoid duplication.

Youngestdev avatar Jul 17 '18 23:07 Youngestdev

@appcypher you might not need to dig deep into cryptography you can use the sha1, sha254, md5 and other hashes from the security library to hash keys call "simple/security/Hash.sim" This will require you to have build the security.dylib dynamic module for MAC. And no module is useless it might not just be use as often as other module so let the Map module be.

Thecarisma avatar Jul 18 '18 08:07 Thecarisma

Cool. I will look into that.

appcypher avatar Jul 18 '18 09:07 appcypher

Heyo! It's quite long here...

I be trying to improve another function/method in the List module - The .map function..


test = new List(arr)
test.map(arr, fn)

Although I have only rough ideas yet, I'll try out them into reality.. I'll see what I can do on that and keep updating us!

Youngestdev avatar May 06 '19 08:05 Youngestdev

Just ensure your fork is upto date, build from master as breaking changes has been implemented

Thecarisma avatar May 06 '19 09:05 Thecarisma

Sure

On May 6, 2019 10:27 AM, "A Toy Soldier" [email protected] wrote:

Just ensure your fork is upto date, build from master as breaking changes has been implemented

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/simple-lang/simple/issues/15#issuecomment-489560334, or mute the thread https://github.com/notifications/unsubscribe-auth/AHMSXDZQPLJJWBJLGSN35UDPT72XLANCNFSM4FF2NEZA .

Youngestdev avatar May 06 '19 09:05 Youngestdev