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