Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Data Types Modules. #15

Open
Thecarisma opened this issue Jun 20, 2018 · 25 comments
Open

Data Types Modules. #15

Thecarisma opened this issue Jun 20, 2018 · 25 comments
Assignees
Labels
enhancement New feature or request module A new Module addition to the simple-lang standard library
Milestone

Comments

@Thecarisma
Copy link
Contributor

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 Thecarisma added enhancement New feature or request module A new Module addition to the simple-lang standard library labels Jun 20, 2018
@Thecarisma
Copy link
Contributor Author

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
Copy link
Contributor Author

Author : @Youngestdev

Update.

I've written some new methods.

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

And Yes ! 🎉

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

@Youngestdev
Copy link
Contributor

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
Copy link
Contributor

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 🎉

@Thecarisma
Copy link
Contributor Author

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 Thecarisma reopened this Jun 30, 2018
@Thecarisma
Copy link
Contributor Author

Keeping this issue open is advised

@Youngestdev
Copy link
Contributor

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

@appcypher
Copy link
Contributor

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

@Youngestdev
Copy link
Contributor

Youngestdev commented Jul 13, 2018 via email

@Thecarisma
Copy link
Contributor Author

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

@appcypher
Copy link
Contributor

appcypher commented Jul 13, 2018

@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
Copy link
Contributor

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']
])

@Youngestdev
Copy link
Contributor

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

@Thecarisma
Copy link
Contributor Author

@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"])

@appcypher
Copy link
Contributor

appcypher commented Jul 14, 2018

@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]

@Youngestdev
Copy link
Contributor

Youngestdev commented Jul 14, 2018 via email

@Thecarisma
Copy link
Contributor Author

Thecarisma commented Jul 14, 2018

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

@Youngestdev
Copy link
Contributor

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

@appcypher
Copy link
Contributor

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.

@Youngestdev
Copy link
Contributor

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

@Thecarisma
Copy link
Contributor Author

@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.

@appcypher
Copy link
Contributor

Cool. I will look into that.

@Thecarisma Thecarisma added this to the 0.4.0 milestone Oct 12, 2018
@Thecarisma Thecarisma removed this from the 0.4.0 milestone Mar 8, 2019
@Thecarisma Thecarisma added this to the 0.4.1 milestone Mar 8, 2019
@Youngestdev
Copy link
Contributor

Youngestdev commented May 6, 2019

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!

@Thecarisma
Copy link
Contributor Author

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

@Youngestdev
Copy link
Contributor

Youngestdev commented May 6, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request module A new Module addition to the simple-lang standard library
Projects
None yet
Development

No branches or pull requests

3 participants