Monday, 31 August 2015

Tool Command Language- Lecture 9 (files)

In this lecture we will see how to read file from disk
The general format is as 

open file _name access permission 

access is the access mode

r.... open the file for reading . The file must b present.
r+...open a file for reading and writing.
w.. open the file for writing. create the file if it is not present.
w+.. open file for reading and writing.. create if not present.
a.. open file for writing . it must be present their.
a+.. open file for writing and create it if not present their.

permission :

permission is an integer to use  to set the file access permissions

close fileID:

closes the file that has been already created.

gets fileID varnamee:

reads a line from fileID and discards the terminating newline.

puts ? -nonewline? fileID string

writes in file.

Examples:
i have a file abc.text in this location \hoome\masroor.
a:
set ns
open \home\masroor\abc  r 
returns file3 which is file id
now i will use this id to close file
close file3

b:
open /home/masroor/abc w+
puts file4 "i hate this "
close file4


Saturday, 29 August 2015

Tool Command Language- Lecture 8 ( search list)

Use of lsearch , lindex and lsort 
a)- lsearch

syntax.
set list {{item1} [item2}...}
set variable [lsearch  $list  item]
it will return index of item. Remember it starts from 0.
Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
set x [lsearch $p "python 2000"]

puts $x 

out put : 2
Note: if output is -1 then the searched value is not present in list.

b) - lindex

syntax.
set list {{item1} [item2}...}
puts [lindex  $list  index(number)]
it will return value at index in list .

Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
puts  [lindex $p 3]
out put : tcl 2005

c)-lsort
syntax.
set list {{item1} [item2}...}
lsort $list
Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
lsort  $p
out put : {c 1987} {java 1991} {python 2000} {tcl 2005}


Thursday, 27 August 2015

Tool Command Language - lecture 7 - Functions

The syntax of function or procedure in tcl is as
                
proc function_name { arguments } {
             body 
             return 
    } 
    Example
 proc add { a b } {
 return [expr $a + $b ]
  }
 set c [add 3 2 ]

 out put  5
 Here we have declared a function or most appropriate a  procedure  named as add, with arguments as a,b. Later we set a variable c and  we call the above function with two arguments. In return we obtain  sum of  these two arguments and that is assigned to c . 



Tool Command Language- Lecture 6 ( "for" loop )

For Loop:
The Syntax of "For" loop in Tcl is as
for {set variable value } {text condition }{ change value}{
body of loop 
}
Example :

for {set x 0 } { $x < 5 } {incr x} { 
puts " value of x : $x " 
}
Out Put:
value of x : 0
value of x : 1
value of x : 2
value of x : 3
value of x : 4

Wednesday, 26 August 2015

Create a Frame In java

import javax.swing.*;   
// swing class is placed in the javax.swing package
public class Main
{
    public static void main(String[] args)
{
EmpetyFrame f = new EmpetyFrame();
// we create a sub class wd class name EmpetyFrame
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// exit upon close event operation
   f.setVisible(true); 
// to show the frame main method calls setvisible method
}
}
class EmpetyFrame extends JFrame
{
public EmpetyFrame( ) // constructor sets size
{
setSize(default_width,default_height);
}
public static final int default_width = 300;
public static final int default_height = 300;
}

Tool command Language - lecture 5. (looping )

While loop:
The syntax of while loop in tcl is as
while {text condition } {
 body of loop
}  
 Example :
 set x 3
 while {$x <6} {
 incr  x 
 puts $x 
 }
                         
here the condition is ist checked and then inside loop value of x is increment by 1. when value of x becomes 6, then condition becomes false and the loop terminates.                

Tuesday, 25 August 2015

Tool Command language -Lecture 4(Use of Switch)

The use of Switch replaces multiple if-else. The syntax is as 
  
switch string pattern 1 body 1 pattern 2 body 2 ... pattern n body n
                                    or
switch string {pattern 1 body 1 pattern 2 body 2... pattern n body n}
example :

set x one
switch $x "ONE" "puts ONE=1" "two" "puts 2"
           or           
set c hate  
switch  $c {
"love" {
puts "i hate u"
 }
"hate" {
 puts "i know"
        }
     }


Monday, 24 August 2015

Tool Command Language - lecture 4 (Decision making and branching )

1. if - else

The syntax of if-else in tcl is as.
if { statement 1 } {statement 2} else {statement 3}
example
set x 10
if { $x == 2 } {puts "hello } else { puts "bye" }
  will print bye
we can also write it like 
if { $x == 2 } {
puts "hello 
else {
 puts "bye" 
 }

Saturday, 22 August 2015

Tool command Language - Lecture 3 ( Operators )

Operators in tcl are same as in other languages like c, c++.
Tcl supports following operators. 
        
  Arithmetic Operators (+, - , *, /,%)
 Relational Operators(==, !=, < , > , >=)
 Bitwise Operators(&,|,^)
 Ternary Operators(?:)
 Logical Operators(&&, || , !)

Here if we have two variables say x and y
   we write in tcl command prompt 
       set x 10
       set y 12
 puts c [expr $x +$y] will print c as 22. 

similarly  we can use relational operators in following manner
                while{$x < 13 } {  
                  incr x  
                  puts $ y
              }
   
  #Remember syntax.

For Ternary operator we have like c as 
      expression 1 ? expression 2 : expression 3.
if after evaluating  expression 1 , it is true then expression 2 will be evaluated. example
  set x 3
set y [expr ($x>4)?"x is greater than 4":"x is less than 4"]
will print " x is less than 4"

Wednesday, 19 August 2015

Tool Command language (Tcl) .. Second lecture ( lists )

Lists

List is nothing but a group of elements. A group of words either using double quotes or curly braces

set x { red green blue }
    Here we have put three variables in list .

puts [lindex $x 2 ]
      Here we will get print blue.
  

Tuesday, 18 August 2015

Difference between 32 bits and 64 bits os.

The main difference is that a 32 bit os/processor can process 2^32 addresses and at a time can access 32 bits from memory. Here data handle/processed(data being processed internally )  by cpu is of width 32 bits.

Tool Command language (Tcl) .. First lecture ( variable declaration )

Variable Declaration 

  In c prog language  when we  declare some variable , we write 
  int x = 3;

  But in Tcl we write
  set x 3;
         "here it is stored as string"
  No need to declare just assign a value to variable. This  statement     will create a variable name x and store it as string.
          Now if we write
puts [expr $x + 5] #  we can also use (put)
      here x is automatically converted into int.
 Now to print x we will write


puts $x .. Answer will be 8 ( as expr above does addition operation)







Grammar Mistakes in Technical Paper Writing

Let me share some experience in this post with you. I'm currently in the second year of my Ph.D. program. We are in the middle of paper...