http://blog.fogus.me/2023/01/06/code-riffs/ [fpjs] read [joc] read or learn more Send More Paramedics l l l Fogus' Thoughts on life, programming, and thinking c clj erl pl frink fth cl org pure icl qi Follow me on Twitter... # or RSS... # Run this blog in mobile 2023 2022 2021 2020 2019 2018 2017 2016 2015 2014 2013 2012 2011 2010 2009 2008 2007 2006 2005 2004 2003 2002 Code Riffs Jan 6, 2023 [vs] Once upon a time I was deep into the MD/DC/VA area punk scene, and believe it or not I played in my share of bands and participated in my share of punk shows -- both in the crowd and sometimes even on stage. I look back on this time fondly, but to be honest I can't say that I ever contributed any song to the universe of music that was worth listening to. That said, while I can't claim to have been a talented song-writer, like many aspiring musicians I did discover my fair share of riffs along the way. A riff is an interesting little musical phrase that one often comes across whilst playing around with a guitar in a casual fashion. Very often riffs form the seeds of what becomes fully-realized songs. Sometimes these songs are good and sometimes they're not, but in most cases they are grown like crystals from the original musical fragment found on the fret-board. For musicians, both practicing and aspiring, the riff represents a universe of potential out of which any number of potential works of musical art may spawn. A few years ago I devised a phrase that I called Code Painting describing source code that: told a story, was usually not generally useful, was beautifully abstract, and created in the spirit of exploration. Unlike a code painting, a code riff is more atomic and often addresses a singular notion. If I were to characterize the attributes of a code riff then perhaps the following will suffice: * A code riff exists independent to a project narrative * A code riff need not be useful * A code riff is often "found" during the act of playful programming or sprung forth from one's mind * A code riff should be beautiful, abstract, and as amusing if possible * A code riff should invoke Huh? A ha! Ha ha! ^1 In my time I've created my share of code riffs; some that inspired something more and some still ripe with potential. If you're interested in some code riffs then a few are available on Github as Tori Lisp, Evalive, and Unfix and additionally the break macro in chapter 17 of The Joy of Clojure. Here's a Clojure code riff from a presentation that I gave many years ago called "The Magnificent Seven": (def NIL ((fn [x y] (if (= x y) x)) = (= = =))) (def CAR (fn [[h & _]] h)) (def CDR (fn [[_ & t]] t)) (def CONS (fn [h t] (fn ([] h) ([_] t)))) (def FIRST (fn [s] (s))) (def REST (fn [s] (s NIL))) (FIRST (CONS 1 (CONS 2 NIL))) ;;=> 1 (FIRST (REST (CONS 1 (CONS 2 NIL))) ;;=> 2 Do you have any code riffs to share? :F --------------------------------------------------------------------- 1. Rich Hickey, the creator of Clojure, is a master of code riffs. - Related posts: 1. nil, nothing, and notset 2. Comparing Lines of Code: Scala and Clojure (FUD version) 3. On Lisp -> Clojure (Chapter 5) 4. On Lisp -> Clojure (Chapter 4) 5. On Lisp -> Clojure (chapter 2) One Comment, Comment or Ping 1. DJ Adams Nice post. I like the idea using the word "riff" here, it fits nicely into my brain. I, err, riffed on some similar "pattern" ideas in this presentation https://docs.google.com/presentation/d /1xgOHBFNOjg6dFz1qHkSpB9VVjKxgjkugoxo13wAZYU0/edit#slide=id.p and in this post https://qmacro.org/blog/posts/2017/02/19/ the-beauty-of-recursion-and-list-machinery/ Jan 6th, 2023 Reply to "Code Riffs" [ ] Name (required) [ ] Mail (required) [ ] Website [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] Submit [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] [ ][Submit] Copyright (c) 2002 - 2011 by Fogus (license information) read about my policy on affiliate links Theme heavily influenced by Ryan Tomayko [ | Log in | top]