Open CymDeveloppement opened 1 week ago
array_value(array, index)
that's essentially a wrapper for array[index]
, what's the use for it? i'd imagine it throwing an error if the value doesn't exist (idk if amber doesnt already do that)
also every stdlib function should be covered by a test (see #127)
array_value(array, index)
is related to #211
i think is more readable :
let str = array_value(split("foo bar test tutu", " "), 0)
compared to :
let result = split("foo bar test tutu", " ") let str = result[0]
and is permit more complex code like :
array_value(split("foo bar test tutu", " "), get_index_function_example("test"))
it's just palliative
and sorry for the test, I did not see. I will write them
I am not a Rust specialist, Do you think it's good ?
#[test]
fn array_value() {
let code = "
import * from \"std\"
main {
echo array_value([1, 2, 3, 4], 1)
}
";
test_amber!(code, "2")
}
#[test]
fn array_index() {
let code = "
import * from \"std\"
main {
echo array_index([1, 2, 3, 4], 3)
}
";
test_amber!(code, "2")
}
#[test]
fn array_search() {
let code = "
import * from \"std\"
main {
let result = array_search([1, 2, 3, 4, 3], 3)
echo result[0]+result[1]
}
";
test_amber!(code, "6")
}
array_value(array, index)
that's essentially a wrapper for
array[index]
, what's the use for it? i'd imagine it throwing an error if the value doesn't exist (idk if amber doesnt already do that)
@b1ek The problem is that Amber has implemented subscript syntax just for variables only. The reason is that back then array literals were literally evaluated as literals ("item1", "item2")
but now they are evaluated as variables (line before:ARRAY=("item1", "item2")
) $ARRAY
Do you think it's good ?
just push the commit and i will approve it if its good, and request changes if its not
@CymDeveloppement any progress on this?
@b1ek pull request is updated with the commit, you can review
tbh i agree with @Mte90, function names are important since they will stay as is.
what about renaming array_value
to array_get
? that seems more straightforward to me as to what this function does
Maybe :
array_value
==> array_get
array_index
==> array_first_index
array_value(array, index)
return the value at indexarray_index(array, value): Num
search the first occurrence of value and return indexarray_search(array, value): [Num]
return an array of Num with corresponding indexes