Giter Club home page Giter Club logo

invisinim's Introduction

invisinim

I tried to write Nim code only with white space characters.

Requirements

  • Nim 2.0
  • Text editor that correctly display ' '.

How to compile and run

$ git clone https://github.com/demotomohiro/invisinim.git
$ cd invisinim
$ nim c -r mycode.nim

Code that generated mycode.nim and              .nim

Save following code to any .nim file and compile and run with nim c -r foo.nim.

import std/[strutils, strformat]

const ZS = " "
var zsn = 0

proc genZSName(): string =
  inc zsn
  ZS.repeat(zsn)

let
  ZeroAry = genZSName()
  toString = genZSName()
  add0 = genZSName()
  echoStr = genZSName()

var modpart = &"""
const {ZeroAry}* = ['\0']

proc {toString}*(ary: openArray[char]): string = ary.substr

proc {add0}*[N: static int](ary: array[N, char]): array[N + 1, char] =
  for i in 0 ..< ary.len:
    result[i] = ary[i]

proc {echoStr}*(msg: string) =
  echo msg

"""

var addToLast: array[8, string]

for i in 0..7:
  addToLast[i] = genZSName()
  modpart.add &"""
proc {addToLast[i]}*[I](ary: array[I, char]): array[I, char] =
  result = ary
  result[^1] = char(result[^1].int + {1 shl i})

"""

let invisibleMod = genZSName()
writeFile invisibleMod & ".nim", modpart

proc charToBits(c: char): string =
  for i in 0 .. 7:
    if ((c.int shr i) and 1) == 1:
      result.add addToLast[i] & " "

var code = &"""
import {invisibleMod}

{echoStr} {toString} """

const cmd = "Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. You can write invisible code."

for i in countDown(cmd.high, 0):
  code.add charToBits(cmd[i]) & " "
  if i != 0:
    code.add &"{add0} "

code.add ZeroAry

writeFile "mycode.nim", code

invisinim's People

Contributors

demotomohiro avatar

Watchers

 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.