Skip to content

Instantly share code, notes, and snippets.

View quasi's full-sized avatar

quasi quasi

View GitHub Profile
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active March 8, 2024 20:05
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@chaitanyagupta
chaitanyagupta / mem-usage.lisp
Last active August 23, 2022 16:51
Memory usage in a Lisp image
;;;; mem-usage.lisp
;;; MEM-USAGE returns memory used by Lisp image in a plist.
;;; MEM-USED prints memory allocated while running the given forms.
;;; Works on SBCL, CMUCL, CCL and CLISP.
;;; Relies on internal APIs (the ones that ROOM uses). Can break at any time.
(defpackage #:mem-usage
(:use #:cl)
(:export #:mem-usage #:mem-used))
@chaitanyagupta
chaitanyagupta / simple-querysets.md
Last active March 16, 2021 13:20
Simple problems to learn how django's querysets work

Simple Querysets

Objective of this exercise is to implement some of the interesting behaviours exhibited by Django querysets:

  • Lazy loading or on-demand evaluation
  • Results caching
  • Filters and chaining

Getting Started

@chaitanyagupta
chaitanyagupta / python-files.md
Last active March 15, 2021 10:20
Learning about files in Python

Files in Python

Basics

Read about reading and writing files in Python.

  1. Why is it recommended to use the with keyword when opening file objects? Why is it important to close a file even if an exception is raised?
  2. The documentation states that, "Using with is also much shorter than writing equivalent try-finally blocks". What is the finally block and, if the with keyword did not exist, could you have used it to properly close a file after it was opened?
  3. The documentation warns: > Calling f.write() without using the with keyword or calling f.close() might result in the arguments of f.write() not being completely written to the disk, even if the program exits successfully.