Skip to content

Instantly share code, notes, and snippets.

extern crate take_mut;
let mut a = 5i32;
let mut b = 6i32;
take_mut::scope(|scope| {
let (a_val, a_hole) = scope.take(&mut a);
let (b_val, b_hole) = scope.take(&mut b);
b_hole.fill(a_val);
a_hole.fill(b_val);
use std::rc::{Rc, Weak};
use std::cell::RefCell;
pub struct Scope<'t, T: 't> {
filled: bool,
hole: &'t mut T
}
impl<'t, T: 't> Scope<'t, T> {
unsafe fn new(mut_ref: &'t mut T) -> (T, Self) {
@Sgeo
Sgeo / hsum.rs
Last active November 27, 2024 15:58
Anonymous sum type prototype
use std::marker::PhantomData;
pub enum Void {}
impl Void {
fn any(&self) -> ! {
match *self {}
}
}
@Sgeo
Sgeo / quantum_rounding.lsl
Created November 12, 2015 05:40
Measures the impact of floating point numbers on low velocities
float estimated_min_attempt_vel(float fps)
{
vector pos = llGetPos();
float alt = pos.z;
integer shell = llFloor(llLog(alt)/llLog(2.0));
return fps * llPow(2.0, (float)shell - 24.0);
}
show(float attempting, float getvel, float actual, float fps, float dilation)
{
create name !A!b=1, animate me . 1 1 0; at tm A:=0 100, name !A!b=1; at tm A:=1 101, name !A!b=0; at tm B:=0 102, animate me . 1 1 0; at tm B:=1 103, animate me . 1 1 1000000000; at tm A*B 104, astart !A!b=1; adone timer !A&!B=1 200 reset
create name !Ab=1; at tm A:=0 100, name !Ab=1; at tm A:=1 101, name !Ab=0; at tm B:=0 102, animate me . 1 1 1000000000; at tm B:=1 103, animate me . 1 1 0; at tm A*B 104, astart !Ab=1; adone timer !A&B=1 200 reset
create name Ab=0; at tm A:=0 100, name Ab=0 ; at tm A:=1 101, name Ab=1; at tm B:=0 102, animate me . 1 1 1000000000; at tm B:=1 103, animate me . 1 1 0; at tm A*B 104, astart Ab=1; adone timer A&B=1 200 reset
create animate me . 1 1 0, name A!b=0; at tm A:=0 100, name A!b=0; at tm A:=1 101, name A!b=1; at tm B:=0 102, animate me . 1 1 0; at tm B:=1 103, animate me . 1 1 1000000000; at tm A*B 104, astart A!b=1; adone timer A&!B=1 200 reset
at tm A&B=1 100, timer A&!B=0 200 reset, timer !A&B=0 200 reset, timer !A&!B=0 200 reset, timer A=1 200 reset, timer B=1 200 re
@Sgeo
Sgeo / split_mut.rs
Created September 17, 2015 05:01
split_mut.rs. This is almost certainly a bad idea
#![allow(dead_code)]
use std::fmt;
use std::error;
#[derive(Debug)]
enum SplitMutError {
AliasedMut
}
@Sgeo
Sgeo / hlist_with_working_contains.rs
Last active August 29, 2015 14:19
HList implementation with macro that allows production of Contains<T>
#![allow(dead_code)]
struct HNil;
struct HCons<H, T> {
head: H,
tail: T
}
trait Contains<A> {
@Sgeo
Sgeo / pure <-> mut
Last active August 29, 2015 14:13
Functions that convert between pure-style (A -> A) and mutating (&mut A -> ()) functions.
fn mut_to_pure<'f, A, FI>(mut f: FI) -> Box<FnMut(A) -> A+'f>
where FI: FnMut(&mut A)+'f {
Box::new(move |mut a| {f(&mut a); a})
}
fn pure_to_mut<'f, A, FI>(mut f: FI) -> Box<FnMut(&mut A)+'f>
where FI: FnMut(A) -> A+'f {
Box::new(move |a: &mut A| {
unsafe {
let mut temp: A = std::mem::uninitialized();
@Sgeo
Sgeo / demethodize
Created November 20, 2014 08:06
Corrected version of @HeadDZombie demethodize based on spread syntax
var demethodize = function(func) {
"use strict";
return function(...args) {
func.apply(args[0], args.slice(1))
};
};
#lang racket/base
(require racket/control)
(struct monad (bind return) #:transparent)
(define-syntax-rule (with-monad ([val m]) body ...)
(let* ([m-once m]
[val
(lambda (ma)