Skip to content

Instantly share code, notes, and snippets.

View bvssvni's full-sized avatar

Sven Nilsen bvssvni

View GitHub Profile
@bvssvni
bvssvni / gist:9674632
Last active December 23, 2023 22:56
A Rust Chain Macro
//! Chain macro in Rust
//!
//! A typical usage is to avoid nested match expressions.
//!
//! Supports:
//! - Pattern matching
//! - Or expressions (A | B => ...)
//! - Guarded statements (x if <cond> => ...)
//! - Implicit else (requires all arms to return same type)
@bvssvni
bvssvni / main.rs
Created January 15, 2017 19:31
LLVM takes a long time to optimize this
extern crate piston_meta;
extern crate range;
extern crate dyon;
use std::sync::Arc;
use self::piston_meta::MetaData;
use self::range::Range;
use self::dyon::{error, load_meta, Module, Runtime};
fn main() {
@bvssvni
bvssvni / bottles_of_beer.dyon
Created December 20, 2018 09:09
99 bottles of beer (in Dyon)
fn main() {
n := 99
println(link {
link i n {
b := n-i
bottles(b)" of beer on the wall, "bottles(b)" of beer.\n"
"Take one down, pass it around, "bottles(b-1)" of beer on the wall.\n\n"
}
"No more bottles of beer on the wall, no more bottles of beer.\n"
"Go to the store and buy some more, "n" bottles of beer on the wall.\n"
/// Phantom type for step 1.
pub enum Step1 {}
/// Phantom type for step 2.
pub enum Step2 {}
/// Contains data we set step by step.
pub struct Data<'a> {
/// 'a' is set in the first step.
a: Option<int>,
@bvssvni
bvssvni / philosophers.txt
Created February 24, 2018 08:43
Philosophers and thinkers communication style described with a single sentence
Albert Einstein - His genius papers are never read by common people, but they absorb every sentence he ever said publicly.
Bertrand Russel - He was the center of the logical revolution of mathematics, but his gentleman appearance hides his colorful life.
Daniel Dennett - Smart, knows a lot and good at talking about interesting things. He is the center.
Eliezer Yudkowsky - The world collides with him, he loves it, he attacks it straight on, and the world loses ... every time.
Elon Musk - A cool idea that sounds like one came up with it while playing on the boy's room, but real.
#![feature(globs)]
#![feature(if_let)]
extern crate piston;
extern crate gfx;
mod snakeapp;
mod object;
mod settings;
mod text;
@bvssvni
bvssvni / gist:9343353
Last active November 11, 2017 19:32
How To Organize Code in Rust per Object or Function
//! rustc 0.10-pre (ee8f45e 2014-02-18 13:41:49 -0800)
//!
//! Before you bite my head off, this is NOT a recommend way of organizing code!
//! It is only a demonstration what you can do in Rust! (wish I put this comment in earlier)
//! My intention with this example is to show new people the features of the module system.
//!
//! The module system in Rust gives you precise control
//! over the interface when writing libraries.
//! You can write the layout independent of how you organize the code!
//! In this example two different conventions are explored.
@bvssvni
bvssvni / unhyping-ai-jokes.md
Last active October 13, 2017 15:57
Unhyping AI Jokes

Bayesian reasoning, no temporal logic

Operator: Computer, the door is open, the door is closed. Is the door closed?
Computer: I don't know!

Monotonic solver, no temporal logic, no assumption checking

Operator: Computer, the door is open, the door is closed. Is the door open?
Computer: Yes!
Operator: Computer, is the door closed?

@bvssvni
bvssvni / unhyping-ai-jokes.md
Created October 11, 2017 19:04
Unhyping AI Jokes

Bayesian reasoning, no temporal logic

Operator: Computer, the door is open, the door is closed. Is the door closed? Computer: I don't know!

Temporal logic, no Bayesian reasoning

Operator: Computer, the sky is green, the sky is blue. Which color has the sky? Computer: It was green, but changed to blue right now.

@bvssvni
bvssvni / add_even.idr
Created April 6, 2017 00:04
Managed to prove the path `add[even] <=> eq`
prove_add_even : (x : Nat) -> (y : Nat) -> even (add x y) = eq (even x) (even y)
prove_add_even Z Z = Refl
prove_add_even Z (S Z) = Refl
prove_add_even Z (S (S k)) = prove_add_even Z k
prove_add_even (S Z) Z = Refl
prove_add_even (S (S k)) Z = prove_add_even k Z
prove_add_even (S Z) (S Z) = Refl
prove_add_even (S Z) (S (S k)) = prove_add_even (S Z) k
prove_add_even (S (S k)) (S j) = prove_add_even k (S j)