This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Anagram | |
class Dictionary < Hash | |
def initialize(dict_file="/usr/share/dict/american-english") | |
words = File.read(dict_file).split(?\n) | |
# Try to optimize #is_word? by sorting the hash in the form of {0 => {"A" => ...}, 1 => {"A" => ... "B" => ... }, ... } | |
words.group_by(&:length).each do |k,v| | |
self[k] = v.group_by(&:chr) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(14)> IO.puts(PrettyPrint.pp {:ok,[1.4015045714773258,<<13::size(5)>>,[]]}) | |
{ | |
:ok, | |
[ | |
1.4015045714773258, | |
<<13::size(5)>>, | |
[] | |
] | |
} | |
:ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(13)> PrettyPrint.pp {:ok,[1.4015045714773258,<<13::size(5)>>,[]]} | |
'{\n :ok,\n [\n 1.4015045714773258,\n <<13::size(5)>>,\n [\n\n ]\n ]\n}' | |
iex(14)> PrettyPrint.pp {:ok,[1.4015045714773258,<<13::size(5)>>,[],:"¨\"@"]} | |
** (ArgumentError) argument error | |
:erlang.++({:error,' :ok,\n [\n 1.4015045714773258,\n <<13::size(5)>>,\n [\n\n ],\n :"',<<136,168,92,34,64,34,10,32,32,93>>}, '\n}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Signals | |
sig = { | |
'TERM' => proc { $m.terminate('Caught termination signal') }, | |
'INT' => proc { $m.terminate('Ctrl-C pressed') }, | |
'HUP' => proc { $m.conf.rehash } | |
} | |
sig.delete 'HUP' if Syndi.windows? | |
sig.each { |signal, prc| Signal.trap(signal) { prc.call } } | |
# This is horrid. This should never be done this way. It is an utter waste of computational time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> Lexer.PIR.tokenize("<<\"TEST\" <<\"SECOND_LEVEL\" <<'THIRD'\nthis probably won't work the first time\nTEST\nthis should go into SECOND_LEVEL\nSECOND_LEVEL\nthis almost certainly will not work\nTHIRD") | |
[ | |
{ | |
:str, | |
1, | |
'this probably won\'t work the first time\n' | |
}, | |
{ | |
:str, | |
1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> Lexer.PIR.tokenize("<<\"TEST\" <<\"SECOND_LEVEL\" <<'THIRD'\nthis probably won't work the first time\nTEST\nthis should go into SECOND_LEVEL\nSECOND_LEVEL\nthis almost certainly will not work\nTHIRD") | |
[{:str,1,'this probably won\'t work the first time\n'},{:str,1,'this should go into SECOND_LEVEL\n'},{:str,1,'this almost certainly will not work\n'},{:newline,1,nil}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Lexer do | |
defmodule PIR do | |
require LexChar | |
defmacrop line(opts) do | |
quote do: elem(unquote(opts),1) | |
end | |
defmacrop file(opts) do | |
quote do: elem(unquote(opts),2) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/Documents/Programming/Active/elixakeet % iex -pa ebin | |
#Erlang R15B03 (erts-5.9.3.1) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false] | |
#Interactive Elixir (0.8.2.dev) - press Ctrl+C to exit (type h() ENTER for help) | |
iex(1)> Lexer.PIR.tokenize(""" | |
...(1)> # this is a comment, so the first line in the array will be a nl | |
...(1)> 'this is a str, the atom for it is :str' | |
...(1)> "this is also a string, but it probably looks weird with \\x31" | |
...(1)> 42 | |
...(1)> 133.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### Macros for character classing | |
defmodule LexChar do | |
@moduledoc "A collection of macros for checking character class" | |
defmacro is_digit(char) do | |
quote do: (unquote(char) >= ?0) and (unquote(char) <= ?9) | |
end | |
defmacro is_lower(char) do | |
quote do: (unquote(char) >= ?a) and (unquote(char) <= ?z) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sixModel | |
type Object struct { | |
refcount, id, flags int | |
_type_ byte | |
methods, attributes *map[string]*Object | |
data PolymorphicData | |
} | |
type PolymorphicData interface{} |