Giter Site home page Giter Site logo

shock's Introduction

Description

shock is a small package to simulate logic gates and circuits. Currently, shock supports the following gates for simulation[1]:

  • and
  • or
  • nand
  • nor
  • xor
  • xnor

shock is written with the chicken Scheme implementation in mind and the current version is v0.3.

Loading shock to your Scheme

After cloning the repo, you can load shock to your chicken interpreter with:

(load "/path/to/shock.scm")

If loading was succesfull, you should see something like this:

; loading shock.scm ...
; loaded shock-v0.3 successfully.
; See LICENSE file for details.
; type (shock-help) and (shock-examples) for usage examples.

alt tag

Getting help after loading shock to your interpreter.

You can also get help on how to use shock by using helping procedures.

These procedures are:

(shock-help) ; print help for shock
(shock-examples) ; print some examples
(shock-list-gates) ; print available gates for simulation

Printing brief usage description

(shock-help)

(shock-help)             :  show this message.
(shock-examples)         :  show examples of usage.
(shock-list-gates)       :  list available gates for simulation.
(simulate-gate gate n)   :  simulate gate of n inputs

alt tag

Listing available gates and circuits for simulation

(shock-list-gates)
Available gates for simulation:
and-gate
or-gate
nand-gate
nor-gate
xor-gate
xnor-gate

alt tag

From circuits, currently only half adder is available. As of version 0.3, half-adder isn't mentioned on the helping procedures, but you can run it with:

(1-bit-half-adder)

alt tag

Usage examples

(shock-examples)
Usage examples:

(simulate-gate and-gate 2) ; simulates and gate of 2 inputs
(simulate-gate nor-gate 4) ; simulates nor gate of 4 inputs

alt tag

This means we can call simulate-gate with each of the gates listed above.

You can also use the shock-help procedure which has a brief description on how to use shock.

Simulating gates - two examples

To simulate a gate of n inputs, all the user has to do is call simulate-gate procedure with the appropriate number of inputs. For instance you can simulate a 2-input and gate by running:

(simulate-gate and-gate 2)

and this should return:

input: (#f #f) -----> #f
input: (#t #f) -----> #f
input: (#f #t) -----> #f
input: (#t #t) -----> #t
Simulation ended successfully.

alt tag

Likewise, to simulate a 3-input nor gate all we have to do is:

(simulate-gate nor-gate 3)
input: (#f #f #f) -----> #t
input: (#t #f #f) -----> #f
input: (#f #t #f) -----> #f
input: (#t #t #f) -----> #f
input: (#f #f #t) -----> #f
input: (#t #f #t) -----> #f
input: (#f #t #t) -----> #f
input: (#t #t #t) -----> #f
Simulation ended successfully

alt tag

Known bugs

Currently, n-inputs, the procedure that produces all the possible inputs of a n-input gate isn't able to produce them in the logic of binary numbers (00, 01, 10, 11 for n = 2). See The inputs for 2-input and-gate on the examples above. Please report any bug at mr.dwts gmail com

Footnotes


[1]: not gate is also available but it makes sense to use it only when building circuits.

shock's People

Contributors

s-p-k avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.