Skip to content

Commit

Permalink
Fix slice range warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeygroover committed Nov 29, 2024
1 parent d47ef06 commit bd0f1a8
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions lib/commands/gen_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ defmodule Commands.GeneralCommands do
def dehead(value) do
cond do
Functions.is_iterable(value) -> Stream.drop(value, 1) |> Stream.map(fn x -> x end)
true -> String.slice(to_string(value), 1..-1)
true -> String.slice(to_string(value), 1..-1//1)
end
end

def tail(value) do
cond do
Functions.is_iterable(value) -> hd(Enum.slice(Enum.to_list(value), -1..-1))
Functions.is_iterable(value) -> hd(Enum.slice(Enum.to_list(value), -1..-1//1))
is_integer(value) -> tail(Functions.to_non_number(value))
true -> String.slice(value, -1..-1)
true -> String.slice(value, -1..-1//1)
end
end

def detail(value) do
cond do
Functions.is_iterable(value) ->
value |> Enum.reverse |> tl |> Enum.reverse |> Stream.map(fn x -> x end)
true -> String.slice(to_string(value), 0..-2)
true -> String.slice(to_string(value), 0..-2//1)
end
end

Expand Down Expand Up @@ -98,7 +98,7 @@ defmodule Commands.GeneralCommands do
def count(value, element) when Functions.is_iterable(value), do: value |> Enum.count(fn x -> equals(x, element) end)
def count(value, element), do: count(value, element, 0)
defp count("", _, count), do: count
defp count(value, element, count), do: count(value |> String.slice(1..-1), element, count + Functions.to_number(value |> String.starts_with?(element)))
defp count(value, element, count), do: count(value |> String.slice(1..-1//1), element, count + Functions.to_number(value |> String.starts_with?(element)))

def strict_count(value, element) when not Functions.is_iterable(value) and not Functions.is_iterable(element), do: element |> Stream.map(fn x -> count(value, x) end)
def strict_count(value, element) when not Functions.is_iterable(value), do: count(value, element)
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/int_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ defmodule Commands.IntCommands do
defp from_roman_numeral("", number), do: number
defp from_roman_numeral(roman, number) do
[curr_number, curr_roman] = Enum.find(@roman_number_list, fn [_, y] -> String.starts_with?(roman, y) end)
from_roman_numeral(roman |> String.slice(String.length(curr_roman)..-1), number + curr_number)
from_roman_numeral(roman |> String.slice(String.length(curr_roman)..-1//1), number + curr_number)
end

def median([]), do: []
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/list_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Commands.ListCommands do
Functions.is_iterable(count) -> take_split(value, count)
Functions.is_iterable(value) and count < 0 -> Stream.take(value, length(Enum.to_list(value)) + count) |> Stream.map(fn x -> x end)
Functions.is_iterable(value) -> Stream.take(value, Functions.to_number(count)) |> Stream.map(fn x -> x end)
true -> String.slice(to_string(value), 0..count - 1)
true -> String.slice(to_string(value), 0..count - 1//1)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/str_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ defmodule Commands.StrCommands do
cond do
Regex.match?(~r/^[a-zA-Z]/, string) ->
matches = Regex.named_captures(~r/^(?<string>[a-zA-Z].+?)(?<remaining>(\.|!|\?|$).*)/s, string)
sentence_case(matches["remaining"], parsed <> String.capitalize(String.slice(matches["string"], 0..0)) <> String.slice(matches["string"], 1..-1))
sentence_case(matches["remaining"], parsed <> String.capitalize(String.slice(matches["string"], 0..0)) <> String.slice(matches["string"], 1..-1//1))
true ->
matches = Regex.named_captures(~r/^(?<string>.)(?<remaining>.*)/s, string)
sentence_case(matches["remaining"], parsed <> matches["string"])
Expand Down Expand Up @@ -236,7 +236,7 @@ defmodule Commands.StrCommands do
string = to_string(string)
cond do
String.contains?(string, "\n") -> Enum.join(intersected_mirror(String.split(string, "\n")), "\n")
true -> string <> (string |> String.reverse |> String.slice(1..-1) |> transliterate("<>{}()[]\\/", "><}{)(][/\\"))
true -> string <> (string |> String.reverse |> String.slice(1..-1//1) |> transliterate("<>{}()[]\\/", "><}{)(][/\\"))
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/interp/canvas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ defmodule Interp.Canvas do

true ->
case List.last(parsed) do
[:code, prev_op] -> parse_directions(String.slice(string, 1..-1), Enum.slice(parsed, 0..-2) ++ [[:code, prev_op <> String.first(string)]])
_ -> parse_directions(String.slice(string, 1..-1), parsed ++ [[:code, String.first(string)]])
[:code, prev_op] -> parse_directions(String.slice(string, 1..-1//1), Enum.slice(parsed, 0..-2//1) ++ [[:code, prev_op <> String.first(string)]])
_ -> parse_directions(String.slice(string, 1..-1//1), parsed ++ [[:code, String.first(string)]])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/interp/functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Interp.Functions do

if is_bitstring(value) and String.starts_with?(value, "-") do
try do
new_val = String.slice(value, 1..-1)
new_val = String.slice(value, 1..-1//1)
-to_number(new_val)
rescue
_ -> value
Expand Down
4 changes: 2 additions & 2 deletions lib/interp/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Interp.Interpreter do
def interp_string(string, stack, environment) do
dissected_string = String.split(string, "ÿ")

{elements, stack, environment} = Enum.reduce(Enum.slice(dissected_string, 0..-2), {[], stack, environment},
{elements, stack, environment} = Enum.reduce(Enum.slice(dissected_string, 0..-2//1), {[], stack, environment},
fn (_, {acc, curr_stack, curr_env}) ->
case Stack.pop(curr_stack, curr_env) do
nil -> {acc, curr_stack, curr_env}
Expand All @@ -67,7 +67,7 @@ defmodule Interp.Interpreter do
elements == [] ->
{Stack.push(stack, string), environment}
true ->
string = Enum.zip(Enum.slice(dissected_string, 0..-2), Stream.cycle(elements)) ++ [{hd(Enum.slice(dissected_string, -1..-1)), ""}]
string = Enum.zip(Enum.slice(dissected_string, 0..-2//1), Stream.cycle(elements)) ++ [{hd(Enum.slice(dissected_string, -1..-1//1)), ""}]
|> Enum.reduce("", fn ({a, b}, acc) -> acc <> to_string(a) <> to_string(b) end)
{Stack.push(stack, string), environment}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/reading/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Reading.InputHandler do

defp parse_multiline_string(chars) do
cond do
String.ends_with?(chars, "\"\"\"") -> String.slice(chars, 0..-4)
String.ends_with?(chars, "\"\"\"") -> String.slice(chars, 0..-4//1)
true -> chars <> "\n" <> parse_multiline_string(String.trim_trailing(IO.read(:stdio, :line), "\n"))
:eof -> ""
end
Expand All @@ -26,7 +26,7 @@ defmodule Reading.InputHandler do
Globals.set(%{global_env | inputs: global_env.inputs ++ [result]})
result
String.starts_with?(input, "\"\"\"") ->
result = parse_multiline_string(String.slice(input, 3..-1))
result = parse_multiline_string(String.slice(input, 3..-1//1))
global_env = Globals.get()
Globals.set(%{global_env | inputs: global_env.inputs ++ [result]})
result
Expand Down

0 comments on commit bd0f1a8

Please sign in to comment.