< Back to IRCAM Forum

Importing LISP code

I am trying to order to ChatGPT that it creates a lisp code then import it to OpenMusic.
I tried to find how to do it on the site of manual, but I didn’t find it
I found an old conversation on this forum:

It looks like a patch but lisp code file, then it appears into an OM patch.
How to do this?
Or if should I read an article of the manual, where is it?
anyway, this is the lisp code that ChatGPT created.
golden-pow2.lisp (1.7 KB)
I asked to ChatGPT if it can remake with lambda recursive patch of this:
golden16.omp (12.5 KB)
the patch above needs also this:
goldenratio.omp (3.3 KB)

Dear Takuya,

Your question here is multiple. So i will answer slowly:

  1. About ChatGPT’s code, it seems to me very complicated. I prefer UnArtificial Intelligence, and here your code translated in lisp with a lot less of lines:
(defun golden-ratio (num)
  (let* ((gold (/ (+ 1 (sqrt 5)) 2))
        (sec (/ num gold)))
    (list sec (- num sec))))

;(golden-ratio 10)


(defun golden-ratio-iter (num iter)
  (let ((rep (golden-ratio num)))
    (loop for n from 2 to iter
          do (setf rep (flat (mapcar #'(lambda (x) (golden-ratio x)) rep))))
    rep))

;(golden-ratio-iter 10 5)

:slight_smile:

  1. Now there are a lot of ways to execute this code in OM.
    First you can also use omloop in a graphic coding. Your golden16 is not so good since you need to iterate all patching for each generation. So you should use omloop. I know it is rather complicated. But anyhow i join the code along here.
    Now for the PWGL example code-box, in OM we have the Lisp Function box. So you can put inside the lisp code and use the code as a box:

  1. Finally you can also embed the code in a personal library see here:

Now to be complete, as you asked, the documentation is right here:

Here the patches:
golden.zip (3.1 KB)

Hope all this helps

Best
K

Dear Karim,
thank you very much!
I have never tried with accum in an omloop because I always use collect, but I learned this time the usage.
For lisp, I understood how to load it.
I will read also manuals.
Thank you again!

Takuya

1 Like