Skip to content

Instantly share code, notes, and snippets.

var create = (globals) => {
var _G = Object.assign({
}, globals || {
});
_G._G = _G;
_G.environment = [{
}];
var isNil = (x) => {
return x === undefined || x === null;
};
@shawwn
shawwn / gist:544b643bba018fb6bd302a5c46222ca6
Created September 8, 2018 23:57
Dispelling myths on HN
~$ time luajit -e 'print(1)'
1
real 0m0.090s
user 0m0.031s
sys 0m0.053s
~$ time luajit -e 'print(1)'
1
real 0m0.082s
(define delimiters (set-of "," "\r" "\n" "\"" ""))
(define whitespace (set-of "," "\r" "\n"))
(define stream (str more)
(obj pos: 0 string: str len: (# str) more: more))
(define peek-char (s)
(char (get s 'string) (get s 'pos)))
(define read-char (s)
#!/usr/bin/env lumen
(define passed 0)
(define failed 0)
(define tests ())
(define system (require 'system))
(define reader (load "reader.l"))
(define-macro test (x msg)
(define aux (load "aux.l"))
(define count-indexed (name)
(let h ((get io 'open) name)
((get h 'seek) h "end" -8)
(with n (tonumber (be64dec ((get h 'read) h "*a")))
((get h 'close) h))))
(define count-rows (name)
(let h ((get io 'open) name)
@shawwn
shawwn / lumen.rs
Created September 10, 2018 20:56
silly rust hacking
//#![feature(proc_macro)]
extern crate exec;
extern crate libc;
// pub unsafe extern fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char
// // use std::io::fs::{mkdir_recursive,rmdir_recursive};
// use std::io;
// use std::io::fs;
// use std::io::process::{ProcessOutput,ProcessExit};
// use std::os;
@shawwn
shawwn / lumen.l
Created September 12, 2018 06:27
Lumen, CL style
(define-global environment (list (obj)))
(define-global target (language))
(define-global nil? (x)
(target
js: (or (= x nil) (= x null))
lua: (= x nil)))
(define-global is? (x) (not (nil? x)))
; Four people, Arnold, Brenda, Carlos and Darlene, each said two statements such that:
; • One person lied in both statements;
; • One person told the truth in both statements; and
; • Two people told the truth in one statement and a lie in the other statement.
; Arnold said, “Brenda lied once” and “Darlene lied twice.”
; Brenda said, “I never lie” and “Arnold never lied.”
; Carlos said, “Darlene lied twice” and “Brenda never lied.”
; Darlene said, “Arnold lied twice” and “I never lie.”
Preface
Is Lisp worth learning? Will it make you a better programmer? Who cares, and why
should you?
If you list the N most impressive programs written in Lisp, it would probably be
dwarfed in depth and breadth by the N most impressive JavaScript programs. Isn't
that proof that this book isn't worth your time?
The best way to disprove this notion is to show by example. Consider a word
@shawwn
shawwn / foo
Created November 29, 2018 07:34
foo