Skip to content

Instantly share code, notes, and snippets.

View Heimdell's full-sized avatar
🔨
Right tool for the right job

Андреев Кирилл Heimdell

🔨
Right tool for the right job
  • Ульяновск
View GitHub Profile
let assert = require('assert')
let util = require('util')
let defined = value => value !== undefined
let notDefined = value => value === undefined
let not = value => ! value
let log = console.log
let say = (msg, value) => (log(msg), value)

Кодировка

Программный код должен быть в кодировке UTF-8. Символы вне диапазона [32.. 127] допускаются только внутри строковых литералов. Табуляция запрещена.

Лексемы

Виды лексем:

  1. Пунктуация
import Control.Exception ( SomeException(..), catch )
import Control.Monad ( when )
import Data.Foldable ( for_ )
import System.Directory ( doesDirectoryExist
, doesPathExist
, listDirectory
, pathIsSymbolicLink
)
import System.FilePath ( (</>) )
@Heimdell
Heimdell / adt.js
Last active December 3, 2017 21:08
Forth-machine
module.exports.Struct = (thunk) => {
let klass = null
return class {
constructor(args) {
Object.assign(this, args)
}
static of(args) {
if (!klass) {
var same = x => x
/*
data Either e a = Ok { value: a } | Err { msg: e }
This means, the "Either e a" (for any types "a" and "e")
is the type of either:
- type Ok, containing field "value" of type "a";
- type Err, containing field "msg" of type "e".
fun readLine () = TextIO.inputLine TextIO.stdIn
fun writeLine str = TextIO.outputSubstr (TextIO.stdOut, Substring.full str)
fun main () =
let
val words = String.tokens (fn x => x = #" ")
fun input keys vals =
case readLine () of
"""
I want to store some call tree, like
> push 1
> seq do
> dup
> push 1
> drop
> end
@Heimdell
Heimdell / seqpar.js
Last active October 17, 2017 21:30
Untyped implementation of sequental and parallel composition on stack machine.
// append elem to list with number of the list cell - 'time'
var Push = (head, tail) => ({head, tail, time: ++Push.time})
Push.time = 0
// this is the empty list - append to it or other list only
var Empty = {empty: true}
// flip(f) is 'f' but with args swapped
var flip = (f) => (x, y) => f(y, x)
require 'set'
def contents(filename)
acc = []
File.open(filename, 'r') do |fin|
while (line = fin.gets)
acc << line
end
end
@Heimdell
Heimdell / joy.js
Last active October 6, 2017 21:24
/*
* Here we build simple virtual machine for Joy programming language,
* or smth like that. Go google it. No, seriously.
*/
/*
* We want to distingush constants 'foo' and funcalls `new Name('foo')`
*/
class Name {