Skip to content

Instantly share code, notes, and snippets.

use glfw::{Action, ClientApiHint, Glfw, Key, Monitor, WindowHint};
fn main() {
/*
I. Initialization
Tries to initialize GLFW. If it fails to do so, let the user know and end the program,
since there is no point in going further.
glfw::fail_on_errors means there will be the panic in the case of initialization failure,
so the unwrap call here is just symbolical.
include string-dict
data ControlFlow<a, b>: next(v :: a) | brk(v :: b) end
fun loop<a, b>(func :: (a -> ControlFlow<a, b>), init :: a) -> b:
cases(ControlFlow) func(init):
| brk(v) => v
| next(v) => loop(func, v)
end
end
include string-dict
data ControlFlow<a, b>: next(v :: a) | brk(v :: b) end
fun loop<a, b>(func :: (a -> ControlFlow<a, b>), init :: a) -> b:
cases(ControlFlow) func(init):
| brk(v) => v
| next(v) => loop(func, v)
end
end
#lang pyret
data CalcOp:
| push-op(n :: Number)
| bin-op(operator :: String)
| un-op(operator :: String)
end
fun first-some(l :: List<(-> Option)>) -> Option:
doc: "search for the first non-none result in a list of lambdas"
@madwareru
madwareru / Cargo.toml
Last active June 6, 2024 23:39
Used by myself to play the company of Songs Of Conquest without that much back hurt
[package]
name = "songs-of-conquest-json-explorator"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
json = "0.12.4"
getopts = "0.2.21"
@madwareru
madwareru / EOPL3_week_1.md
Last active November 4, 2023 16:29
пост-отзыв по книге Essentials Of Programming Languages после первой неполной недели чтения

Итак, пост-отзыв по EOPL3 после первой неполной недели чтения.

Из двух глав осилил пока только первую, где в основном столкнулся с проблематикой задания различных наборов данных через индукцию, как и было обещано в названии 🙂

Обычно, множества предлагается задавать через т.н. list comprehensions, которые есть во многих ФП языках типа хаскеля, а так же есть в python, C#, Kotlin и т.д.

Примеры ниже (на python, C# и Kotlin соответственно):

use proc_macro2::{TokenStream, TokenTree};
use combine::{parser, between, many, Parser, token};
use quote::{format_ident, quote};
enum Node {
Inc,
Dec,
IncTapePos,
DecTapePos,
PutChar,
use std::collections::HashMap;
#[derive(Copy, Clone)]
enum MatchPattern { Any, Exact(u8) }
#[derive(Copy, Clone)]
enum OpCode { Match(MatchPattern), KleeneStar(MatchPattern) }
#[derive(Copy, Clone)]
struct Cursor<'a, T: Copy> { parts: &'a[T], cursor: usize }
use std::ptr;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::arch::x86_64::*;
fn scale_2x_unsafy_simd(pixels: &[u32], width: u32, height: u32) -> Vec<u32> {
assert_eq!(width % 4, 0);
let whole_size = (width * height * 4) as usize;
let width = (width / 4) as usize;
let dbl_width = (2 * width) as usize;
macro_rules! make_ident_tup {
($i:ident) => {$i};
($i:ident, $($irest:ident),+) => {($i, make_ident_tup!($($irest),+))}
}
macro_rules! cross_join {
( $lhs:expr ) => { $lhs };
( $lhs:expr, $($rhss:expr),+) => {($lhs).flat_map(
|x| (cross_join! ($($rhss),+)).map( move |y| (x, y)))}
}