variable with names dependent on arguments

29 views
Skip to first unread message

Musicologo

unread,
Dec 4, 2013, 11:55:31 PM12/4/13
to symbolic...@googlegroups.com
1) How can I use arguments as a source to name different variables in new functions??
I mean something like


(defun functionx (a)

`(progn
(setq ,a blabla)
(setq ,a2 blabla2)
(setq ,awow blabla3)
)
))


So that all these variables have their name coming from the argument?? This is relevant to me so that I can then do something like

functionx (a)  --> a, a2, awow
functionx (b)  ---> b, b2, bwow
functionx (boat)  ---> boat, boat2, boatwow

or even a loop

and I get externally  a, a2, awow, b, b2, bwow, boat, boat2, boatwow with different names and none of them clashes!


2) I would also like to know how to append/attach and the reverse (detach, extract) characters in general to variables, arguments, symbols, etc...
it would be useful to be able to do something like
(function?  '(12)  '(a b c d)) ---->  '(12a 12b 12c 12d)

I've explored functions like concatenate or merge or compress but it seems I'm not using the right syntaxes. I believe I have a syntax problem using them.






pstone imap

unread,
Dec 5, 2013, 3:28:04 AM12/5/13
to symbolic...@googlegroups.com
(defun functionx (name)
  (set name 'blabla)
  (set (compress (list name 2)) 'blabla2)
  (set (compress (list name 'wow)) 'blabla3))

(functionx 'a)

a
--> blabla
a2
--> blabla2
awow
--> blabla3

(functionx 'boat)

boat
--> blabla
boat2
--> blabla2
boatwow
--> blabla3

Peter

--
You received this message because you are subscribed to the Google Groups "Symbolic Composer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symboliccompos...@googlegroups.com.
To post to this group, send email to symbolic...@googlegroups.com.
Visit this group at http://groups.google.com/group/symboliccomposer.
For more options, visit https://groups.google.com/groups/opt_out.

Musicologo

unread,
Dec 7, 2013, 11:49:09 PM12/7/13
to symbolic...@googlegroups.com
I'm sorry but for some reason this kind of construction is not helping my problem at all. I don't want to have "blabla" out. I want to have the argument changed out!...

I'm giving a concrete example this time, after playing around with compress, in order to have indexed zones.
In this particular example I want to define an encapsulated macro (I'm using the template I've seen in the forum in an old post):


(defmacro functionx (section)

  `(progn
     `(progn
  (setq st (string ,section))
  (setq xxx (intern (concatenate 'string st "1")))
  (setq xxx2 (intern (concatenate 'string st "2")))
 )

(def-section ,xxx
   zone '(4/4)
   tonality (activate-major c 3)
   length (1/8)
   symbol (a b c d e f)
   channel 1
   program 1
   )

(def-section ,xxx2
   zone '(4/4)
   tonality (activate-minor e 3)
   length (1/8)
   symbol (f g e d b a)
   channel 1
   program 1
   )
)
)


What am I doing wrong??
When I call (functionx 'a)

I wanted to get zone a1 and zone a2 and instead "the variable xxx is unbound".
I tried to wrap things around `(progn so that the definitions would be evaluated first, but I don't know what am I doing wrong.
I need that the argument to be read, THEN evaluated and concatenated into arg1, arg2, arg3, etc... THEN evaluated as a name of section, and only then sections with the name argX to be outputed...


pstone imap

unread,
Dec 8, 2013, 8:38:43 AM12/8/13
to symbolic...@googlegroups.com
btw, make simple questions, specify input, output, code what you tried, and why the code did not work expected way, avoid general questions such as stating you want blabla output, and cut the example to barebones

you specified you wanted blabla output, that's what you got :-)

your example sections here are also fuzzy, no default or instrument, why (activate-major ..) why not (activate-tonality (major ..)), missing quotes, and any reason to use very fuzzy `(progn `(progn … ?!

def-section is complex macro that parses free-form stuff, and does its things by side-effects
better to call it alone
easier to test your expansions in segments, too -- you know where you go wrong

(defun functionx (section)
  (eval `(progn
           (setq st (string ',section))
           (setq xxx (intern (concatenate 'string st "1")))))
  (eval `(def-section ,xxx
            piano
               zone '(4/4)
               tonality (activate-tonality (major c 3))
               length '(1/8)
               symbol '(a b c d e f)
               channel 1
               program 1)))

(functionx 'something)

(play-file nil
   piano '(something1)
)

Peter

Musicologo

unread,
Dec 8, 2013, 3:05:42 PM12/8/13
to symbolic...@googlegroups.com
Ok! Thank you very much.
I usually do very general questions so they can fit to anybody else and also to get a general answer that I can apply in any situation.
I figured out it would be "impossible" to post my entire program and ask what am I doing wrong, so I've tried to "simplify" it.
Most of the times these issues are related with syntax issues, missing quotes, misunderstanding on how a command works..
But I will try to be more explicit next time instead of "general".

Musicologo

unread,
Dec 8, 2013, 9:50:19 PM12/8/13
to symbolic...@googlegroups.com
I'm stuck again on this encapsulated problem. I managed to even put several zones in the package, and in the "evaluations" they went ok. But on the final listening all failed.
I went back to basics and realized the issue happened even with only one zone.




(defun functionx (section)
  (eval `(progn
           (setq st (string ',section))
           (setq xxx (intern (concatenate 'string st "1")))
          ))

  (eval `(def-section ,xxx
            piano
               zone '(4/4)
               tonality (activate-tonality (melodic-minor c 4))

               length '(1/8)
               symbol '(a b c d e f)
               channel 1
               program 1))




        )

---> this is ok


(functionx 'd)
(functionx 'e)

---> both these expand ok (they create zones d1 and e1)
(def-tempo 80)

--> ok

(play-file nil
   :all '(d1 e1 d1)
)

---> error :(  "No music found in score").

pstone imap

unread,
Dec 9, 2013, 5:11:11 AM12/9/13
to symbolic...@googlegroups.com
You should be able to solve this by yourself. Hint: where's velocity slot … I'd also use default slot for tempos.

Define sections first MANUALLY to ensure they chain well.
Once score is working, wrap sections into macros one by one.

Peter
Reply all
Reply to author
Forward
0 new messages