18 September 2013

Scala Notes 8: keyword list ( reserved words )

Information:
List of  keywords (reserved words/keywords) based on  "The Scala Language Specification v 2.9 (DRAFT) from 24.5.2011)".
Definition based on:


Info  for Java folks.
There is no break* , continue , public keywords in Scala.


List of  keywords ( reserved words )
abstract - It makes a declaration abstract. It is not required for abstract members for most cases( I found case,where you need do that: http://stackoverflow.com/questions/2038370/scala-traits-and-abstract-methods-override ),but i don't why.

case - It starts clause for matched expression.

catch - It starts a clause for thrown exception.

class - It starts a class declaration.

def  - It starts a method declaration. 

do - it starts do-while loop.

else - it starts else clause for an if clause (when evaluation of if is false)

extends - it indicates  inheritance. that class or trait is   declared as child of the parent type of the class or trait.

false  -  one of Boolean's value.

final  - It addes "prohibit" attribute  .For class it means   prohibit inheritance and for method  prohibit   overriding.

finally - it starts clause after try/catch blocks (whatever exception is thrown or not).

for  - It starts for loop.

forSome -  According to O'reilly book( as I do not come across yet) :  Used in existential type declarations to constrain the allowed concrete types that can be used. 

if  - it starts if clause.

implicit - Marks a method as eligible to be used as an implicit type converter. Marks a method parameter as optional, as long as a type-compatible substitute object is in the scope where the method is called. 

import - it imports member(s) into the current scope. 


lazy - According to O'reilly book( as I do not come across yet) :   Defer evaluation of a val.

match - it starts pattern matching clause.

new - It creates a new instance of a class.

null  - It exists for compatibility and interoperability with Java and .NET libraries only. It means variable that has not been assigned a value.

object  - it starts signleton version of class (One instance only)

override - it indicates change of original member of class (like function etc. ) for non final members(See final for more details)

package - it starts declaration of package (scope)

private - it describes visibility of a declaration.

protected  - it describes visibility of a declaration. 

return -  a return from a function.

sealed - Applied to a parent class to require all directly derived classes to be declared in the same source file.(I do not come across this yet)


super  - An object refers to parent of itself.  (it is the same as this,but it binds into parent of a object 

this - An object refers to itself.

throw  - It indicates what type  exception  can be a thrown, if things went wrong.

trait - A mixin module that adds additional state and behavior to an instance of a class.

try - It starts scope of block of code that may throw an exception.

true  - one of Boolean's value.

type - It starts a type declaration.

val (value) - It starts declaration of  read-only variable.

var  (variable) -  It starts declaration of  read/write variable.

while - It starts a while loop (or starts while section of do/while loop). 

with - keyword is similar to Java’s implements keyword for interfaces. In Scala it includes the trait in class or object.

yield  -  is a result ( as collection ) from for loop (see http://pastorcmentarny.blogspot.co.uk/2013/06/scala-notes-10-yield-for-yield.html)

@  - It starts an annotation.

_  - it has many functions (it used in  many cases  like function literals , import ,place holder and etc.

:   - Separator between identifiers and type annotations. 

= - is an assignment 

<- - is used in for comprehensions in generator expressions. 

- is a unicode representation for <-.  [Unicode:  \u2190]


<: - It is used in abstract and  parametrized  type declarations ( It is used to constrain the allowed types).

<%  - It is used in abstract and   parametrized  type “view bounds” declarations. 


=> - It is used in function literals to separate the argument list from the function body. 

  is a unicode representation for =>.  [Unicode: \u21D2] 


>:  - It is used in abstract and  parametrized  type declarations ( It is used to constrain the allowed types).

# - it used in type projections (I do not come across yet)


List of  deprecated keywords ( reserved words )
requires - it was used for self-typing. (I didn't find why)


* break  appear in  Scala version 2.8  but it is implemented as a library method not as built-in break keyword.

No comments:

Post a Comment