Skip to content

Instantly share code, notes, and snippets.

@danlei
Created August 1, 2012 07:25
Show Gist options
  • Save danlei/3224534 to your computer and use it in GitHub Desktop.
Save danlei/3224534 to your computer and use it in GitHub Desktop.
Syntactic motif offsets (Lisp baseline)
(defun indices (input-file output-file)
(with-open-file (in input-file :direction :input)
(with-open-file (out output-file :direction :output
:if-exists :supersede
:if-does-not-exist :create)
(loop with previous-field = nil
for index from 0
for field = (read in nil nil)
while field
if (not previous-field)
do (format out "0")
else if (<= field previous-field)
do (format out " ~w" index)
do (setq previous-field field)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment