Skip to content

Instantly share code, notes, and snippets.

@commander-trashdin
commander-trashdin / default-types.lisp
Last active March 2, 2021 17:26
Important part of my util, that is about sane defaults for all types, including parametrized. Let's try to cover all of them, can be very useful.
(defparameter *default-impl* (make-hash-table))
(Defun %dimensions-comp (dimensions)
(cond ((eql '* dimensions) 0)
((listp dimensions) (mapcar (lambda (x) (if (eql '* x) 0 x)) dimensions))
(t dimensions)))
@commander-trashdin
commander-trashdin / double-linked-list-dispatched.lisp
Created February 28, 2021 10:56
An example of datastructure with dispatch, very much alpha version
(ql:quickload 'adhoc-polymorphic-functions)
(use-package :adhoc-polymorphic-functions)
;(define-polymorphic-function make (type size)) ;;This one is harder that you might think
(define-polymorphic-function push-front (data container))
(define-polymorphic-function push-back (data container))
(define-polymorphic-function pop-front (container))
(define-polymorphic-function pop-back (container))
(define-polymorphic-function size (container))
(defstruct guest
(checkin 0 :type fixnum)
(checkout 0 :type fixnum))
(defstruct guestload
(start 0 :type fixnum)
(guestcount 0 :type fixnum))
(defstruct tdate
(date 0 :type fixnum)
type Guest struct {
CheckInDate int
CheckOutDate int
}
type Load struct {
StartDate int
GuestCount int
}
@commander-trashdin
commander-trashdin / qs.cpp
Created March 7, 2021 17:19
showing how to do this
template <class Iterator, class RandomGenerator>
void QuickSort(Iterator begin, Iterator end, RandomGenerator& generator) {
if (begin == end) {
return;
}
std::uniform_int_distribution<> dis(0, end - begin - 1);
auto pivot = *(begin + dis(generator));
auto first = begin;
auto last = end - 1;
if (begin == last) {
@commander-trashdin
commander-trashdin / template.lisp
Last active March 31, 2021 15:14
Doing some templates
(defun encode-type (typename)
(let ((str ""))
(labels ((rec (name)
(when name
(if (listp name)
(mapcar #'rec name)
(setf str (concatenate 'string str "-" (format nil "~s" name)))))))
(rec typename)
str)))
@commander-trashdin
commander-trashdin / diofant.hs
Last active April 2, 2021 15:49
Diofant equation
module Main where
import Data.Maybe
import Text.Read
uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
uncurry3 foo (a,b,c) = foo a b c
get3Ints s = do
[a, b, c] <- traverse readMaybe $ words s
@commander-trashdin
commander-trashdin / struct.lisp
Last active April 8, 2021 22:26
more adpf structures
(defmacro define-struct (name inheritance &body slots)
(let ((trueslots (loop :for (name . rest) :in slots
:collect (ecase (length rest)
(1 `(,name . ,rest))
(2 (let ((type (cadr (member :t rest))))
`(,name ,(default type) :type ,type)))
(3 (let ((type (cadr (member :t rest))))
`(,name ,(third rest) :type ,type)))))))
`(progn
@commander-trashdin
commander-trashdin / dl.lisp
Created April 26, 2021 10:09
dl-list-template 2: electric boogaloo
(ql:quickload 'adhoc-polymorphic-functions)
(use-package :adhoc-polymorphic-functions)
(deftype ind () `(integer 0 #.array-dimension-limit))
(defparameter *default-impl* (make-hash-table))
/// A munger which XORs a key with some data
use std::borrow::Borrow;
#[derive(Clone)]
pub struct Xorcism<'a> {
key: &'a [u8],
position: usize,
}
pub trait Captures<'a> {}