Lytlang -> Elixir :: CoffeeScript -> JavaScript
Find a file
2019-06-16 00:59:42 -05:00
config Initial commit 2019-05-11 13:01:39 -05:00
lib WIP 2019-06-16 00:55:27 -05:00
src WIP 2019-06-16 00:55:27 -05:00
test Begin transition to leex and yecc? 2019-06-16 00:36:12 -05:00
.formatter.exs Initial commit 2019-05-11 13:01:39 -05:00
.gitignore Initial commit 2019-05-11 13:01:39 -05:00
mix.exs Initial commit 2019-05-11 13:01:39 -05:00
README.md Add rough preview 2019-06-16 00:59:42 -05:00

Lytlang

Lytlang's goal is to allow for more terse Elixir code and is itself written in Elixir. Its syntax is a terrible merging of Elm, CoffeeScript, Elixir, and some made-up crap. Here's a rough preview:

!mod Leetcode

# Look, a comment!

### part of the comment
Look, a multiline comment!
part of the comment ###

@doc
	LeetCode #1: two_sum

	TODO: store a map of complements (differences) as iterating for O(n)

fn two_sum _:list _:int i=0 ::
	[] _ _ -> nil
	[cur | rest] target current_index
		Enum.find_index rest, fn x -> cur + x == target ::
			nil -> two_sum rest target current_index
			i -> [current_index, 1 + current_index + i]

@doc LeetCode #2: add_two_numbers

fn add_two_numbers _:list _:list _=[] i=0 ::
	[] _ l m, _ [] l m -> finish_add_two_numbers l m
  [n1 | r1] [n2 | r2] l carry
		add_two_numbers r1 r2 [rem (carry + n1 + n2) 10) | l] (div n1 + n2 10)

fn finish_add_two_numbers l:list m:int -> m == 0 ? l : [m | l]

@doc
	LeetCode #3: longest non-repeating susbtring

	TODO: better utility function names?

fn longest_non_repeating_substring s
	s |> String.codepoints |> Enum.reduce {0 0 0 %{}} &ln3_reducer/2 |> elem 0

fn ln3_new_least least map char
	Map.has_key? map char ::
		true -> max least ((Map.get map char) + 1)
		_ -> least

fn ln3_reducer char {mx i least map}
	least = ln3_new_least least map char
	{(max mx (i - least + 1) (i + 1) least (Map.put map char i)}

@doc
	LeetCode #4: median of sorted arrays

	TODO: solution should me O(log(m+n))
	TODO: finish an actual solution?

fn median_of_sorted_arrays _ _ -> 3

@doc LeetCode #65: Valid Number

@valid_decimal_number_regex ~r/^\s*(?:\+|-)?\d+(?:\.(?=\d))?\d*(?:e(?=[\d\+-]))?(?:\+|-)?\d*(?:\.(?=\d))?\s*$/

fn valid_decimal_number s -> Regex.match? @valid_decimal_number_regex s

TODO: Add more description

Development Resources