Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
NalaGinrut / morse.scm
Created September 22, 2014 08:47
Morse coding
(use-modules (ice-9 rdelim))(define morse '((#\a ".-")(#\b "-...")(#\c "-.-.")(#\d "-..")(#\e ".")(#\f "..-.")(#\g "--.")(#\h "....")(#\i "..")(#\j ".---")(#\k "-.-")(#\l ".-..")(#\m "--")(\
#\n "-.")(#\o "---")(#\p ".--.")(#\q "--.-")(#\r ".-.")(#\s "...")(#\t "-")(#\u "..-")(#\v "...-")(#\w ".--")(#\x "-.--")(#\y "-.--")(#\z "--..")))(for-each (lambda (x) (if (char-alphabetic\
? x)(display (car (assoc-ref morse x))))(display " "))(string->list (string-downcase (read-line (current-input-port)))))(newline)
#!/usr/bin/env guile
!#
(use-modules (ice-9 rdelim)
(ice-9 ftw)
(ice-9 futures)
(srfi srfi-1))
(define get-string-all (@ (rnrs io ports) get-string-all))
(define G (ash 1 30))
(define M (ash 1 20))
@NalaGinrut
NalaGinrut / pong.scm
Last active May 24, 2024 07:06
tiny Actor-model
;;==============Tiny framework of Actor-model=========================
(use-modules (ice-9 control) (ice-9 match) (ice-9 q))
(define *mailbox* (make-hash-table))
(define *task-queue* (make-q))
(define (gen-pid n) (gensym (format #f "actor-~a-" n)))
(define-syntax-rule (! pid msg)
(let ((mq (hashq-ref *mailbox* pid)))
(if mq
@NalaGinrut
NalaGinrut / clp.scm
Last active November 9, 2015 11:13
Auto prover of Combinatory Logic
(use-modules (ice-9 match))
(define (cl str)
(define (parser s)
(let lp((i 0) (ret '()))
(cond
((= i (string-length s))
(map (lambda (x)
(if (char? x) (string->symbol (string x)) x))
(reverse ret)))
@NalaGinrut
NalaGinrut / lru.scm
Created January 14, 2017 14:30
Simple LRU implementation in Scheme
(define (make-lru size)
(define cnt 0)
(define fl '())
(define ht (make-hash-table))
(define (refresh-fl i)
(set! fl (cons i (filter (lambda (x) (not (= x i))) fl))))
(lambda (cmd . i/v)
(case cmd
((get)
(refresh-fl (car i/v))
(use-modules (artanis server epoll)
(artanis utils)
(ice-9 rdelim)
(ice-9 match)
(ice-9 suspendable-ports)
(ice-9 control))
(install-suspendable-ports!)
(define (call-with-sigint x y) (%call-with-sigint x y))