Jump to content

Parameter as variable?


Recommended Posts

Hi,

I want to make the following construction:

(defun mapping-integers (x y)
  (interval-to-pitch (integer-to-interval x) :start y))

(mapping-integers '(0 4 5 9 11) 'c5)


I get an error-warning having the wrong start parameter, how could this be done?

I have a list of integers (0 4 5 9 11) and a list of root notes (c5) and want them to process to get lists like (c5 e5 f5 a5 b5)..

ole

Link to comment
Share on other sites

to answer my own question, I found a workaround:

(defun mapping-integers-2 (x y)
  (chordize (pitch-transpose (pitch-to-integer y) (integer-to-pitch x))))

(mapping-integers-2 '(0 4 5 9 11) 'g4)


nevertheless I would like to know if it is possible to handle the keyword parameters with variables..

Link to comment
Share on other sites

Solution:

(pitch-transpose-start 'c5 (integer-to-pitch '(0 4 5 9 11)))
=> (c5 e5 f5 a5 b5)


with &key

(defun mapping-integers (l &key start)
  (if start (pitch-transpose-start start (integer-to-pitch l))
    (integer-to-pitch l)))

(mapping-integers '(0 4 5 9 11) :start 'c5)
=> (c5 e5 f5 a5 b5)
 
with &optional
(defun mapping-integers2 (l &optional start)
  (if start (pitch-transpose-start start (integer-to-pitch l))
    (integer-to-pitch l)))

(mapping-integers2 '(0 4 5 9 11) 'c5)
=> (c5 e5 f5 a5 b5)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy