Skip to content

Instantly share code, notes, and snippets.

@ktateish
ktateish / expr.go
Last active November 6, 2020 02:47
Static Analysis with Go
package main
import (
"go/ast"
"go/parser"
)
func main() {
expr, _ := parser.ParseExpr("2 + 3 * 5")
ast.Print(nil, expr)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, time
from datetime import datetime, timedelta
from slackclient import SlackClient
try:
from urllib.request import urlopen, Request
except ImportError:
(use compat.sicp)
(define (memq item x)
(cond ((null? x) false)
((eq? item (car x)) x)
(else (memq item (cdr x)))))
;;; Ex 2.53
(list 'a 'b 'c)
;;; => (a b c)
@ktateish
ktateish / SICP-Ex-2-2-omake.scm
Created February 11, 2016 06:04
図形言語強化版(ベジエ曲線で線画をスムーズに。要マシンパワー)
(use math.prime)
(use compat.sicp)
(use gl)
(use gl.glut)
;;; picture language primitives ------------------------------
(define (draw-line v1 v2)
(gl-begin* GL_LINES
(gl-vertex (xcor-vect v1) (ycor-vect v1) 0.0)
(gl-vertex (xcor-vect v2) (ycor-vect v2) 0.0)))
(use math.prime)
(use compat.sicp)
(use gl)
(use gl.glut)
;;; Ex 2.17
(define (last-pair. lst)
(if (null? (cdr lst))
lst
(last-pair. (cdr lst))))
(use compat.sicp)
(define (make-rat n d)
(cons n d))
(define (numer r)
(car r))
(define (denom r)
(cdr r))
(define (add-rat x y)
(use compat.sicp)
(use math.prime)
(define (cube x)
(* x x x))
(define (sum-integers a b)
(if (> a b)
0
(+ a (sum-integers (+ a 1) b))))
;;; Ex1.9
;;;
;;; (define (+ a b) (if (= a 0) b (inc (+ (dec a) b)))) の場合
;;;
;;; (+ 4 5)
;;; (inc (+ 3 5))
;;; (inc (inc (+ 2 5)))
;;; (inc (inc (inc (+ 1 5))))
;;; (inc (inc (inc (inc (+ 0 5)))))
;;; (inc (inc (inc (inc 5))))
;;; Ex 1.1
10 ;; => 10
(+ 5 3 4) ;; => 12
(- 9 1) ;; => 8
(/ 6 2) ;; => 3
(+ (* 2 4) (- 4 6)) ;; => 6