Skip to content

Instantly share code, notes, and snippets.

View darius's full-sized avatar

Darius Bacon darius

View GitHub Profile
withal@gmail.com
I have questions about some Common Lisp code. First, I'm unfamiliar with defsubst. Is it a standard macro?
Yes, defsubst is a standard macro in Common Lisp. It is similar to defun, which is used to define functions, but with a key difference: defsubst is used to define inline functions, also known as "substitute functions" or "substitutions".
When a function is defined with defsubst, the compiler is advised to expand the function at compile-time, essentially inlining the function's body wherever it is called. This can lead to performance improvements, as the function call overhead is eliminated. However, it may also increase the size of the compiled code.
Keep in mind that using defsubst is just a suggestion to the compiler, and it is not guaranteed to inline the function. The decision is ultimately up to the compiler's optimization settings and heuristics.
@darius
darius / gist:b463c7089358fe138a6c29286fe2d37b
Last active March 15, 2023 03:24
GPT-4 learning Cant
Hi ChatGPT, can you write some code for me in a dialect of Scheme?
Of course! I can provide you with an example of code in a dialect of Scheme. Here's a simple program that demonstrates a recursive implementation of the factorial function in Racket, a popular dialect of Scheme.
scheme
Copy code
#lang racket
(define (factorial n)
(if (= n 0)
1
;; Some macros to make ELisp more like Cant. Just for my own use.
(put 'be 'lisp-indent-function 1)
(put 'else 'lisp-indent-function 0)
;; TODO is there not a better way?
(font-lock-add-keywords 'emacs-lisp-mode
`((,(regexp-opt '("be" "begin" "else")) . font-lock-keyword-face)))
(defmacro hide (&rest body)
(A conversation with ChatGPT. I added some notes below this gist.)
----
I'll teach you a Lisp-family language called Cant. Here's an interaction in the REPL.
-> (to (I-am name) (out .say "Hi, ~w!\n" name))
-> (I-am 'Alice)
Hi, Alice!
The interpreter prompted with "->". I typed in a definition of the `I-am` function, and then called it at the next prompt. `"Hi, ~w!\n" is a string literal, while `Alice` is a Lisp symbol, quoted with `'` to distinguish it from a variable.
Learning https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/
Notes on the UI:
There's no sandbox that'd let you explore creating new theorems.
(I was stuck on one in Multiplication World but thought I'd be able to
prove a variation with the expressions commuted, (a+b)*t = a*t + b*t.
Hopefully that'd help me get unstuck.)
There are 4 panes (names mine):
Docs Editor State
--- semantle.js 2022-02-19 22:16:27.654749238 -0600
+++ semantle_untested.js 2022-02-19 22:50:24.281830204 -0600
@@ -119,7 +119,13 @@
if (oldGuess === guess) {
color = '#cc00cc';
} else {
- color = '#000000';
+ // XXX untested
+ let guessCount = guessed.size;
+ if (guessCount - 3 < guessNumber) { // Is this one of the most recent guesses?
Structure and Interpretation of Computer Programs https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html
https://www.nand2tetris.org/
https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours
A Philosophy of Software Design
https://www.amazon.com/Philosophy-Software-Design-John-Ousterhout/dp/1732102201/ref=sr_1_1
The Innovator's Dilemma
"""
derived from Kragen Sitaker's http://canonical.org/~kragen/sw/dev3/caronte.py
"""
from __future__ import division, print_function
import itertools
import grammars
from semantics import ast_semantics, ComboSemantics, DictSemantics
grammar_text = r"""
"""
derived from Kragen Sitaker's http://canonical.org/~kragen/sw/dev3/caronte.py
"""
from __future__ import division, print_function
from parson import Grammar
# TODO {'foo'} won't work quite right with FNORD
grammar_text = r"""
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""Caronte: uma pequena lua.
(from http://canonical.org/~kragen/sw/dev3/caronte.py by Kragen Sitaker, hacked a bit by Darius)
This is part of a series of simple exercises I’ve been doing in
hacking programming-language prototypes together from scratch in one
day. After 4½ hours this successfully generates a fractal and I am
going to bed happy. It compiles a tiny infix language into a