-
-
Save igauravsehrawat/376c71236de984b618c6 to your computer and use it in GitHub Desktop.
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
// Alternative JavaScript Syntax | |
Person = :(name, address) { @name!, @address! } | |
Person::inspect = :{ <: "{@name} lives at {@address}" } | |
tj := Person('TJ', '314 Bessborough ave') | |
bob := Person('Bob', 'Some place') | |
[tj, bob].each(:(person){ print(person.inspect()) }) |
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
// C | |
#include <stdio.h> | |
#include <string.h> | |
typedef struct Person { | |
char *name; | |
char *address; | |
} Person; | |
int | |
main () | |
{ | |
int i; | |
Person tj = { "TJ", "314 Bessborough ave" }; | |
Person bob = { "Bob", "Some place" }; | |
Person people[2] = { tj, bob }; | |
for (i = 0; i < 2; ++i) printf("%s lives at %s\n", people[i].name, people[i].address); | |
return 0; | |
} |
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
-- Haskell | |
data Person = Person { | |
personName :: String, | |
personAddress :: String | |
} | |
personInspect :: Person -> String | |
personInspect p = (personName p) ++ " lives at " ++ (personAddress p) | |
tj = Person "TJ" "314 bessborough ave" | |
bob = Person "Bob" "Some place" | |
people = map personInspect [tj, bob] | |
main = print (people) |
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
// JavaScript | |
Person = function(name, address) { | |
this.name = name | |
this.address = address | |
} | |
Person.prototype.inspect = function() { | |
return this.name + ' lives at ' + this.address | |
} | |
tj = new Person('TJ', '314 Bessborough ave') | |
bob = new Person('Bob', 'Some place') | |
each([tj, bob]), function(person){ | |
print(person.inspect()) | |
}) |
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
// PHP | |
<?php | |
class Person { | |
public function Person($name, $address) { | |
$this->name = $name; | |
$this->address = $address; | |
} | |
public function inspect() { | |
return $this->name . ' lives at ' . $this->address; | |
} | |
} | |
$tj = new Person('TJ', '314 bessborough ave'); | |
$bob = new Person('Bob', 'Some place'); | |
$map = array(); | |
foreach(array($tj, $bob) as $person) { | |
array_push($map, $person->inspect()); | |
} | |
print_r($map); |
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
# Ruby | |
class Person | |
attr_reader :name, :address | |
def initialize name, address | |
@name, @address = name, address | |
end | |
def inspect | |
"#{@name} lives at #{@address}" | |
end | |
end | |
tj = Person.new 'TJ', '314 bessborough ave' | |
bob = Person.new 'Bob', 'Some place' | |
people = [tj, bob].map { |person| person.inspect } | |
p people |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment