Jump to content
Sign in to follow this  
PatrickMimran

Have several result options in a function

Recommended Posts

Hello

i tried to have a function who could move one atom or a list anyplace in another list 

,  but now i would like to have the options to move this atom or list with or without parenthesis  , see option a option b  option a2 option b2 .

I have no idea how i can implement several result options in a function  , could you please explain me how to do that 

 

Thank you 

 

Patrick

 

 

her are the functions i'd use as helping functions

 

(defun list-diff (L1 L2)
  (cond
    ((null L1) nil)
    ((null (member (first L1) L2)) (cons (first L1) (list-diff (rest L1) L2)))
    (t (list-diff (rest L1) L2))
  )
)

(defun hasSublistp (lst)
    (cond ((null lst) nil)
          ((listp (first lst)) t)
          (t (hasSublistp (rest lst)))))

 

This is the final one 

 

(defun consxp (rang item lis )
  (setq oldlist lis)
  (setq newlist ( nthcdr rang oldlist ))
   (setq litem (list item))
   
  (cond

   ( ( and ( listp item ) (hassublistp oldlist ))
     ; OPTION A    (append (list-diff  oldlist newlist  ) (list item) (nthcdr rang oldlist )))

     ; OPTION B    (append (list-diff  oldlist newlist  ) item (nthcdr rang oldlist )))

 

   (( and ( atom item ) (hassublistp oldlist ))
; OPTION A2         (append (list-diff  oldlist newlist  ) (cons (list item) (nthcdr rang oldlist ))))

; OPTION B2         (append (list-diff  oldlist newlist  ) (cons item (nthcdr rang oldlist ))))
   
        (( listp item )
         
         (append (list-diff oldlist newlist )   item (nthcdr rang oldlist )))
        
        (( atom item )
         
         (append (list-diff oldlist newlist )   (cons  item  (nthcdr rang oldlist ))))))

 

 

 ;  ( consxp 2 '( a d a) '(a  (d)  c  )) option a ) for example 

 

 

 

 

Share this post


Link to post
Share on other sites

Something like that using conditionnal "if" :

(defun consxp (rang item lis &key (option1 a) (option2 a))
  ......
  (cond
   ( ( and ( listp item ) (hassublistp oldlist ))
    (if (equal option1 a)
     (append (list-diff  oldlist newlist  ) (list item) (nthcdr rang oldlist ))
     (append (list-diff  oldlist newlist  ) item (nthcdr rang oldlist ))))
 
   (( and ( atom item ) (hassublistp oldlist ))
    (if (equal option2 a)
      (append (list-diff  oldlist newlist  ) (cons (list item) (nthcdr rang oldlist ))))
    (append (list-diff  oldlist newlist  ) (cons item (nthcdr rang oldlist ))))
   
       ........

 

Share this post


Link to post
Share on other sites

Désolé  mais je n'arrive pas à 

le faire marcher en suivant vos instructions 

 

(defun consxp (rang item lis &key (option1 a) (option2 a) )
  (setq oldlist lis)
  (setq newlist ( nthcdr rang oldlist ))
   (setq litem (list item))
   
  (cond

   ( ( and ( listp item ) (hassublistp oldlist ))
         (if (equal option1 a))
     (append (list-diff  oldlist newlist  ) (list item) (nthcdr rang oldlist ))
     (append (list-diff  oldlist newlist  ) item (nthcdr rang oldlist )))

   (( and ( atom item ) (hassublistp oldlist ))
         (if (equal option2 a)
      (append (list-diff  oldlist newlist  ) (cons (list item) (nthcdr rang oldlist ))))
    (append (list-diff  oldlist newlist  ) (cons item (nthcdr rang oldlist ))))
   
        (( listp item )
         
         (append (list-diff oldlist newlist )   item (nthcdr rang oldlist )))
        
        (( atom item )
         
         (append (list-diff oldlist newlist )   (cons  item  (nthcdr rang oldlist ))))))

 

 

 ( consxp 2 '(a d a) '(a  (d)  c)     )))

Share this post


Link to post
Share on other sites

i think POSITION-INSERT can do what you want.

 

Example:

(position-insert '((2 3 4)) '((a d a)) '((a  (d)  c)))
=> ((a (d) a d a c))

(position-insert '((2 3 4)) '(((a d a))) '((a  (d)  c)))
=> ((a (d) (a d a) (a d a) (a d a) c))

(position-insert '(2 3 4) '(((a d a))) '((a  (d)  c)))
=> ((a (d) (a d a) c))

 

Please, have a look to the documentation of POSITION-INSERT and to my example and let me know if it's works for your need.

 

SB.

Share this post


Link to post
Share on other sites

Yes it does the work very well but no for lists when i do:

(position-insert 2 '(g8 g3 g6 )  '(c4 c4 c4 c4 c4) :type list)
or
(position-insert 2 '(g8 g3 g6 )  '(c4 c4 c4 c4 c4) :type 'list) 

Thanks  Patrick

Share this post


Link to post
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.

Sign in to follow this  

  • Similar Topics

    • By JulioHerrlein
      In my Dissertation, I worked a way to convert every chord and set in a modulo 12 rhythm,
      so the entire catalog of FORTE are converted to rhythms, following the steps of Babitt:
       

       
      As a hardcore serialist, Babbitt was interested in converting 12-tone rows to rhythms, in a kind of 12-tone rhythm theory.
      Below, Wuorinen show one example of a typical Babbitt idea:
       

       
      For the sake of explaining my idea of function, it's important to have in mind that for Babbitt, the order of the
       row is very important and lead to different results in the pitch to rhythm conversion. Take a look in the example
       below:
       

       
      In the preceeding figure, the order of the C major triad generate different rhythms. In the example (0 4 7) have a
      different result from (4 0 7) or (7 0 4).
       
      In the system I developed in my Dissertation, the order does NOT matter, since (0 4 7), (7 0 4) or (4 0 7) will result
       in exactly the same rhythm, as you can see below:

       
      In my system, the transposition equals rotation (as well as in Babbitt)

       
      And every chord symbol can be transformed in a rhythm:
       

      Even voicings can be converted in longer Rhythms (the more spread the voicing, the longer the rhythm):
       

       
       
      So I did every FORTE SET in the catalog, in this way:
      Below, you can see the example of the rhythm of the major triad (Forte number 3-11b).
      In the 1st bar there is the prime form (0 4 7).
      In each subsequent bar there is a rotation of the first set by 16th note increments.
       
      HERE IS THE POINT, for the sake of the new function !
       
      The note C (that I call Rhythmic Fundamental, the "root" of the rhythm) is being displaced, as
       you can see in the circled notes.
       
      THE SET WRAP AROUND ITSELF, always forming 12 time-points (always twelve 16th notes),
      in a different way from Babbit, where the order of the sets generates longer rhythms.
      THIS WAY IS MORE INTERESTING For Popular and Minimalist Repetition Music, as
       well as 12 tone music.
       
      In the bottom staff, there are the complementary rhythm of the 3-11b set, i.e., the 9-11a
       set. In the catalog, every set is presented alongside its complementary set and every set is
      presented in 3/4 (16th notes) and in 12-8 (with the 8th note as the base value for the increments
       and rotations).

       
      So the function needed would be the one that mirror exacty this kind of conversion, not the tradicional time-point-system conversion,
      so I could use my catolog inside Opusmodus, connecting the diferent sets, like this:
       

       
      Or even using portions of the Rhythmic Sets, by truncating some of them, like this:
       

       
      In the preceeding example, only parts of the 2 sets are used (9 time points out of 12 in the 
      first and 8 time points out of 12 in the second).
       
      So, I hope someone could help me to find a way of implementing this.
      Maybe Janusz or Stephane could find interesting to develop this kind of idea inside
       the software.
       
      All the best !
      Julio Herrlein
    • By JulioHerrlein
      Dear All, 
       
      One interesting thing that could be implemented as a function could be a form of generating Negative Harmony.
      In the video below, there are some explanation of what it is and the origin in the Levy book.
      It was a trendy topic due to the Jacob Collier interview. And there are a lot of fun videos making versions of pop tunes using negative harmony.
       
      The way I understand it, it is simply a kind of mapping notes in relation to an axis, like in the figure below.
       

       
      So we need a function that could map a note in any register to another note in the closest register to the first on.
      So, any  C note will be mapped to G, all Db to F#, all D to F, all, Eb to E, all B to Ab, all Bb to A.
       
      It´s also possible to generate other mappings as well.
       
      I think that replace map or substitute map can do the job, but I´m not sure (I will try), but I find interesting to post it here to explore the idea.
       
      All the best,
       
      Julio
       
      It´s kind of funny to sse in this por versions how every is upside down and how you can generate an entirely new song from exactly the same material.
       
       
       
      POP TUNES with negative harmony:
       
       
       
       
       
    • By torstenanders
      What is the Lisp function for stopping playback (bound to the shortcut cmd-esc)? 
       
      ... I could never add a custom keyboard shortcut to the Opusmodus text editor Hemlock (and I tried), but I just managed adding keyboard shortcuts and a menu for playing Opusmodus snippets and my polyphonic score format to Emacs (thanks to the fact that scores now can be displayed in a separate window). Only need some key for stopping playback as well.
       
      (The main thing I will then miss when using Emacs as the Opusmodus IDE is the close integration of the document, but well, you cannot have everything 🙂  On the plus side, I have a more stable editor and in particular a very good debugger.)
       
      Thanks! 
       
      Torsten
×
×
  • Create New...