Jump to content
Sign in to follow this  

Crazy behavior

Recommended Posts

Dear Friends

I´m working on sketches for a piano piece.

I declared some variable setf´s for manipulating pitches, rhythms, etc.

In the def score instance below, almost in the end of script, OM is evaluating

 a non-declared variable pat-pitches2. "pat-pithes2" or "pat-pitches" is not in any place of this

 script, altought I used this in other file. Can OM pick variables from other files ? 


Why OM is behaving like this ? Seems crazy.





:pitch (ambitus '(g1 g3)(chordize-list (gen-divide '(1 1 1 1 1 1 1 1) (pitch-transpose-n '(0 0 -12 0) pat-pitches2))))
;;; HOW OM IS EVALUATING the variable pat-pitches2 - IT is NOT declared in any place of this file !!!!
   :velocity velocity2





Share this post

Link to post
Share on other sites

This is how lisp works :smile:

Any variable you use in your score needs to be evaluated first.

simple test

(setf var '(1 2 3 4))
=> (1 2 3 4)

(setf var '(a b c d)
=> (a b c d)


Now the var result is (a b c d)

Share this post

Link to post
Share on other sites

> Maybe a good idea would be some kind of FLUSH function that cleans the environment,

> so we don't need to close and reopen the program ;)


Setting (and overwriting!) "global variables" with setf results in side effects, which can be difficult to control. 


Because of that, experienced Lisp programmers use side effects like overwriting "global variables" only rarely and when really necessary, and instead work with constants and "local variables". 


For quick hacking or testing using setf is very convenient and should not be dismissed, but if you are looking for a way to avoid restarting to create a clean slate then use "local variables".





In Lisp parlance, these are dynamic and lexical variables, not quite the same thing as local and global variables in other languages, but perhaps these terms are more easy to understand :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this