Nyquist Cookie Monster

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

Warning: this plugin has nothing to do with music at 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
cookie.ny (1.36 KB)

Lol. Me want cookie too :smiley:
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.

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.

Took me a while to get this bit:

(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:

(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”

(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))

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

(string 97)

gives the same result as:

(string (code-char 97))

How on Earth did you work that one out :open_mouth:
Or was it a discovery from a lucky typo error? :stuck_out_tongue:

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.