Lists in Scheme Explained.

May 30, 2008

Lists

Lists can be built using pairs. A list is denoted by a collection of items enclosed in parentheses, e.g.

(2 4 6 8 10)

In other words, a list is a chain of pairs ending in the empty list. If the chain of pairs does not end with the empty list, the list is said to be improper. An improper list is not a list!

The empty list is denoted (). The list (2 4 6 8 10) is the same as (2 . (4 . (6 . (8 . (10 . ()))))). An improper list can be represented using dotted notations in the following way: (2 4 6 8 . 10), which is equivalent to (2 . (4 . (6 . (8 . 10)))).

Note that lists should be quoted when fed to the interpreter, otherwise the interpreter will try to apply the first item in the list to the other items in the list, e.g.

> (2 4 6 8 )
procedure application: expected procedure, given: 2; arguments were: 4 6 8
> '(2 4 6 8 )
(2 4 6 8 )

Lists can be constructed using cons in the following way:

(cons 2 (cons 4 (cons 6 (cons 8 (cons 10 '())))))

Note that

(cons 1 (cons 2 '()))

is a list, whereas

(cons 1 2)

is not. The latter is a pair. A list is constructed from pairs and is consiedered a pair, but a pair is not in itself a list! The empty list is, however, not a pair.

Lists can also be constructed using the procedure list as follows:

(list 2 4 6 8 10)

If we wish to take lists apart, we can use car and cdr and combinations thereof. For example:

>(car (list 2 4 6 8 10))
2

whereas

>(cdr (list 2 4 6 8 10))
(4 6 8 10)

The result of applying cdr to a list is always a list.

Let’s say that we want to extract the second element in the list. In order to accomplish this we can combine car and cdr in the following way:

>(car (cdr (list 2 4 6 8 10)))
4

There is a shortening for combined car:s and cdr:s. The same could be accomplished as follows:

>(cadr (list 2 4 6 8 10))
4

car:s and cdr:s can be combined four times. Hence, the following combinations exist:

(caar ls)   ; is the same as (car (car ls))
(cadr ls)    ; is the same as (car (cdr ls))
(cdar ls)    ; is the same as (cdr (car ls))
(cddr ls)   ; is the same as (cdr (cdr ls))
(caaar ls) ; is the same as (car (car (car ls)))
(caadr ls) ; is the same as (car (car (cdr ls)))
(cadar ls) ; is the same as (car (cdr (car ls)))
(caddr ls) ; is the same as (car (cdr (cdr ls)))
(cdaar ls) ; is the same as (cdr (car (car ls)))
(cdadr ls) ; is the same as (cdr (car (cdr ls)))
(cddar ls) ; is the same as (cdr (cdr (car ls)))
(cdddr ls) ; is the same as (cdr (cdr (cdr ls)))
(caaaar ls); is the same as (car (car (car (car ls))))
(caaadr ls); is the same as (car (car (car (cdr ls))))
(caadar ls); is the same as (car (car (cdr (car ls))))
(caaddr ls); is the same as (car (car (cdr (cdr ls))))
(cadaar ls); is the same as (car (cdr (car (car ls))))
(cadadr ls); is the same as (car (cdr (car (cdr ls))))
(caddar ls); is the same as (car (cdr (cdr (car ls))))
(cadddr ls); is the same as (car (cdr (cdr (cdr ls))))
(cdaaar ls); is the same as (cdr (car (car (car ls))))
(cdaadr ls); is the same as (cdr (car (car (cdr ls))))
(cdadar ls); is the same as (cdr (car (cdr (car ls))))
(cdaddr ls); is the same as (cdr (car (cdr (cdr ls))))
(cddaar ls); is the same as (cdr (cdr (car (car ls))))
(cddadr ls); is the same as (cdr (cdr (car (cdr ls))))
(cdddar ls); is the same as (cdr (cdr (cdr (car ls))))
(cddddr ls); is the same as (cdr (cdr (cdr (cdr ls))))

For example:

>(caddr (list 2 4 6 8 10))
6
>(car (cdr (cdr (list 2 4 6 8 10))))
6

These procedures can also be combined if the standards ones are insufficient. For example:

> (define ls '(((((((1 2) 3) 4) 5) 6) 7) 8))
> (caaaar ls)
(((1 2) 3) 4)
> (car (caaaar ls))
((1 2) 3)
> (cdaar (caaaar ls))
(2)

Scheme also provides the procedures set-car! and set-cdr! for explicitly changing the value of the car or cdr of a list. This is done as a side effect and the return value is unspecified.

> (define ls (list 1 2 3 4 5))
> ls
(1 2 3 4 5)
> (set-car! ls 10)
> ls
(10 2 3 4 5)
> (set-cdr! ls '())
> ls
(10)

Note that lists created in the following way cannot be changed using set-car! or set-cdr!:

> (define ls '(1 2 3 4 5))

This is because ls is now a list constant that cannot be changed. Don’t be tempted to do it incorrectly even if the implementation allows it.

Care should be taken when using set-car! and set-cdr!. For example: when using set-cdr!, we may run into situations in which the object is a list at first, but after application of set-cdr! it is not.


Program to display fibonacci series in Scheme

May 30, 2008

(define a 0) ;define initial values of the series a=0
(define b 1) ;define second initial value b=1
(define c 0) ;the next item in the series – initialised to 0 but will change as we move along the series

;;function to display the number of items user wants in series(**loops is not a keyword**)
;;loops is the name of the fucntion
(define (loops z)
(if (= z 2) ;;comparing it with 2 because first 2 items of series we already have (**namely a and b**)
;;as soon as z equals 2 the series ends as we are decrementing z
(begin
(newline)
(display “end of series”))

;;if z is not equal to 2 call the function fab(a b) to calculate and display the next item in the series.
(begin
(fab a b)
(loops (- z 1))) ;;decrement z by 1 each time an item is printed
)
)

;;function to calculate next item in the series and display it
;;also displays the first 2 items i.e. a and b at the start of the series
;;logic is same as that in ‘C/C++’
(define (fab x y)
(if ( and (= a 0) (= b 1))
(begin
(display a)
(display ” “)
(display b)
(display ” “)
)
(begin
(display ” “)
))
(begin
(set! c (+ x y))
(display c)
(display ” “)
(set! a b)
(set! b c)
))
;;end of fucntion

;;ask user for the number of elements he wants in the series.
(display “Enter the Number of Numbers you want :- “)
;;read user input
(define ite (read))
;;call loops fucntion (**loops is not a keyword.it is a user defined fucntion
(loops ite)


Program to reverse a number in Scheme Programming Language

May 30, 2008

(define rev 0) ; initialize reverse of number as 0
(define rem 0) ;initialize remainder as 0
;;read the number from the user.
(display “Enter number whose reverse you want to find :- “)
(define n (read))
;;define the function reverse to reverse the number
;;the logic inside is same as that in ‘C/C++’
(define (reverse n)
(if (> n 0)
(begin
(set! rem (remainder n 10))
(set! rev(+ (* rev 10) rem))
(set! n (floor (/ n 10)))
(reverse n))
;;else part of the if loop begins
(begin
(display “The reverse is :- “)
(display rev)
);end of else part of if loop
);end of if loop
);end of function definition
(reverse n) ;calling the reverse function with the number entered by the user.


Vectors in Scheme Explained

May 30, 2008

(display “enter the length of the vector you want to create :- “)
(define a(read)) ; reading vector length from user
(define len 0) ; defining length of vector as 0

(define v(make-vector a)) ;making a vector of length a(a- entered by user)(**make-vector is a keyword**)

(define (initvector n) ; function to ask user for values of each element of the vector
(let loop ((i 0) (x 0)) ; creating local variables i and x and assiging 0 (**loop is not a keyword**)
(if (< i n) ;checking for i < n
(begin
(display “Enter element of vector.Element Number “)
(display (+ i 1))
(display “:- “)
(set! x(read)) ;reading value entered by user into local variable x
(vector-set! v i x) ;assigning the value x to index i of vector v
;incrementing i to next index of the vector v and setting x to 0 (** you have to set both local variables
(loop (+ i 1) (= x 0))
);end of begin
);end of if
);end of let loop statement
);end of initvector function
(initvector a)

(display v)


Removing G.O.D Saikoboy trojan

May 30, 2008

Removing G.O.D Saikoboy trojan

This notorious trojan (which spreads by exploiting the autorun feature in Windows OS) locks the taskbar, taskmanager as well as registry editing.  To enable all the above features and to remove the irritating G.O.D Saikoboy’s Internet explorer message that comes at the top of your IE – read on
(1) Unlock Task Manager
Goto Start -> Run and copy and paste this code (in one line)
REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v           DisableTaskMgr /t REG_DWORD /d 0 /f
(2) Unlock Registry Editor
REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v                             DisableRegistryTools /t REG_DWORD /d 0 /f
(3) Using Registry Editor, delete the following value in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Window Title
Next, Open the task manager you will find two processes with the name svchost.exe
one has the user name “SYSTEM” and the other has your user name (login ID) end the process “svchost.exe” which have your user name beside it (it is a trojan)
Then go to C: and find a hidden file called CONFIG (not config.sys) and delete it


Program To add 2 complex Numbers in Scheme

May 30, 2008

Here we will be Using Structures to add two Complex numbers in Scheme Programming Language.

Structures in Scheme are similar to those in ‘C/C++’.

First you define the structure and then you create instances of it.

(define-struct complex (real imag)) ; defining the structure.
(define c1(make-complex 6 3)) ; creating an instance d1 and assigning the values
(define c2(make-complex 3 4));another instance d2
(define (complexadd d1 d2) ; function to add
(make-complex  (+ (complex-real d1) (complex-real d2))
(+ (complex-imag d1) (complex-imag d2)))

)
(define csum (complexadd c1 c2)) ; creating the 3rd complex number which will store the result and calling complexadd function

(complex-real csum) ;displaying real part
(complex-imag csum) ;displaying imaginary part.

As soon as line 1 is read by Dr. Scheme it creates a constructor called “make-complex” to make new instances of structure complex and 2 accessor functions called “compex-real” and “complex-imag” to access the two variables/values of every instance of the complex type.


Vectors in Scheme Explained.

May 30, 2008

Vectors

Vectors are heterogenous structures whose elements are indexed by integers. A vector typically occupies less space than a list of the same length, and the average time required to access a randomly chosen element is typically less for the vector than for the list.

The length of a vector is the number of elements that it contains. This number is a non-negative integer that is fixed when the vector is created. The valid indexes of a vector are the exact non-negative integers less than the length of the vector. The first element in a vector is indexed by zero, and the last element is indexed by one less than the length of the vector.

Vectors are written using the notation #(obj …). For example, a vector of length 3 containing the number zero in element 0, the list (2 2 2 2) in element 1, and the string “Anna” in element 2 can be written as following:

  #(0 (2 2 2 2) "Anna")

Note that this is the external representation of a vector, not an expression evaluating to a vector. Like list constants, vector constants must be quoted:

  '#(0 (2 2 2 2) "Anna")  =>  #(0 (2 2 2 2) "Anna")
[[procedure]] (vector? obj)

Returns #t if obj is a vector, otherwise returns #f.

[[procedure]] (make-vector k)
[[procedure]] (make-vector k fill)

Returns a newly allocated vector of k elements. If a second argument is given, then each element is initialized to fill. Otherwise the initial contents of each element is unspecified.

[[library procedure]] (vector obj ...)

Returns a newly allocated vector whose elements contain the given arguments. Analogous to list.

  (vector 'a 'b 'c)               =>  #(a b c)
[[procedure]] (vector-length vector)

Returns the number of elements in vector as an exact integer.

[[procedure]] (vector-ref vector k)

k must be a valid index of vector. Vector-ref returns the contents of element k of vector.

  (vector-ref '#(1 1 2 3 5 8 13 21)
              5)         =>  8
  (vector-ref '#(1 1 2 3 5 8 13 21)
              (let ((i (round (* 2 (acos -1)))))
                (if (inexact? i)
                    (inexact->exact i)
                    i))) => 13
[[procedure]] (vector-set! vector k obj)

k must be a valid index of vector. Vector-set! stores obj in element k of vector. The value returned by vector-set! is unspecified.

  (let ((vec (vector 0 '(2 2 2 2) "Anna")))
    (vector-set! vec 1 '("Sue" "Sue"))
    vec)      =>  #(0 ("Sue" "Sue") "Anna")

  (vector-set! '#(0 1 2) 1 "doe")  =>  error  ; constant vector
[[library procedure]] (vector->list vector)
[[library procedure]] (list->vector list)

Vector->list returns a newly allocated list of the objects contained in the elements of vector. List->vector returns a newly created vector initialized to the elements of the list list.

  (vector->list '#(dah dah didah))  =>  (dah dah didah)
  (list->vector '(dididit dah))     =>  #(dididit dah)
[[library procedure]] (vector-fill! vector fill)

Stores fill in every element of vector. The value returned by vector-fill! is unspecified.


Rock Song 2

May 29, 2008

[[mAA 2nd sOng]]

time changes everythng,
but i aint gonna change,
i’ll alwz b d same,
a kid at heart,
whose sweet and smart.

time is a teacher,
and am it’s student,
who is a learner,
and smarter than his teacher,

there will b times,
whn u’ll b down and out,
and worn out,
feel like givin up,
but u need 2 fight,
with all ur plight,
and beat the *** out of time.

time changes everythng,
but i aint gonna change,
i’ll alwz b d same,
a kid at heart,
whose sweet and smart.

time is a carrier of pain and tears,
but i am gonna fight like the warrirors,
stand up tall till i am alive,
and stick a bee hive in the face of time.

I aint gonna lie down low,
coz i will show time,
how to stick and arrow up it’s ass,
with my gold plated bow.

life mayb *** up,
and I maybe *** up,
but i aint gonna give up,
coz i am gng 2 stick it up…

time changes everythng,
but i aint gonna change,
i’ll alwz b d same,
a kid at heart,
whose sweet and smart.


Rock Song 1

May 29, 2008

–[[mAA fIrst ROCK sOng LYRICS]]–wriTTEn by mE of CourSe

||–life is a bitch,–||
||–n am a dog,–||
||–whose goNNa fcuk liFe,–||
||–aLL liFe Long–||

||–u kNw y,–||

||–cz i ain’T goNNa take anY shit 4m u,–||
||–no mAtter wHO mayb u,–||
||–u aInt goNNa sTab me behind maa bAcK,–||
||–if u hav d BALLS stab me on mAA 6 pAck,–||
||–u sTabbeD mE in d BACk,–||
||–n gav mE a LOT f PAIN,–||
||–bUT am soRRY freAkO,–||
||–won’t let u fukn dO iT ever aGAin,–||

||–u knW y?–||

||–cz,–||
||–life is a bitch,–||
||–n am a dog,–||
||–whose goNNa fcuk liFe,–||
||–aLL liFe Long–||

||–it ain’t easy 2 live without u,–||
||–but if u come back nw,–||
||–i’D hv 2 golDEn word 4 u,–||
||–*** U,–||
||–cz am no lOnger a sLAvE f maa mEMOriES,–||
||–i AM d mASter of maa MERCeNaRIES–||

||–u knW y?–||

||–cz,–||
||–life is a bitch,–||
||–n am a dog,–||
||–whose goNNa fcuk liFe,–||
||–aLL liFe Long–||


HOW TO REMOVE HACKED BY GODZILLA VIRUS

May 24, 2008

Now a days with the increasing use of portable drives various types of virus infect a large number of system very easily.

One of these common virus is “Hacked by Godzilla Virus” which normally spreads through portable drives etc.

My system got infected with this Hacked by Godzilla Virus and I repaired my system without the help of any antivirus software.

Lets first discuss the common symptoms of the Godzilla Virus.

If your system is infected by this virus you will see the this text “Hacked by Godzilla Virus” in the title at the top of the window of Internet explorer

Some other symptoms:

1. Task manager is disabled.

2. Regedit (Command for registry edit) is disabled.

3. Folder options got disappeared From windows explorer.

4. Double clicking on any of your system drive( c: ,d: etc) initiates a new instance of the virus.

So, you won’t be able to open any of your drive by double click rather you have to open then by right click >> explore.

5. msconfig command is disabled – this virus is not dependent on system startup but it disables the msconfig command used to modify the system startup programs.

Let’s see how you can remove Godzilla virus in 5 minutes.

Follow the Step by step procedure given below to remove hacked by godzilla virus.

1. First download process explorer ,run it and end all the process which are running as wscript.exe

2. Download RRT.exe (Remove restrictions tool)

You may be wondering..what is RRT?

So for your FYI: RRT (Remove Restrictions Tool) v.1.0 is a tiny tool that does the work for AVs, it re-Enables all what the virus had disabled, and brings every thing including task manager ,regedit ,msconfig and hidden folder options back.

3. now, you have regedit command enabled.

Browse to Go to HKEY_LOCAL_MACHINE \Software \Microsoft \Windows \Current Version \Run and delete MS32DLL (right click on it and select delete)

Go to HKEY_CURRENT_USER \Software \Microsoft \Internet Explorer \Main and delete “Window Title” which has it’s value of “Hacked by Godzilla“ or you can also write your name as a recognition for yourself.

4. Open My Computer,File menu go to Tools -> Folder Options, click on View tab

Under Advance settings,
check “Show Hidden files and folders“,
uncheck “Hide extensions for known file types“,
uncheck “Hide protected operating system files (Recommended)
and click “OK” button

5. now right click on each of your drive and click explore now delete the files with names autorun.inf and MS32DLL.dll.vbs including your USB Drive

6. Restart your PC and your PC should be clean from Hacked by Godzilla.

Source – http://www.technixupdate.com/