recursive function

9 views
Skip to first unread message

ole

unread,
Oct 12, 2013, 11:43:43 AM10/12/13
to symbolic...@googlegroups.com
Hi,

I'am stucked with the following:

(setq zeile2 (open-sequence '(er scheint unbedeutend zwo)))
-->(e r s c h e i n t u n b e d e u t e n d z w o)

;this does not work
(defun anagram (sym lis)
(cond ((endp lis) nil)
((equal sym (first lis)) t)
(t (anagram (rest lis)))))

(anagram 's zeile2)
-->error

;this works:

(defun anagram (lis)
(cond ((endp lis) nil)
((equal 's (first lis)) t)
(t (anagram (rest lis)))))
-->t
(anagram zeile2)

Something is wrong with that variable thing.. do I have to use let somehow..?




thanks!

ole




www.oleschmidt.de



ole

unread,
Oct 12, 2013, 11:57:34 AM10/12/13
to symbolic...@googlegroups.com
answering my own question, I found the error:
it must be like this:

(defun anagram (sym lis)
(cond ((endp lis) nil)
((equal sym (first lis)) t)
(t (anagram sym (rest lis)))))


ole


www.oleschmidt.de
> --
> 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.

pstone imap

unread,
Oct 12, 2013, 12:11:55 PM10/12/13
to symbolic...@googlegroups.com
Btw, anagram is permuted reordering of a word filtered with a list of meaningful words.

Your anagram function works the same as Lisp member function, which tests if symbol is a member of a list.

Peter

ole

unread,
Oct 12, 2013, 2:09:31 PM10/12/13
to symbolic...@googlegroups.com
but it gives me t or nil instead of the rest of the list..

How can I compare two lists- see if the have the same symbols in common like

(a b c d e)
(d c b e a)

are containing the same symbols. How can I test that? Something like two recursion functions, one in another..?

thanks!



www.oleschmidt.de

pstone imap

unread,
Oct 12, 2013, 4:21:54 PM10/12/13
to symbolic...@googlegroups.com
exact anagram test

(member '(a b c d e) (find-permutations '(d c b e a)) :test #'equal)
--> nil or subsequence, which means t

if you merely want to test if all list1 symbols are member of list2

(member-all '(a b e d e) '(d c b e a))
--> t

it is predefined in 17th century composer package
it is wider test, and you need to adapt it

one possibility is to test lengths of unique symbols and member-all

(setq l1 '(a b e d e))
(setq l2 '(d c b e a))

(and (equal (length (remove-duplicates l1))
(length (remove-duplicates l2)))
(member-all l1 l2))
--> nil

or cross member them

(and (member-all l1 l2)
(member-all l2 l1))
--> nil

or

(find-difference '(a b e c d) '(d c b e a))
--> nil

but here you would need also to compare if both are of same length

permutations is exact, but even short 10 elements make 3628800 permutations, 11, 12, 13 will jam your machine
I'm not sure if the other ways are always exact but work fast on long sequences

Peter

ole

unread,
Oct 12, 2013, 5:05:31 PM10/12/13
to symbolic...@googlegroups.com
thanks!

Unfortunatly there is no documentation about member (and its flags)..
(although it is a lisp function, I run into it in several lisp tutorials..)
>
>
>
>
> (member-all '(a b e d e) '(d c b e a))
> --> t
>
> it is predefined in 17th century composer package
>
Do you mean member-all ist predefined in 17 century pianist? So it is a SCOM function?
(just peeked into the 17 century pianist, looks very interesting, as far as I did understand
the code is hidden, it is just a sort of surface or how does it work with all that
*global variables*?)

>
>
> (find-difference '(a b e c d) '(d c b e a))
> --> nil

that one I was looking for but could not find..

What would be an interesting feature: to have a sort of tagging system so you can tag for
example find-difference with "compare" and "equality" "in common" and the Look up search will bring
find-difference up when typing in "equality..
I had spend a lot of time (re-)searching functions..



>
> I'm not sure if the other ways are always exact but work fast on long sequences
>
I will make some tests with very long sequences and will share the results (if some things go strange).

Thanks again for your support

ole




ole

unread,
Oct 12, 2013, 6:15:47 PM10/12/13
to symbolic...@googlegroups.com
I'am fiddeling around with what you gave to me and do not understand what the :test #'equal flag does to member, it chooses from lots of permutations 10?



(member '(a b c d e) (find-permutations '(d c b e a)) :test #'equal)
-->((a b c d e) (a b c e d) (a b e d c) (a b e c d) (a e d c b) (a e d b c)
(a e c d b) (a e c b d) (a e b d c) (a e b c d))

ole

pstone imap

unread,
Oct 16, 2013, 8:46:13 AM10/16/13
to symbolic...@googlegroups.com
Member is Lisp function and found in Full Lisp Manual in SCOM7 System / Lisp Tools menu. SCOM documents only mostly-often required Lisp functions. Maybe Lisp Tools could be extended a bit. I'll mark this to work stack.

Member-all is undocumented SCOM function. Not all SCOM functions are documented, because they usually serve their purpose when implementing documented functions, and they are not directly related to composing. But there can be many useful tools for the advanced user, that could be documented in Programming category. I'll mark this to work stack.

17th century package implements positional chords, triad enhancement system, modulation path search, generation and analysis functions. These are well documented.

17th Century Pianist score uses harmonise-modulation-zones, which is undocumented, but its parameters are mostly explained in the score. It simulates piano performer of that age, when focus is on one hand the other hand gets less focus, which swap in serial. The poor performer is been supervised by Mr. Bach himself, and so he needs to quickly interpolate mostly satisfying intervals if the theme supplied by the great master cannot be executed in progressive modulations and in harmony with the other hand. It is not a very general way to compose nowadays, indeed (loop copying, he he), and thus it is non-documented.

SCOM7 Harmonizer score also shows how to apply ornament-symbols-lengths from 17th Century package, which is undocumented function, too. It applies division patterns to related symbol/length input, and enhances these with counting and division patterns, which are realized randomly according to rules. It is not general ornamentation system, but just a hack to add some typical performance trills here and there, thus not documented.

About tagging. SCOM7 lets you tag interesting files that you want to work later. When you have used SCOM for years, there are lots of stuff in your folders. While browsing you hit some interesting sounding stuff. Tag it for later. Listen more and tag them. When you are in production mode check out those tags. Or when listening some documents, find interesting function, tag it. Tags remind these kind of discoveries.

Keyword tagging. Add a comment line in a score ; cool stuff. Locate finds the score later when you search cool stuff. I noticed that Notes are not yet searched. Add your keywords in notes now - I'll mark that they should be searched in the future.

Peter
Reply all
Reply to author
Forward
0 new messages