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
(declare lookup [sym env]) | |
(defn lookup [sym [sym val & _]] val) | |
(defn lookup [sym [_ _ & rest]] (lookup sym rest)) | |
(defn lookup [sym []] (error "Symbol " syn " not found")) | |
(declare eval [expr env]) | |
(defn eval [expr _] (error "Invalid expression" expr)) | |
(defn eval [(int n) env] n) | |
(defn eval [(float n) env] n) |
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
(defpred + [t] | |
(+ [t t] t)) | |
(deferr + [t] | |
"Type " t " does not have an addition operation defined on it.") | |
(defrule + [int] | |
(+ [v1 v2] (int-+ v1 v2))) | |
(defrule + [float] | |
(+ [v1 v2] (float-+ v1 v2))) | |
(defpred lookup [env sym > 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
(defpred forte [type] | |
(forte-val [type] int)) | |
(defrule (forte ()) | |
(forte-val [_] 0)) | |
(defrule (forte ('O & rest)) | |
[(forte rest)] | |
(forte-val [(_ & rest)] | |
(* (forte-val rest) 2))) |
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
type result(T, E) = ok(T) | err(E). | |
decl E is error, T1 is any, T2 is any, F is T1 -> result(T2, E) => | |
check(result(T1, E), F) -> result(T2, E). | |
check(R, F) := case R of { | |
ok(V) => F!V, | |
err(E) => err(E) | |
}. |
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
import 'package:flutter/material.dart'; | |
import 'dart:math'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData( |
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
use std::collections::HashMap; | |
use std::sync::Arc; | |
#[derive(Clone)] | |
pub enum Value { | |
Num(f64), | |
Str(String), | |
Struct(HashMap<String, Arc<Value>>), | |
} |
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
use std::ops::{Mul, Add}; | |
struct Parser { | |
parser: Box<Fn(&[u8], usize) -> Vec<usize>>, | |
} | |
fn empty() -> Parser { | |
Parser{parser: Box::new(|_s: &[u8], idx| vec![idx])} | |
} |
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
#[derive(Debug)] | |
struct List<T> { | |
elem: T, | |
next: Option<Box<List<T>>>, | |
} | |
#[derive(Debug)] | |
struct Queue<T> { | |
tail: Option<Box<List<T>>>, | |
head: *mut Option<Box<List<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
use std::collections::HashMap; | |
use std::hash::Hash; | |
struct Memoize<F, T1, T2> where F: Fn(&T1) -> T2 { | |
cache: HashMap<T1, T2>, | |
func: F, | |
} | |
impl<F, T1, T2> Memoize<F, T1, T2> where F: Fn(&T1) -> T2, T1: Eq + Hash, T2: Clone { | |
fn new(func: F) -> Memoize<F, T1, T2> { |
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
;; This is not really Clojure code. I used the .clj extention since it provides the closests syntax highlighting to this imaginary language. | |
(defabst constantly [?t] (-> ?t (-> ?t)) | |
(fn [c] | |
(fn [] | |
(copy c)))) | |
(deftype List [?t] | |
(::nil) | |
(::item ?t (List ?t))) |
NewerOlder