Skip to content

Instantly share code, notes, and snippets.

@igauravsehrawat
Forked from tj/person.ajs
Last active August 29, 2015 14:07
Show Gist options
  • Save igauravsehrawat/376c71236de984b618c6 to your computer and use it in GitHub Desktop.
Save igauravsehrawat/376c71236de984b618c6 to your computer and use it in GitHub Desktop.
// 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()) })
// 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;
}
-- 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)
// 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())
})
// 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);
# 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