Erlang Programming/How To Do It Example
%this module have listable function such as rev and double
%%this function will reverse the result
%%this function will double the result
this is important example to know what is scope and context in erlang. i am using lot of variable with same name in different
function.there will be always error if you assign different value on same variable in same function context.
so here you can see there is different function context and variable scope in same module.
now i m going to define another module which is call quicksort with the help of list comprehension. i think with this example you will
be compatible with it. copy paste or make own self module and run it see what happens!!
%start copying module to list comprehension
erlang cmd compile and execute the module
it wil output 2,24,36
this is not perfect example but to know some thing about it is better.
explanation of list comprehension: if your are not good enough or beginner so you will not find it useful but for purpose its useful. write:[X||X<-F||X<S]. means X should be F but every element of X should not be bigger than S. X<-F is generator which generate X and X<S is filter which decide whose element is eligible to be in X. you can make lot of generator and filter. but filter nust have <- towards X which is going to output. more on list comprehension look at rf manual.