-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Lists/arrays #67
Comments
An alternative with post-0.4.2
pokered's macros/scripts/maps.asm works somewhat like this, e.g.
|
Here are some macros for working with lists (using features of post-0.5.0 rgbasm
|
That actually demonstrates a possible use case for
|
Bump @Sanqui, what do you think of Rangi's suggested alternatives? |
Well, it's sort of hacky, would have been nice to have some syntactical sugar for this whole thing, but it would work for me, I think. I can't help but wonder if dictionaries would be possible with this approach too, to possibly enable loading entire JSON-like structures. |
Struct support has been requested (#98), is shimmed, but has native support planned because rgbds-structs is a big pile of spaghetti hacks. |
We were discussing native arrays in Some possible syntaxes for array literals:
Most string functions would usefully have array counterparts, though I don't know if they should start with "
Macros like in list.asm could take care of more advanced array manipulation, like counting a value, removing/replacing the first/last/all of a value, sorting, reversing, etc. If any of them are found to be particularly useful, they can always be added in a later release. (Even the A question: how to assign an identifier to an array? There's a notable difference between arrays and strings. If you have
This proposal also doesn't address arrays of strings, which could be at least as useful. Example: have an array of all monster names, and in texts discussing |
A few unsorted comments on your comment:
|
|
It's true that plenty of languages use 1-based indexing. It's also true that languages are nearly universally hated by programmers for doing so, and the only reason they do it is because they are math- or science-oriented and scientists and mathematicians tend to count from 1. String indexing is a relatively rare operation, while array indexing is the only reason you'd ever use arrays in the first place, so getting it right for arrays is a lot more important, to the point it probably trumps the need for consistency.
|
|
A less serious but not entirely joking suggestion: once we have user-defined functions, we could add |
> A less serious but not entirely joking suggestion: once we have user-defined functions, we could add ARRAYMAP(arr, fn) to apply *fn* to each element of *arr*, and ARRAYFILTER(arr, fn) to select only the elements of *arr* for which *fn* returns nonzero/true. Or even ARRAYREDUCE(arr, fn, start=0) to apply a reducing function (e.g. if DEF plus(x, y) = x + y, then ARRAYREDUCE([1,2,3], plus) == 6).
Definitely useful.
(Ed: I removed the email chains from these comments. --Rangi)
|
Updated syntax for the very basic arrays in the original feature request: MACRO def_array
def \1#LEN equ _NARG - 1
for idx, \1#LEN
def argi = idx + 2
def \1#{d:idx} equ \<argi>
endr
ENDM
def_array MOVES, $24, $3a
db MOVES#LEN
db MOVES#0, MOVES#1
MACRO def_str_array
def \1#LEN equ _NARG - 1
for idx, \1#LEN
def argi = idx + 2
def \1#{d:idx} equs \<argi>
endr
ENDM
def_str_array POKEMON_NAMES, "BULBASAUR", "IVYSAUR"
def STARTER1 equ 0
db "So you want {POKEMON_NAMES#{d:STARTER1}}?@" Extensions like appending to an array are also pretty easy to implement: MACRO append_array
def \1#{d:\1#LEN} equ \2
redef \1#LEN equ \1#LEN + 1
ENDM
append_array MOVES, $f0
assert MOVES#LEN == 3
assert MOVES#2 == $f0
MACRO append_str_array
def \1#{d:\1#LEN} equs \2
redef \1#LEN equ \1#LEN + 1
ENDM
append_str_array POKEMON_NAMES, "VENUSAUR"
assert POKEMON_NAMES#LEN == 3
assert !strcmp("{POKEMON_NAMES#2}", "VENUSAUR") (The possibilities for advanced features -- concatenating, searching, sorting, reversing, function-mapping, shuffling -- get increasingly more like a "real programming language" than "genuinely useful utilities for assembly metaprogramming", and I'm not sure it's worth dedicating language syntax/code/testing/maintenance to them.) |
Are there any examples of lists/arrays in other assemblers? Prior art that we could get inspiration and use cases from? |
Is there any chance for something like this to happen at all? Is it even a good idea?
Should be made to work for strings too.
The text was updated successfully, but these errors were encountered: