
#import <Foundation/Foundation.h> int main() parts := ['hello', 'world'] greeting := '' for String part in parts if part == parts[0] Locale myLocale = Locale.currentLocale greeting << part.capitalizedString else greeting << ' ' greeting << part Log('%@', greeting + '!') return 0 #import <Foundation/Foundation.h> @interface FileHelper : NSObject @property (readonly) NSString* name; @property (readonly) NSString* format; -(NSFileHandle*) openFile: (NSString*) path; -(NSFileHandle*) openFile: (NSString*) path withPermissions: (NSString*) permissions; @end @implementation FileHelper -(NSString*) name { return @"Macintosh"; } -(NSString*) format { return @"HFS+"; } -(NSFileHandle*) openFile: (NSString*) path { return [NSFileHandle fileHandleForReadingAtPath: path]; } -(NSFileHandle*) openFile: (NSString*) path withPermissions: (NSString*) permissions { NSFileHandle* handle = nil; if ([permissions isEqualTo: @"readonly"] || [permissions isEqualTo: @"r"]) { handle = [NSFileHandle fileHandleForReadingAtPath: path]; } else if ([permissions isEqualTo: @"readwrite"] || [permissions isEqualTo: @"rw"]) { handle = [NSFileHandle fileHandleForUpdatingAtPath: path]; } return handle; } @end #import <Foundation/Foundation.h> interface FileHelper String name {readonly} String format {readonly} openFile: String, [withPermissions: String], return FileHandle end implementation FileHelper name, return String = 'Macintosh' format, return String = 'HFS+' openFile: String path, withPermissions: String = 'readonly', return FileHandle = nil if permissions == 'readonly' or permissions == 'r' return FileHandle.fileHandleForReadingAtPath: path else if permissions == 'readwrite' or permissions == 'rw' return FileHandle.fileHandleForUpdatingAtPath: path end
Essentially, Eero is a powerful syntactic sugar for Objective-C, increasing readability, security, and reducing code. According to the author (Andy Arvanitis) , initially he just wanted to get rid of the brackets in Objective-C, and chose the name of the language when he saw the model of the pedestal table, which successfully performed its functions without unnecessary interfering legs. So, the language is named after the Finnish table architect Eero Saarinen . I am not strong in Finnish, but apparently the name should sound something like an “ero” with the accent on the first syllable.
First, in Eero, padding is used to select blocks instead of curly braces, as in Python. Semicolon at the end of instructions and definitions is not required. int count = 0 while ( count < 100 ) something = false count++ i++; j++
In Eero, sending messages is recorded using dot notation, for messages with no arguments, this is similar to the notation for properties. Arguments are passed after the colon, several arguments are separated by commas. id myarray = NSMutableArray.new myarray.addObject: myobject myarray.insertObject: myobject, atIndex: 0
Since an object cannot be represented in Objective-C except in terms of a pointer, in Eero all class type variables are treated as pointers, without using an asterisk (*) . NSString mystring = myobject.description NSString otherString = (NSString) someObject
When declaring local variables, you can omit their type, it will be automatically deduced from the assigned expression. To do this, use the special operator ": =". i := 100 mystring := myobject.description
Eero implements such a wonderful thing as namespaces . The “NS” prefix is ​​enabled by default, i.e. All types from the Foundation framework can be used without a prefix. mystring := String.stringWithUTF8String: "Hello, World" using prefix . using prefix AB ... theAddressBook := AddressBook.sharedAddressBook void AAPrint(String str) NSLog('AA: %@', str); void BBPrint(String str) NSLog('BB: %@', str); using prefix AA using prefix BB ... Print('test') // AA: test
In Eero, it is not necessary to specify the names of method arguments, in the case of omission, they are automatically determined from the selector. For example, in the following method, the arguments will be named bytes , length, and encoding : initWithBytes: const void*, length: UInteger, encoding: StringEncoding initWithBytes: const void*, length: UInteger, encoding: StringEncoding, return id interface MyClass openFile String, [withPermissions: String], return FileHandle end implementation MyClass openFile: String, withPermissions: String = 'r', return FileHandle handle := nil if permissions == 'r' handle = FileHandle.fileHandleForReadingAtPath: file else if permissions == 'w' or permissions == 'rw' handle = FileHandle.fileHandleForUpdatingAtPath: file return handle end implementation MyClass model, return String = 'G35' serialNumber, return String = 'X344434AABC' end
Properties are very simple to declare. Attributes are, if necessary, specified in curly braces. interface MyClass String name {nonatomic, copy} String desc {readonly} end
Indentation is used when defining blocks, and the caret "^" is not used. Compared to Objective-C syntax, blocks look very simple: myblock := (int x, int y) if x < 0 printf( "value was negative! (%d)\n", x ) x = 0 return x + y xyblock := (int x, int y | return x + y) descriptions := mylist.mapWith: (id element | return element.description)
Eero has operator overloading. Firstly, for all objects the operator "==" is an alias for the isEqual method. What is important primarily for readable and safe string comparison: mystring := MutableString.new mystring.appendString: 'Hello, World' if mystring == 'Hello, World' // , .. helloString := 'Hello' worldString := 'World' helloWorldString := helloString + ', ' + worldString mystring := '' mystring << 'Hello, World' | Operator | Selector | Note |
| + | plus: | Including operator + = |
| - | minus: | Including operator - = |
| * | multipliedBy: | Including operator * = |
| / | dividedBy: | Including operator / = |
| % | modulo: | Include operator% = |
| < | isLessThan: | |
| <= | isLessThanOrEqualTo: | |
| > | isGreaterThan: | |
| > = | isGreaterThanOrEqualTo: | |
| << | shiftLeft: | |
| >> | shiftRight: |

goto not allowed in the compiler level language. :)
#pragma mark ... , they are visible in the drop-down list.Source: https://habr.com/ru/post/129993/
All Articles