This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cond-expand | |
(gauche (import (gauche base) (scheme base) (scheme write))) | |
(guile (import (srfi srfi-1))) | |
(chibi (import (srfi 1) (scheme small)))) | |
(define (f x y) (list (list (+ (* (caar x) (caar y)) | |
(* (cadar x) (caadr y))) | |
(+ (* (caar x) (cadar y)) | |
(* (cadar x) (cadadr y)))) | |
(list (+ (* (caadr x) (caar y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; referense | |
;;;; SLIB 3b1-5 | |
;;;; Gauche 0.9.11 | |
;;;; MIT/GNU Scheme 11.2 | |
(define (reduce-right f ridentity ls) | |
(if (null? ls) ridentity | |
(let loop ((ridentity (car ls)) (ls (cdr ls))) | |
(if (null? ls) ridentity | |
(f ridentity (loop (car ls) (cdr ls))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cons () { | |
eval CAR"$CNUM"="$1"; eval CDR"$CNUM"="$2"; | |
CONSR="$CNUM.conscell"; CNUM="$((CNUM+1))"; | |
} | |
car () { eval CARR="\$CAR${1%%.conscell}"; } | |
cdr () { eval CDRR="\$CDR${1%%.conscell}"; } | |
TRUE=1; FALSE=0; NULL="empty"; | |
pairp () { | |
case "$1" in (*.conscell) PAIRPR="$TRUE" ;; (*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
extern int yylex(void); | |
int yyerror(const char *s) { printf("%s\n", s); return 0; } | |
int node[4096]; int nnum = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define *lh* #f) | |
(define (get-token) | |
(define (put-c1 x) (set! *lh* x)) | |
(define (null-c1) (set! *lh* #f)) | |
(define (get-c1) (if *lh* (let ((lh *lh*)) (null-c1) lh) (read-char))) | |
(define (tstring t) (list->string (reverse t))) | |
(define (skip-spaces) | |
(do ((c (get-c1) (get-c1))) | |
((not (member c (string->list " \n\r"))) (put-c1 c)))) | |
(let loop ((c (get-c1)) (t '())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
LH = False | |
def get_token(): | |
def put_c1(x): global LH; LH = x | |
def null_c1(): global LH; LH = False | |
def get_c1(): | |
if not LH: | |
try: return stdin.read(1) | |
except EOFError: pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# One token input function with look-ahead caching | |
stty -icanon | |
LF="$(printf \\012)" | |
get_c1 () { | |
case "$LH" in ("") GC1R=$(dd bs=1 count=1 2>/dev/null) | |
;;(*) GC1R="$LH"; LH="" ;;esac | |
} | |
skip_spaces () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define *lh* #f) | |
(define (get-token) | |
(define (put-c1 x) (set! *lh* x)) | |
(define (null-c1) (set! *lh* #f)) | |
(define (get-c1) (if *lh* (let ((lh *lh*)) (null-c1) lh) (read-char))) | |
(define (tstring t) (list->string (reverse t))) | |
(define (skip-spaces) | |
(do ((c (get-c1) (get-c1))) | |
((not (member c (string->list " \n\r"))) (put-c1 c)))) | |
(let loop ((c (get-c1)) (t '())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### | |
#### ev.py: A Pure LISP Interpreter | |
#### in Pseudocode-style Python 3 | |
#### | |
#### (C) 2022 TAKIZAWA Yozo | |
#### This code is licensed under CC0. | |
#### https://creativecommons.org/publicdomain/zero/1.0/ | |
#### | |
#### <examples> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wolfram's 2-state 3-symbol Turing Machine | |
from time import sleep | |
delta = {1: {0: (1, 1, 2), 1: (2, -1, 1), 2: (1, -1, 1)}, | |
2: {0: (2, -1, 1), 1: (2, 1, 2), 2: (0, 1, 1)}} | |
ds = {0: ' ', 1: '.', 2: '*'} | |
tlen = 80 | |
tape, head, state = [0] * tlen, int(tlen / 2) - 9, 1 |
OlderNewer