Author Topic: kata  (Read 5338 times)

0 Members and 1 Guest are viewing this topic.


  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
« on: April 03, 2013, 04:23:19 am »
very important project.



intel asm:

 - mono:
Code: [Select]
apt-get install mono-csharp-shell mono-mcs mono-complete


- clojureScript =>
Code: [Select]
apt-get install clojure clojure-contrib
differences between lisp and clojure:


Code: [Select]
apt-get install erlang erlang-examples erlang-ssh erlang-tools erlang-manpages
erl -man io

Code: [Select]
apt-get install mercurial
hg clone -u release
cd go/src

Code: [Select]
apt-get install ghc6 ghc6-doc


Code: [Select]
apt-get install ruby-1.9.1-dev ruby-1.9.1 ruby-1.9.1-full ruby-1.9.1-examples

Code: [Select]
apt-get install guile-1.8

- book
- perl modules:




objective C:
Code: [Select]
apt-get install gobj


Code: [Select]
apt-get install gfortran gnustep


Code: [Select]
apt-get install gnu-smalltalk

guile scheme:
Code: [Select]
apt-get install guile

Code: [Select]
arm  C++      D2      golang   java  node.js  perl  python  rust
C    clojure  erlang  haskell  lua   ocaml    php   ruby    x86  r-project smalltalk fortran











typed coffee:


ref man:




  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #1 on: April 08, 2013, 08:30:58 pm »

# haskell suffix

# set prompt
:set prompt "ghci> "

# Not equal

# !

# lists
all elements of list must be same type

# join two lists
[1,2] ++ [3,4]

# prepend element to head of list (cons)
1 : [2,3]

# difference between '' and ""
=> "123"

# var func
let e = exp1

# Types have Capital letter
# variable starts with a lower case letter

# the last result

# insert module
:m +Module

# type
:type it
:type 3+2

# print types on everything
:set +t

# strongly typed
must explicitly coerce types if they are mismatched.

# Explicitly testing types (type signature)
1 :: Int
1 :: Char => fails..

# comparisons/tests
odd 1
compare 1 2
compare 'a' 'a'
(compare 1 1) == EQ

# Some list operators
head [1, 2, 3, 4]
tail ['a', 'b', 'c', 'd']
tail "list"
take 2 [1,2,3,4,5] => [1,2]
drop 3 [1,2,3,4,5] => [4,5]

# tuples : Can contain elements of different 'type'
(1, 'a', "hi")
(4, ['a', 'm'], (16, True))

# tuple functions

fst (1,2) => 1
snd (1,2) => 2

# passing an expression to a function
head (drop 4 "azerty")

# lines
lines "hi\nyou\n" => ["hi","you"]

# loading a module
:load bleh.hs

# variables in haskell
Once a variable is bound, it's value does not change.. much different than imperative langs

# non strict evaluation
haskell uses non-strict evaluation, opposite of C

Identifying a type variable
Type variables always start with a lowercase letter. You can always tell a type variable from a normal variable by context, because the languages of types and functions are separate: type variables live in type signatures, and regular variables live in normal expressions. No comments

It's common Haskell practice to keep the names of type variables very short. One letter is overwhelmingly common; longer names show up infrequently. Type signatures are usually brief; we gain more in readability by keeping names short than we would by making them descriptive.

defining types, streamlining functions.



  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #2 on: April 13, 2013, 05:10:18 pm »

perldoc bleh

the return from a subroutine determines it's context.

value context: describe's how perl interprets a piece of data
 == enforces numeric context
 eq enforces string context
 can coerce data to various contexts

 my $numeric_x =  0 + $x;  # forces numeric context  <-- ex: force numeric context
    my $stringy_x = '' . $x;  # forces string  context <-- force string context
    my $boolean_x =    !!$x;  # forces boolean context <-- force boolean context

the default scalar variable: $_
the default array variable: @_

many of perl's operators (chomp, chr, ord, lc, length, reverse, print, say, uc, etc) operate on the default scalar variable if no arguments are provided.

use $_ as you would "it" in language

@_ , shift,pop

<$FH> -> equivalent to readline

Variable names always have a leading sigil (or symbol) which indicates the type of the variable's value. Scalar variables (Scalars) use the dollar sign ($). Array variables (Arrays) use the at sign (@). Hash variables (Hashes) use the percent sign (%):

the context of the lvalue can dictate the result, ie, my $first = $hash { $key }; will give $first the first element in the hash

- perl uses :: for namespaces, Blah::bleu
- all namespaces are globally visible

By convention, packages all start with an uppercase letter.

Lexical scope governs the visibility of variables declared with my—lexical variables. A lexical variable declared in one scope is visible in that scope and any scopes nested within it, but is invisible to sibling or outer scopes

You may provide a block to the package declaration:
package Store::Toy
        my $discount = 0.10;

  my $name    = 'Donner Odinson, Bringer of Despair'; <-- Literal string, interpreted literally
    my $address = "Room 539, Bilskirnir, Valhalla"; <-- with double quoted, you can encode \t, \n, \r, \f, \b, etc

A string declaration may cross logical newlines

concatenator operator: .

quote operators: qq (double quoting), q (single quoting)
 qq{ "hi" ok eh }
 q{testing ..}

heredoc syntax for large strings:
 my $k =<< 'EOF'
EOF <-- must start at the beginning of the line

modifying file handle: binmode $fh, "mode"
encoding/decoding strings etc. encode() decode()

use underscores instead of commas for large numbers (if you want to separate fields): my $billion = 1_000_000_000

undef value represents an unassigned, undefined, and unknown value.
- undef is false in boolean context

() = empty list

parenthesis do not create lists, commas create lists

range operator to create lists:
my @chars = 'a' .. 'z';
    my @count = 13 .. 27;

Use the qw() operator to split a literal string on whitespace to produce a list of strings:
    my @stooges = qw( Larry Curly Moe Shemp Joey Kenny );

postfix if: say "blah" if $y == 1;
block if: if ($y == 1) { ... }

unless, negated form of if
- blah unless $y == 1;

else if = elsif

terniary conditional operator exists: my $h = 1 ? bleh : blah;

foreach (1 .. 10)
for my $i (1 .. 10)
for (my $i = 0; $i <= 10; $i += 2)

next bleh ...The next statement restarts the loop at its next iteration.
last bleh ... Ends loop immediately
redo bleh ... The redo statement restarts the current iteration without evaluating the conditional again
continue bleh .. The continue construct behaves like the third subexpression of a for loop;
given bleh... The given construct is a feature new to Perl 5.10. It assigns the value of an expression to the topic variable and introduces a block


while(1) {
 next NEXT true;

Iteration and Scoping
Iterator scoping with the topic variable provides one common source of confusion. Consider a function topic_mangler() which modifies $_ on purpose. If code iterating over a list called topic_mangler() without protecting $_, debugging fun would ensue:

Code: [Select]
    for (@values)

    sub topic_mangler

If you must use $_ rather than a named variable, make the topic variable lexical with my $_:

Code: [Select]
    sub topic_mangler
        # was $_ = shift;
        my $_ = shift;


        return $_;

Using a named iteration variable also prevents undesired aliasing behavior through $_.

Code: [Select]
for (
        # loop initialization subexpression
        say 'Initializing', my $i = 0;

        # conditional comparison subexpression
        say "Iteration: $i" and $i < 10;

        # iteration ending subexpression
        say 'Incrementing ' . $i++
        say "$i * $i = ", $i * $i;

given / when:
Code: [Select]
given (shift)
            when (/paper/)    { say 'You win!' };
            when (/rock/)     { say 'We tie!'  };
            when (/scissors/) { say 'I win!'   };
            default           { say $confused  };

tail calls:
A tailcall occurs when the last expression within a function is a call to another function—the outer function's return value is the inner function's return value
sub bleh { return blah(); |

The builtin goto operator has a form which calls a function as if the current function were never called, essentially erasing the bookkeeping for the new function call.
goto &function;

chomp: Use the chomp builtin to remove line-ending characters from each line. Many novices forget this.


Perl 5's fundamental data type is the scalar, a single, discrete value. That value may be a string, an integer, a floating point value, a filehandle, or a reference—but it is always a single value. Scalars may be lexical, package, or global (Global Variables) variables.

declare array:
- my @array;

index an array, always use scalar sigill
- $array[1]

last index of array:
- $#array;
- $array[-1]

index elements 'from the end':
- $array[-x] <- negative index

If you assign to an index beyond the array's current bound, Perl will extend the array to account for the new size and will fill in all intermediary positions with undef

Assigning to a scalar element of an array imposes scalar context, while assigning to the array as a whole imposes list context.

to clear an array:
- @array = ();

array operators:
- push : push to tail of array
- pop : pop tail of array

unshift : prepends a list of elements to the start of the array and returns the new number of elements in the array.
shift : removes and returns the first element of the array.

The splice operator removes and replaces elements from an array given an offset, a length of a list slice, and replacements. Both replacing and removing are optional; you may omit either behavior
my ($winner, $runnerup) = splice @finalists, 0, 2;

Array slices:
- my @blah = @array[1,5]

magic global: $" ... usually a single space

Code: [Select]
# what's in this array again?
    local $" = ')(';
    say "(@sweet_treats)";
    (pie)(cake)(doughnuts)(cookies)(raisin bread)


A hash is a first-class Perl data structure which associates string keys with scalar values

Hashes have two important properties:
1) they store one scalar per unique key
2) they provide no specific ordering of keys.

Declaring a hash:
my %hash;

Assigning values to keys:
$hash{'key'} = value;

Assign multiple values in one statement:
my %hash = {
 'bleh' => blah

Novices often always quote string literal hash keys, but experienced developers elide the quotes whenever possible. In this way, the presence of quotes in hash keys signifies an intention to do something different.

use the exists keyword on hashes to figure out if a key exists.

Using exists instead of accessing the hash key directly avoids two problems. First, it does not check the boolean nature of the hash value; a hash key may exist with a value even if that value evaluates to a boolean false (including undef):

keys operator: provides a list of keys

values operator: provides a list of values

each operator: The each operator produces a list of two-element lists of the key and the value:
- my ($addressee, $address) = each %addresses

reset hash iterator:
- keys %blah;

merging two hashes:
Code: [Select]
Hash slices make it easy to merge two hashes:

    my %addresses        = ( ... );
    my %canada_addresses = ( ... );

    @addresses{ keys   %canada_addresses }
              = values %canada_addresses

Locking Hashes
As hash keys are barewords, they offer little typo protection compared to the function and variable name protection offered by the strict pragma. The little-used core module Hash::Util provides mechanisms to ameliorate this.

To prevent someone from accidentally adding a hash key you did not intend (whether as a typo or from untrusted user input), use the lock_keys() function to restrict the hash to its current set of keys. Any attempt to add a new key to the hash will raise an exception. This is lax security suitable only for preventing accidents; anyone can use the unlock_keys() function to remove this protection.

Similarly you can lock or unlock the existing value for a given key in the hash (lock_value() and unlock_value()) and make or unmake the entire hash read-only with lock_hash() and unlock_hash().


All global variables and functions declared or referred to after the package declaration refer to symbols within the MyCode namespace. You can refer to the @boxes variable from the main namespace only by its fully qualified name of @MyCode::boxes.

Every package declaration creates a new namespace if necessary and causes the parser to put all subsequent package global symbols (global variables and functions) into that namespace.

To modify the value by reference, use the \ sigill and then the double $$ sigill to modify it:

Modifying a value in place, or returning a reference to a scalar can save memory. Because Perl copies values on assignment, you could end up with multiple copies of a large string. Passing around references means that Perl will only copy the references—a far cheaper operation.

Perl does not offer native access to memory locations. The address of the reference is a value used as an identifier. Unlike pointers in a language such as C, you cannot modify the address or treat it as an address into memory. These addresses are only mostly unique because Perl may reuse storage locations as it reclaims unused memory.

Use the reference operator to create a reference to a declared array:

    my @cards     = qw( K Q J 10 9 8 7 6 5 4 3 2 A );
    my $cards_ref = \@cards;
Any modifications made through $cards_ref will modify @cards and vice versa. You may access the entire array as a whole with the @ sigil, whether to flatten the array into a list or count its elements:

    my $card_count = @$cards_ref;
    my @card_copy  = @$cards_ref;

Hash references

my $hash_Ref = \%hash;
my $x = \%hash_ref;
my $keys = $%hash_ref;
$hash_Ref{'key'} = ...

Function References

sub bleh { print "hi" };
my $fn = \&bleh;

When you attempt to write to a component of a nested data structure, Perl will create the path through the data structure to the destination as necessary:

    my @aoaoaoa;
    $aoaoaoa[0][0][0][0] = 'nested deeply';
After the second line of code, this array of arrays of arrays of arrays contains an array reference in an array reference in an array reference in an array reference. Each array reference contains one element. Similarly, treating an undefined value as if it were a hash reference in a nested data structure will make it so:



  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #5 on: April 27, 2013, 08:03:08 pm »

shit i just lost all of the python notes i added in here.. instead going to just copy and paste stuff:

def fn(params):
  """ doc string """

everything in python is an object

print fn.__doc__

statically typed language
A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages.
dynamically typed language
A language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.
strongly typed language
A language in which types are always enforced. Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.
weakly typed language
A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.

find out which module you are in:
print __name__


>>> d = {"server":"mpilgrim", "database":"master"}
>>> d
{'server': 'mpilgrim', 'database': 'master'}
>>> d["server"]                                   

>>> del d[42]
>>> d
{'server': 'mpilgrim', 'uid': 'sa', 'database': 'master', 'retrycount': 3}
>>> d.clear()

del d["server"]

li = ["a", "b", "mpilgrim", "z", "example"]
>>> li
['a', 'b', 'mpilgrim', 'z', 'example']
>>> li[0]                                       

>>> li[-1]

>>> li[1:3] 
['b', 'mpilgrim']

['a', 'b', 'mpilgrim', 'z', 'example']
>>> li[:3]
['a', 'b', 'mpilgrim']
>>> li[3:] 
['z', 'example']
>>> li[:] 
['a', 'b', 'mpilgrim', 'z', 'example']

extend & append
>>> li
['a', 'b', 'mpilgrim', 'z', 'example']
>>> li.append("new")               
>>> li
['a', 'b', 'mpilgrim', 'z', 'example', 'new']
>>> li.insert(2, "new")           
>>> li
['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new']
>>> li.extend(["two", "elements"])
>>> li
['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']

['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']
>>> li.index("example")

['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']
>>> li.remove("z")

concatenating lists:
['a', 'b', 'mpilgrim', 'example', 'new']
>>> li += ['two']

A tuple is an immutable list. A tuple can not be changed in any way once it is created.

>>> t = ("a", "b", "mpilgrim", "z", "example")
>>> t
('a', 'b', 'mpilgrim', 'z', 'example')
>>> t[0] 

   You can't add elements to a tuple. Tuples have no append or extend method.
   You can't remove elements from a tuple. Tuples have no remove or pop method.
   You can't find elements in a tuple. Tuples have no index method.
   You can, however, use in to see if an element exists in the tuple.
So what are tuples good for?

Tuples are faster than lists. If you're defining a constant set of values and all you're ever going to do with it is iterate through it, use a tuple instead of a list.
It makes your code safer if you “write-protect” data that does not need to be changed. Using a tuple instead of a list is like having an implied assert statement that shows this data is constant, and that special thought (and a specific function) is required to override that.
Remember that I said that dictionary keys can be integers, strings, and “a few other types”? Tuples are one of those types. Tuples can be used as keys in a dictionary, but lists can't be used this way.Actually, it's more complicated than that. Dictionary keys must be immutable. Tuples themselves are immutable, but if you have a tuple of lists, that counts as mutable and isn't safe to use as a dictionary key. Only tuples of strings, numbers, or other dictionary-safe tuples can be used as dictionary keys.
Tuples are used in string formatting, as you'll see shortly.

 v = ('a', 'b', 'e')
>>> (x, y, z) = v     
>>> x

[0, 1, 2, 3, 4, 5, 6]

concat srings:
k = "uid"
>>> v = "sa"
>>> "%s=%s" % (k, v)


 li = [1, 9, 8, 4]
>>> [elem*2 for elem in li]     
[2, 18, 16, 8

mappings: The keys, values, and items Functions
>>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
>>> params.keys()   
['server', 'uid', 'database', 'pwd']
>>> params.values()
['mpilgrim', 'sa', 'master', 'secret']
>>> params.items() 
[('server', 'mpilgrim'), ('uid', 'sa'), ('database', 'master'), ('pwd', 'secret')]

object orientation

ways to import modules:

 import module
 from Module import Module

the second syntax:
This is similar to the import module syntax that you know and love, but with an important difference: the attributes and methods of the imported module types are imported directly into the local namespace, so they are available directly, without qualification by module name. You can import individual items or use from module import * to import everything.

defining classes

class Something:

'pass' keyword, empty statement

parent classes
class FileInfo(UserDict):
   In Python, the ancestor of a class is simply listed in parentheses immediately after the class name. So the FileInfo class is inherited from the UserDict clas

constructor: __init__

 class Ok:
  """ ok """
  def __init__(params):
    print "hi\n"

class Ok:
  def __init__(self, params=None):
   print self.params
  def rage():
   print "Raging";

n = Ok()

class: special methods

def __getitem__(self,key): ...
def __setitem__(self,key):...

repr, cmp, delitem, len,

private class elemnents:
Private functions, which can't be called from outside their module
Private class methods, which can't be called from outside their class
Private attributes, which can't be accessed from outside their class.


...     fsock = open("/notthere")       
... except IOError:                     
...     print "The file does not exist, exiting gracefully"
... print "This line will always print"


   This is new: a try...finally block. Once the file has been opened successfully by the open function, you want to make absolutely sure that you close it, even if an exception is raised by the seek or read methods. That's what a try...finally block is for: code in the finally block will always be executed, even if something in the try block raises an exception. Think of it as code that gets executed on the way out, regardless of what happened before.



>>> pattern = '^M?M?M?$'
>>>, 'MM'


  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #6 on: May 10, 2013, 07:16:59 am »


  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #7 on: August 27, 2013, 02:51:38 am »

since im so busy at work & it's hard for me to focus on big projects.. I'm resuming this project.

Tonight I made my "hello world's" for each language:

Code: [Select]
arm  C++      D2      golang   java  node.js  perl  python  rust
C    clojure  erlang  haskell  lua   ocaml    php   ruby    x86  r-project smalltalk fortran objective-C

ok well, arm/x86 aren't done yet.. need to figure out what im going to code on for ARM, maybe get a raspberry pi or something.. or use qemu

i might add a few more languages to the mix.. any suggestions? i crossed out C# and scala, not really into the .NET stuff.

This is going to be such a fun project.. i've wanted to do this for a long time, now it's time to focus on it.

maybe I should add a databases folder to the kata project? With redis, mongo, mysql, ... or maybe i should just interface them from the languages above (sounds better).



  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #8 on: August 28, 2013, 08:53:08 am »

quick reference docs:


package managers:

redis_1 : playing with redis libraries for various languages
  • C (hiredis)
  • clojure
  • golang
  • D
  • erlang

Stuff i'm currently reading for learning these langs.

In progress:

 - leftoff:
 - leftoff:
golang :
 - leftoff:
 - leftoff:
erlang: "Introducing erlang"
 - leftoff:
erlang : ""
 - leftoff:
c++ : C++ Primer, 5th edition
 - leftoff: C2
haskell :
 - leftoff: 3. Types, Typeclasses, and Polymorphism
haskell: ,
 - leftoff:
elixir :
 - leftoff:
smalltalk: The Blue Book :
 - leftoff:
smalltalk :
 - leftoff: C4
guile :
 - leftoff:
objective C:
 - leftoff:
python : Learning python - 4th edition
 - leftoff:
python : diving in :
 - leftoff :
python : think python
 - leftoff : CH 2
ruby: computer science programming basic in ruby
 - leftoff:
java : learning java, 4th edition
 - leftoff:
ocaml :
- leftoff:
 - leftoff:
 - leftoff:

scala: effective scala :
 - leftoff:
perl :
 - leftoff:

08/31/2013 : clojure :
08/31/2013 : erlang :
09/02/2013: scala :

libraries and stuff:

 - go :
 - go :
 - go :
- c :
- c :

 - go :



perl redis:

python redis:


php redis:

java redis:

rust redis:

native php modules:

rust kernel modules:

go worker:


  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email
Re: kata
« Reply #9 on: September 01, 2013, 08:31:34 pm »


  • Administrator
  • Hero Member
  • *****
  • Posts: 30104
  • who run it.
  • Respect: +7286
    • View Profile
    • Email