Jump to content
Sign in to follow this  
jfcharles

Attribute substitution

Recommended Posts

Hi,

Newcomer here, please point me to resources if I'm missing something obvious.

Here is a function that substitutes attributes when they are combined. Is there an easier way of doing this? Thanks!

(defun attribute-substitution (new old list-of-attributes) 
    (mapcar (lambda (list) (join-attributes list)) 
    (substitute-map new old (mapcar (lambda (attr) 
    (disjoin-attributes attr)) list-of-attributes))))

(attribute-substitution 'pizz 'arco '(ten+arco pizz arco))
=> (ten+pizz pizz pizz)

 

Share this post


Link to post
Share on other sites

And here is what I have as "replace" version. For instance if you want to replace pizz by arco and arco by pizz:

(defun attribute-replace (new-old-list list-of-attributes) 
    (mapcar (lambda (list) (join-attributes list)) 
    (replace-map new-old-list (mapcar (lambda (attr) 
    (disjoin-attributes attr)) list-of-attributes))))

(attribute-replace '((pizz arco) (arco pizz)) '(ten+arco pizz arco pizz+marc))
=> (ten+pizz arco pizz arco+marc)

Let me know if there are other ways of doing this, thanks!

Share this post


Link to post
Share on other sites

The function allows you to use the omn-form sequence as well: 🙂

(attribute-replace '((pizz arco) (arco pizz)) '(q c4 ten+arco e4 pizz f4 arco d4 pizz+marc))
=> (q c4 ten+pizz e4 arco f4 pizz d4 arco+marc)

 

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  

×
×
  • Create New...