(defvar measure-1 '()) measure-1
(cons 'c4 measure-1) measure-4 Note that the value of measure-1 is still NIL, you have to setf the variable to its new value: (setf measure-1 (cons 'c4 measure-1)) measure-1
(setf measure-1 (cons 'd4 measure-1)) measure-1 The duple-cell structure is now:
(car measure-1) (cdr measure-1)
(defvar measure-2 (list 'b3 'c4 'b3 'c4 'a3)) Note that this is similar to do: (setf measure-2 (cons 'b3 (cons 'c4 (cons 'b3 (cons 'c4 (cons 'a3 nil))))))
(append measure-1 measure-2)
(pop measure-2) measure-2 (push 'b3 measure-2)
(defvar a-notes (list measure-1 measure-2 '(d4 c4)))
(car a-notes) ;;; this is measure-1 (car (cdr a-notes)) ;;; this is measure-2 (car (cdr (cdr a-notes))) ;;; the same as measure-1
(second (car a-notes)) or (second (first a-notes)) or (nth 1 (first a-notes)) (second (cadr a-notes)) or (second (first (rest a-notes))) or (nth 1 (nth 0 (rest a-notes))) and the first and last elements of a-notes have the same content: (first a-notes) (second (rest a-notes))
(eq (nth 1 (first a-notes)) (nth 1 (nth 0 (rest a-notes)))) (eq (first a-notes) (second (rest a-notes)))
(eq 1.0 1.0) (eq "hello" "hello")
(eql 1.0 1.0) (eql (nth 1 (first a-notes)) (nth 1 (nth 0 (rest a-notes)))) but: (eql (first a-notes) (second (rest a-notes))) (eql "hello" "hello")
(equal (first a-notes) (second (rest a-notes))) (equal "hello" "hello") but: (equal 1 1.0)
(equalp 1 1.0) (equalp "Hello" "HELLO")
eq eql equal equalp
(setf a-notes-copy (copy-list a-notes))
(reverse (nth 1 a-notes))
(nreverse (nth 1 a-notes-copy)) (nth 1 a-notes-copy)
(remove 'c4 (nth 0 a-notes))
(delete 'c4 (nth 0 a-notes-copy)) (nth 0 a-notes-copy)We can remove-duplicates from a list (or repeated notes from a score...):
(remove-duplicates (nth 1 a-notes))
(delete-duplicates (nth 1 a-notes-copy)) (nth 1 a-notes-copy)And finally, we can substitute one element for another in a list (or change wrong notes from a score... which are them?):
(substitute 'g4 'c4 (nth 0 a-notes))The destructive version of substitute is the function nsubstitute:
(nsubstitute 'g4 'c4 (nth 0 a-notes-copy)) (nth 0 a-notes-copy)
©1996-98 by Juan Pampin, juan@ccrma.stanford.edu