@yashigani
@interface Person {
NSString *_firstname;
NSString *_lastname;
}| struct User { | |
| let username: String | |
| } | |
| extension User: CustomStringConvertible { | |
| var description: String { return "username: \(username)" } | |
| } | |
| // DAO |
| enum N { | |
| case Zero | |
| indirect case Succ(N) | |
| static func succ(n: N) -> N { | |
| return .Succ(n) | |
| } | |
| } | |
| let zero: N = .Zero |
| final class Person { | |
| var name: String | |
| lazy var greeting: ImplicitlyUnwrappedOptional<String> = { | |
| return "Hello, \(self.name)" | |
| }() | |
| init(_ name: String) { | |
| self.name = name | |
| } | |
| } | |
| var p = Person("Steve") |
| enum N { | |
| case Zero | |
| indirect case Succ(N) | |
| init(_ n: UInt) { | |
| switch n { | |
| case 0: self = .Zero | |
| default: self = .Succ(N(n - 1)) | |
| } | |
| } |
| import Foundation | |
| public class JSON: Printable { | |
| private let object: JSONObject | |
| init(_ object: AnyObject?) { | |
| self.object = JSONObject.parse(object) | |
| } | |
| private init(_ object: JSONObject) { | |
| self.object = object | |
| } |
| // FizzBuzz by Enum | |
| enum FizzBuzz { | |
| case Fizz, Buzz, FizzBuzz, Other(Int) | |
| var state: String { | |
| switch self { | |
| case .Fizz: return "Fizz" | |
| case .Buzz: return "Buzz" | |
| case .FizzBuzz: return "FizzBuzz" | |
| case .Other(let i): return "\(i)" |
| use strict; | |
| use warnings; | |
| use 5.010; | |
| my $debug = $ENV{DEBUG} // 1; | |
| my $answer = int(1 + rand 100); | |
| say "answer is $answer" if $debug; | |
| GAME: { |
| enum Debug { | |
| case Log(Bool) | |
| func log(message: String) { | |
| switch self { | |
| case Log(true): | |
| println(message) | |
| case Log(false): | |
| return | |
| default: | |
| return |
| helloworld = "+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+." | |
| type Code = (String, String) | |
| type Pointer = ([Int], [Int], [Int]) | |
| parse :: Code -> Pointer -> Pointer | |
| parse ([], _) p = p | |
| parse ('>':xs, bs) p = parse (xs, '>':bs) $ incrementP p | |
| parse ('<':xs, bs) p = parse (xs, '<':bs) $ decrementP p | |
| parse ('+':xs, bs) p = parse (xs, '+':bs) $ increment p |