Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News stdlib functions #305

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

6loccee
Copy link

@6loccee 6loccee commented Jul 14, 2024

I added easy functions but quite useful for what the language is based on

@@ -176,6 +176,12 @@ pub fun create_dir(path: Text): Null {
}
}

pub fun delete_dir(path: Text): Null {
if dir_exist(path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if is useless, rm -f will ignore an error if it happened. it would be useful to check if its actually a file and not a directory or something, since rm -f on a directory would fail

src/std/main.ab Outdated
return unsafe $echo -n "{text}" | base64$
}

pub fun decodeb64(encoded: Text): Text {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the point of naming it decodeb64? does it stand for decode base 64? in that case, its inconsistend naming with encode64 which i guess stands for encode base 64

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a human error. I'll put the b in base64 there. Do you think it would be okay? or give me another suggestion

}

pub fun randint(min: Num, max: Num): Num {
return unsafe $shuf -i "{min}-{max}" -n 1$
Copy link
Member

@b1ek b1ek Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite controversial. is it widely present on most UNIX systems? does its behaviour change from platform to platform? how often is it maintained? does it generate secure random numbers? does it work with floats?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this very obviously will break with negative numbers

create_dir("/tmp/amber-test")
if dir_exist("/tmp/amber-test") {
delete_dir("/tmp/amber-test")
echo "deleted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not check if the directory has actually been deleted

@@ -0,0 +1,4 @@
import * from "std"
main {
echo randint(1,1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not check if any weird range would output correct info, like if min would be greater than max

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made 1 random out of 1 because how to guess the result to pass the tests.

@b1ek
Copy link
Member

b1ek commented Jul 14, 2024

also, please include some description of the functions in the PR description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants