Fixing up sorting more.
This commit is contained in:
parent
f553bf2948
commit
a858775a68
@ -1,4 +1,5 @@
|
||||
require "lib/metaprogramming.nom"
|
||||
require "lib/utils.nom"
|
||||
require "lib/control_flow.nom"
|
||||
require "lib/operators.nom"
|
||||
|
||||
@ -116,6 +117,15 @@ compile [%expression for %var in %iterable] to:
|
||||
|end)(game, setmetatable({}, {__index=vars}))
|
||||
parse [%expression for all %iterable] as: %expression for % in %iterable
|
||||
|
||||
rule [%items sorted] =:
|
||||
%copy = (% for all %items)
|
||||
sort %copy
|
||||
%copy
|
||||
rule [%items sorted by %key] =:
|
||||
%copy = (% for all %items)
|
||||
sort %copy by %key
|
||||
%copy
|
||||
|
||||
# TODO: maybe make a generator/coroutine?
|
||||
|
||||
#.. Dict comprehensions can be accomplished okay by doing:
|
||||
|
@ -87,11 +87,9 @@ compile [max of %items by %value_expr] to:
|
||||
| return \(%value_expr as lua)
|
||||
|end)
|
||||
compile [sort %items] to: "table.sort(\(%items as lua))"
|
||||
compile [sort %items by %key] to: ".."
|
||||
|nomsu.utils.sort(\(%items as lua), function(x)
|
||||
| local ret, vars = nil, {['']=x};
|
||||
| \(%key as lua statements)
|
||||
| return ret
|
||||
rule [sort %items by %key] =: lua expr ".."
|
||||
|nomsu.utils.sort(\(%items), function(x)
|
||||
| return (\(%key))(nomsu, {['']=x});
|
||||
|end)
|
||||
|
||||
# String utilities
|
||||
|
Loading…
Reference in New Issue
Block a user