Skip to content

Instantly share code, notes, and snippets.

View lispm's full-sized avatar

Rainer Joswig lispm

  • Germany
View GitHub Profile
; response to https://kaushikghose.wordpress.com/2017/01/18/common-lisp-doesnt-yield/
; write functions which map a function over stuff
; use I/O streams
(defun map-fastq-stream (in fn)
"Map FN over the IN stream. FN gets called on each second line out of four lines."
(flet ((fastq-reader (in)
(prog2
(read-line in nil)
; Lispworks
(defun fastq-reader (fname)
(let ((in (open fname)))
#'(lambda ()
(prog2 ; <-- prog1 and prog2 are nifty!
(read-line in nil)
(read-line in nil) ; <-- this is the sequence line
(read-line in nil)
; linear-search returns the position of item in the list
(defun linear-search (list item &aux (pos 0))
(dolist (e list nil)
(if (eql e item)
(return pos)
(incf pos))))
(defun linear-search (list item &aux (pos 0))
; https://z0ltan.wordpress.com/2017/02/24/a-piglatin-translator-in-common-lisp-and-contrasting-it-with-the-racket-version/
#|
(defpackage #:piglatin
(:use :cl :cl-user))
; using CL-USER makes no sense, it usually does not export anything.
(in-package #:piglatin)
(defvar *fli1*
(fli:register-module "/Applications/Julia-0.5.app/Contents/Resources/julia/lib/libjulia.0.5.1.dylib"))
(fli:define-foreign-function
(jl-init "jl_init" :source)
((julia-home-dir (:reference-pass :ef-mb-string)))
:result-type :void
:language :C
:calling-convention :cdecl)
#|
* (cffi:use-foreign-library "/Applications/Julia-0.5.app/Contents/Resources/julia/lib/libjulia.0.5.1.dylib")
#<CFFI:FOREIGN-LIBRARY LIBJULIA.0.5.1.DYLIB-505 "libjulia.0.5.1.dylib">
* (cffi:defcfun ("jl_init" jl-init) :void (julia-home-dir :string))
JL-INIT
* (jl-init "/Applications/Julia-0.5.app/Contents/Resources/julia/lib/")
(define-condition invalid-nucleotide-error (error)
((nucleotide :initarg :nucleotide)))
(defvar *nuc-table*
'((#\G . #\C) (#\C . #\G) (#\T . #\A) (#\A . #\U)))
(defun transcribe (nucleotide)
(or (cdr (assoc nucleotide *nuc-table*))
(error 'invalid-nucleotide-error :nucleotide nucleotide)))
(defun sunset (color &key (shift-list '(1 4/3 4/3)))
"Redshifts the #RRGGBB color."
(format nil
"#~{~X~}"
(loop for start in '(1 3 5) and shift in shift-list
collect (truncate (parse-integer color
:start start
:end (+ start 2)
:radix 16)
shift))))
(defun hyphae (sand size fn itt rad mid)
(let ((curr (make-hash-table :test #'equal))
(hits 0))
(labels ((init (snk n)
(loop for i from 0 below n do
(setf (gethash
(add-vert! snk (rnd-in-box 250 250 :xy '(250 250)))
curr)
0)))
; https://github.com/inconvergent/snek
(proclaim '(inline last1 single append1 conc1 mklist))
(proclaim '(optimize speed))
(asdf:defsystem "snek"
:description "SNEK is Not an Acronym"
; :version "0.0.1"
:author "Anders Hoff"