Wednesday 26 October 2016

Implementation of 64 bit Binary Calculator using concurrent lisp.

Implementation of 64 bit Binary Calculator using concurrent lisp.


Here is implementation of 64 bit binary calculator program with Concurrent lisp (Sbcl Compiler)

(defvar A ) ;variable declaration
(defvar B ) 
(defvar C ) 



(defun :bits (value &optional (size 64)) ; 64 is bit size
(format t "~v,'~B" size value)) ;here "~B" is for Binary , "~D" for Decimal
; "~v" is for output format

(write-line "Welcome To Calculator") 


(write-line "Enter A: ") 
(setq A (read)) ; Set input value in variable
(:bits A) ;show value of variable


(terpri)  ; This is for New line                                          
(write-line "Enter B: ") 
(setq B (read)) 
(:bits B)

(terpri)  ; This is for New line


(write-line "1.Addition") 
(write-line "2.Substraction") 
(write-line "3.Multiplication") 
(write-line "4.Division") 


(sb-thread:make-thread (lambda () (progn (sleep 0) ;lambda is the symbol for an anonymous;
;function, a function without a name. Every time you use an anonymous function, you need to ;include its whole body.
(setq C (+ A B)) ; addition id done and stored in var C
(write-line "Addition Of Two Numbers: ") 
(:bits C))))   ; Value in var c will displayed



(sb-thread:make-thread (lambda () (progn (sleep 2) ;PROGN calls its expression in the order they ;have been written.
(setq c (- A B)) 
(write-line "Substraction Of Two Numbers: ") 
(:bits C))))


(sb-thread:make-thread (lambda () (progn (sleep 4) ;progn is a special form that causes each of its ;arguments to be evaluated in sequence and then returns the value of the last one. The preceding ;expressions are evaluated only for the side effects they perform. The values produced by them
;are discarded.
(setq c (* A B)) 
(write-line "Multiplication Of Two Numbers: ") 
(:bits C))))

(sb-thread:make-thread (lambda () (progn (sleep 6)
(setq c (/ A B)) 
(write-line "Division Of Two Numbers: ") 
(:bits C))))

(terpri)  ; This is for New line
(sleep 20)
(exit)


;-----Output:---------


;[hacker911@localhost]# sbcl --noinform --load calc.lisp
;Welcome To Calculator
;Enter A:
;4
;----------------------------------100
;Enter B:
;2
;-----------------------------------10
;1.Addition
;2.Substraction
;3.Multiplication
;4.Division
;
;Addition Of Two Numbers: 
;----------------------------------110
;Substraction Of Two Numbers:
;------------------------------------10
;Multiplication Of Two Numbers:
;---------------------------------1000
;Division Of Two Numbers: 
;------------------------------------10
;[hacker911@localhost]#


If any Question , write it in Comment section...

No comments:

Post a Comment