Nyquist Cookie Monster

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Nyquist Cookie Monster

Permanent link to this post Posted by edgar-rft » Sun May 23, 2010 11:45 pm

Category: Nyquist fun and other nonsense - the Audacity Nyquist Cookie Monster plugin

Warning: this plugin has nothing to do with music at all...

Code: Select all
;nyquist plug-in
;version 2
;type generate
;name "Cookie Monster"
;action "Cookie Monster thinking..."
;info "Give me cookie!!!"
;control input "Want cookie" string "Cookie?" " "

;; cookie monster idea stolen from:
;;
;;  David Touretzky
;;
;;  COMMON LISP:
;;  A Gentle Introduction
;;  to Symbolic Computation
;;
;; get a free copy:
;;
;;  http://www.cs.cmu.edu/~dst/LispBook/

(let ((whitespace (format nil " ~a~%" #Tab)))
  (setq input (string-trim whitespace input)))

(setq input (if (string= input "")
                "NOTHING"
                (string-upcase input)))

(setq a "067079079075073069"
      b "079104044032067111111107105101033"
      c "032084104097110107032121111117033"
      d "046046046032109117110099104032109117110"
      e "099104032109117110099104032046046046"
      f "066085082080033"
      g "078111032119097110116032"
      h "071105118101032109101032099111111107105101033033033")

(defun x (x)
  (let ((y (length x)) (r "") (s ""))
    (dotimes (z y r)
      (setq s (strcat s (string (char x z))))
      (when (= 2 (rem z 3))
        (setq r (strcat r (y s)) s "")))))

(defun y (y)
  (string (read (make-string-input-stream y))))

(cond ((string= input (x a))
       (format t "~a~%" (x c))
       (format nil "~a~a~%~a~a~%~a~%" (x b) (x c) (x d) (x e) (x f)))
      (t
       (format t "~a~%" (x h))
       (format nil "~a~a!~%~a~%" (x g) input (x h))))

The cookie monster idea is stolen from:

David Touretzky - COMMON LISP: A Gentle Introduction to Symbolic Computation

Get a copy of the book for free at http://www.cs.cmu.edu/~dst/LispBook/

I apologize for the most unreadable Lisp code ever, but otherwise it's no fun to play. Just simply copy the "cookie.ny" file from the attachment into your Audacity "plug-ins" folder and at the next start of Audacity you'll find a "Cookie Monster" plugin in the "Generate" menu.

Known problems: The Cookie Monster only works with Audacity_1.3.x-beta and above.

No further instructions given here, you must find out yourself how it works...

Have fun - edgar
Attachments
cookie.ny
(1.36 KiB) Downloaded 122 times
edgar-rft
 
Posts: 347
Joined: Sun Jan 20, 2008 12:03 am
Operating System: Please select

Re: Nyquist Cookie Monster

Permanent link to this post Posted by steve » Mon May 24, 2010 4:27 pm

Lol. Me want cookie too :D
A fine example of obfuscated code.

The book looks good also - only had a quick flick through so far but some interesting examples. Shame it doesn't cover *warp* (which I find one of the most confusing aspects of Nyquist), but I realise that's specific to Nyquist.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45630
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Cookie Monster

Permanent link to this post Posted by edgar-rft » Mon May 24, 2010 8:24 pm

Part-II of the game is to find out how the code works ...

I have continued the *warp* discussion under Nyquist Transformation Environment because this is not possible to explain in a few sentences.
edgar-rft
 
Posts: 347
Joined: Sun Jan 20, 2008 12:03 am
Operating System: Please select

Re: Nyquist Cookie Monster

Permanent link to this post Posted by steve » Mon May 24, 2010 11:47 pm

edgar-rft wrote:Part-II of the game is to find out how the code works ...

Took me a while to get this bit:
Code: Select all
(let ((whitespace (format nil " ~a~%" #Tab)))
  (setq input (string-trim whitespace input)))

but it's pretty neat.
The thing that threw me was that I misread " ~a~%" as "~a~%"

In another context it could be adapted to something like:
Code: Select all
(let ((whitespace (format nil "_- ~a~%" #tab #Newline)))
(setq input (string-trim whitespace input)))


The main part of the code is not dissimilar to a plug-in that I wrote at the end of March this year:
Here's an extract from my "AnechoicChamberReverb.ny"

Code: Select all
(defun msg1 ()
(strcat
(string(code-char 97))
(string(code-char 112))
(string(code-char 114))
(string(code-char 105))
(string(code-char 108))
(string(code-char 32))
(string(code-char 102))
(string(code-char 111))
(string(code-char 111))
(string(code-char 108))
(string(code-char 33))))
(defun msg2 ()
(strcat
(string(code-char 32))
(string(code-char 32))
(string(code-char 32))
(string(code-char 32))
(string(code-char 58))
(string(code-char 45))
(string(code-char 41))))
(format NIL "~a~%~%~a" (msg1) (msg2))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45630
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Cookie Monster

Permanent link to this post Posted by edgar-rft » Tue May 25, 2010 12:52 pm

I think this is nowhere really documented, but the Nyquist STRING function can convert code-char numbers directly to strings:

Code: Select all
(string 97)

gives the same result as:

Code: Select all
(string (code-char 97))
edgar-rft
 
Posts: 347
Joined: Sun Jan 20, 2008 12:03 am
Operating System: Please select

Re: Nyquist Cookie Monster

Permanent link to this post Posted by steve » Tue May 25, 2010 5:09 pm

How on Earth did you work that one out :shock:
Or was it a discovery from a lucky typo error? :P
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45630
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Cookie Monster

Permanent link to this post Posted by edgar-rft » Tue May 25, 2010 7:46 pm

stevethefiddle wrote:How on Earth did you work that one out

Can't remember, to tell the truth. But when I learned XLISP together with David Sky, we worked with several other XLISP versions, which all were more or less slightly different to the XLISP that Nyquist uses. We just simply tried out everything of all other XLISPs with Nyquist and found lots of things, which were not documented in the Nyquist manual. This was how the XLISP Documents Collection came to be. I assumed all of these things to be documented in the XLISP Reference, but obviously I have forgotten to write this down. Shame on me.
edgar-rft
 
Posts: 347
Joined: Sun Jan 20, 2008 12:03 am
Operating System: Please select


Return to Nyquist



Who is online

Users browsing this forum: No registered users and 1 guest