Skip to content

Instantly share code, notes, and snippets.

@ClarkeRemy
ClarkeRemy / complex.rs
Created January 30, 2022 05:54
super basic complex number implementation overloaded with rust primitives
use std::{ops::*,cmp::PartialEq};
#[derive(Debug,Clone,Copy,PartialEq)] pub struct Complex(f64,f64);
type C=Complex;
impl Add for C{ type Output = C; fn add(self, rhs: Self) -> Self::Output { Complex(self.0+rhs.0,self.1+rhs.1)}}
impl Sub for C{ type Output = C; fn sub(self, rhs: Self) -> Self::Output { Complex(self.0-rhs.0,self.1-rhs.1)}}
impl Neg for C{ type Output = C; fn neg(self ) -> Self::Output { Complex(-self.0,-self.1)}}
impl Mul for C{ type Output = C; fn mul(self, rhs: Self) -> Self::Output { Complex((self.0*rhs.0)-(self.1*rhs.1), (self.0*rhs.1)+(self.1*rhs.0))}}
impl Div for C{ type Output = C; fn div(self, rhs: Self) -> Self::Output {
@ClarkeRemy
ClarkeRemy / bird_combinators.txt
Created January 30, 2022 07:11
learning bird combinators
Bluebird : B : \abc.a(bc) : S(KS)K :
Blackbird : B1 : \abcd.a(bcd) : BBB :
Bunting : B2 : \abcde.a(bcde) : B(BBB)B : B B1 B
Becard : B3 : \abcd.a(b(cd)) : B(BB)B : BDB
Cardinal : C : \abc.acb : S(BBS)(KK) :
Dove : D : \abcd.ab(cd) : BB :
Dickcissel : D1 : \abcde.abc(de) : B(BB) : BD
Dovekies : D2 : \abcde.a(bc)(de) : BB(BB) : DD
Eagle : E : \abcde.ab(cde) : B(BBB) : B B1
Bald Eagle : E^ : \abcdefg.a(bcd)(efg) : B(BBB)(B(BBB)) : EE

Monad

Rank (0)

  • Floor
  • Ceiling
  • Decrement (_1&+)
  • Increment ( 1&+)
  • Open ( unbox )
  • Conjugate ( complex Numbers)
  • Signum
  • Neg ( *&_1 )( Negate )
@ClarkeRemy
ClarkeRemy / lifetimes.rs
Created October 24, 2022 16:54
Lifetimes Rust
fn main() {
let x1 = vec![1_u8];
let r1 = &x1[..]; // 'l1
let ret = {
let x2 = vec![2_u8];
let r2 = &x2[..]; // 'l2
let mut y2 = Holder(r2);// Holder<'l2>
@ClarkeRemy
ClarkeRemy / fib.rs
Created October 30, 2022 15:10
unfinished fib vm
fn fib (input:usize)->usize{
const KIBI : usize = {let (mut x, mut times) = (2,0); loop{if times == 10 {break x} times+=1; x*=2}};
const MEBI : usize = KIBI*KIBI;
const WORD_SIZE : usize = core::mem::size_of::<usize>();
const TRUE : usize = true as usize;
const FALSE : usize = false as usize;
const INST_REG : usize = 7;
const STACK_REG : usize = 6;
@ClarkeRemy
ClarkeRemy / Unique.ijs
Last active January 5, 2023 10:43
Unique Object
NB. for reference ( https://code.jsoftware.com/wiki/Guides/Lexical_Closure )
coclass 'Unique'
lines =. {{ <;._2 m }}
NB. format : 'ref proof' =: input Unique message
NB. on drop no proof is returned
proof =.{{)n
'message own'=. y
@ClarkeRemy
ClarkeRemy / tailcall.rs
Created April 24, 2023 18:45
Tail Call Elimination Rust
#![allow(redundant_semicolons)]
/// The current continuation
type Cont<S,O> = (S, fn(S)->Process<S,O>);
/// The State of a Process
enum Process<S,O>
{ Continue(Cont<S,O>)
, Complete(O)
}
@ClarkeRemy
ClarkeRemy / d_list.rs
Created July 30, 2023 15:27
A basic doubly linked list implementation in Rust
mod doubly_linked_list
{
extern crate core;
extern crate alloc;
use
{ core::
{ ptr
, marker::PhantomData
, option::Option::{self, *}
, iter::{Iterator, IntoIterator, DoubleEndedIterator}
@ClarkeRemy
ClarkeRemy / swappy.rs
Last active August 7, 2023 16:45
Swappy
#[derive(Debug)]
enum Switchy<A,B>
{ Nil
, Cons(A, Box<Switchy<B,A>>)
}
impl<A,B> Switchy<A,B>
{ fn cons(t : A, tail : Switchy<B,A>)->Self
{ Self::Cons(t, Box::new(tail)) }
}
@ClarkeRemy
ClarkeRemy / call_erased.rs
Created August 22, 2023 19:41
Call Erased (cursed)
fn call_later<T:Fn(&G),G>(_ : &T) -> unsafe fn(*const(), *const())
{
|p : *const (), g : *const()|
{ unsafe { (&*(p as *const T))(&*(g as *const G)) }
}
}