Skip to content

Commit 1db717e

Browse files
committed
Evaluate each substream when sorting a list of lazy streams
- before sorting we need to actually resolve each of the inner functions so the sort applies to the result not the lazy stream fn - fixes #184
1 parent 1d532f3 commit 1db717e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/interp/commands/unary_interp.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ defmodule Interp.UnaryInterp do
133133
"ć" -> Stack.push(Stack.push(stack, GeneralCommands.dehead(a)), GeneralCommands.head(a))
134134
"Â" -> Stack.push(Stack.push(stack, a), if is_iterable(a) do a |> Enum.reverse else to_string(a) |> String.reverse end)
135135
"ê" -> Stack.push(stack, if is_iterable(a) do Enum.sort(Enum.to_list(a)) |> ListCommands.uniques else Enum.join(Enum.sort(String.graphemes(to_string(a))) |> ListCommands.uniques, "") end)
136-
"{" -> Stack.push(stack, if is_iterable(a) do Enum.sort(Enum.to_list(a)) else Enum.join(Enum.sort(String.graphemes(to_string(a)))) end)
136+
"{" -> Stack.push(stack, if is_iterable(a) do Enum.sort(eval(a)) else Enum.join(Enum.sort(String.graphemes(to_string(a)))) end)
137137
"`" -> %Stack{elements: Enum.reverse(if is_iterable(a) do Enum.to_list(a) else String.graphemes(to_string(a)) end) ++ stack.elements}
138138
"O" -> if is_iterable(a) do Stack.push(stack, ListCommands.sum(a)) else Stack.push(%Stack{}, ListCommands.sum(Stack.push(stack, a).elements)) end
139139
"Æ" -> if is_iterable(a) do Stack.push(stack, ListCommands.reduce_subtraction(a)) else Stack.push(%Stack{}, ListCommands.reduce_subtraction(Stack.push(stack, a).elements |> Enum.reverse)) end
@@ -198,4 +198,4 @@ defmodule Interp.UnaryInterp do
198198

199199
{new_stack, environment}
200200
end
201-
end
201+
end

0 commit comments

Comments
 (0)