This file contains hidden or 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 random | |
class Die: | |
def __init__(self, n): | |
self.sides = n | |
def roll(self): | |
return random.randint(1, self.sides) | |
dice = [Die(6), Die(6), Die(6)] |
This file contains hidden or 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 (java.lang.invoke MethodHandles | |
MethodHandles$Lookup | |
MethodType | |
MethodHandle)) | |
(def ^MethodHandle abs-handle (.findStatic (MethodHandles/lookup) | |
Math | |
"abs" | |
(MethodType/methodType Long/TYPE Long/TYPE))) |
This file contains hidden or 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
; source https://github.com/woodrush/sectorlisp-examples/blob/main/lisp/basic.lisp | |
; Common Lisp translation: [email protected], 2022 | |
; https://gist.github.com/lispm/a2f56a1a6dc5599a039eb7134d99cd4a | |
(defun basic-example () | |
(BASICINTERPRETER | |
(QUOTE ( | |
(10 REM FIND AND PRINT PRIME NUMBERS BELOW N_MAX. ) | |
(20 LET N_MAX = (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) ) | |
(30 LET I = (1 1) ) |
This file contains hidden or 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
;; LISP-2 acting like LISP-1 (by Ron Garrett) | |
(defmacro define (name&args &body body) | |
(let ((name (car name&args)) | |
(args (cdr name&args))) | |
`(defun ,name ,args | |
(flet ,(mapcar (lambda (arg) `(,arg (&rest args) (apply ,arg args))) | |
args) | |
,@body)))) | |
This file contains hidden or 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
CFLAGS=-std=c99 -pedantic -Wall -Werror | |
.PHONY: run forth | |
run: forth | |
./forth test.fs | |
forth: forth.c | |
$(CC) $(CFLAGS) -o forth forth.c |
This file contains hidden or 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 <string.h> | |
#include <assert.h> | |
FILE *in; long M[1<<24]={0}, *D, *R, H=0x130000, IP=0, T; | |
long getu() { long t, h = getc(in); if (h < 0xC0) return h; | |
t = ((h&0x1F) << 6) | (getc(in) & 0x3F); if (h < 0xE0) return t; | |
t = ( t << 6) | (getc(in) & 0x3F); if (h < 0xF0) return t; | |
t = ( t << 6) | (getc(in) & 0x3F); return t & 0x1FFFFF; } | |
void putu(long c) { if (c < 0x80) { putchar(c); return; } | |
if (c < 0x7FF) { putchar(0xC0|(c>>6)); } else { |
This file contains hidden or 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
// v is vector testing equiv | |
// obj is RHS operand, potentially infinite seq | |
else if(obj instanceof List) | |
{ | |
Collection ma = (Collection) obj; | |
if(ma instanceof Counted) | |
if(ma.size() != v.count()) | |
return false; |
This file contains hidden or 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
// Tiny FORTH by T. NAKAGAWA 2004/07/04-10,7/29,8/5-6 | |
/* | |
Tiny FORTH | |
Experimental Forth for Arduino | |
T. Nakagawa | |
2004/07/10 | |
*/ | |
#include <stdio.h> |
This file contains hidden or 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
(defn- spec-checking-fn | |
"Takes a function name, a function f, and an fspec and returns a thunk that | |
first conforms the arguments given then calls f with those arguments if | |
the conform succeeds. Otherwise, an exception is thrown containing information | |
about the conform failure." | |
[fn-name f fn-spec] | |
(let [fn-spec (@#'s/maybe-spec fn-spec) | |
conform! (fn [fn-name role spec data args] | |
(let [conformed (s/conform spec data)] | |
(if (= ::s/invalid conformed) |
This file contains hidden or 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
(ns clojure.spec.test.alpha | |
(:refer-clojure :exclude [test]) | |
(:require | |
[clojure.pprint :as pp] | |
[clojure.spec.alpha :as s] | |
[clojure.spec.gen.alpha :as gen] | |
[clojure.string :as str])) | |
(in-ns 'clojure.spec.test.check) | |
(in-ns 'clojure.spec.test.alpha) |