Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 4 days, 10 hours ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

lisp code in libraries

Author 3 Subscribed Users |
Profile photo of fdsdb
fdsdb

Hi All,

I am trying to translate a PWGL library I made last Summer, into OM.
I am not very skilled in lisp programming, so I should need following information:

– how can I preload another OM library in loading my own? I have read documentation, specifically (require-library “name-of-library-to-be-loaded”), I have tried to put it in main lisp document of my library (name-of-library.lisp), but in loading my library OM doesn’t ask me for loading other library (specifically I need to laod Situation library), and actually it is not loaded, I must load it by hand.
– I need to incorporate two Situation library objects in my code: csolver and ch-sol. How can I define them in my code?

Sorry for not being extremely clear, I am not a programmer. Thanks to everyone in advance for help.

Ciao

fdsdb

March 7, 2018 at 10:08 #25806
Profile photo of anders
anders

Hi fdsdb.

Including (require-library “Situation”) in any loaded lisp-file (e.g. mylib.lisp) should load “Situation”, provided “Situation” is somewhere in your library search path.

If this doesn’t work out of the box, i suspect you’re not in the :openmusic package. Easiest to begin with is to include a line (in-package :om) somewhere near the top of your “mylib.lisp”.

– I need to incorporate two Situation library objects in my code: csolver and ch-sol. How can I define them in my code?

If you are in the :om-package, they are already there once “Situation” gets loaded.

If you want to set up a separate package for your lib, which you should when it grows larger, you can find some ways to achieve this by looking into some other libraries, and also importing symbols from external packages.

Good luck!

March 7, 2018 at 11:51 #25809
Profile photo of fdsdb
fdsdb

Dear Anders,

For the moment thank you very much for your fast reply. I am in (in-package :FDSDB_XXth_CT), following OM documentation about new libraries. I am going to do some trial, perhaps I will again have to ask for help. If I resolve I will post the solution and I hope in some month also the library… :-).

Thank you again, ciao

Fabio

March 7, 2018 at 15:08 #25816
Profile photo of fdsdb
fdsdb

Hi,

Sorry, I must return to ask for help. I apologize for long message.

I can not succeed in automatically loading Situation library on loading my library. At the moment it consists only of two files: FDSDB_XXth_CT.lisp (main file) and Dodecaphony.lisp in sources folder of my library files.
This is the beginning of main file:

(defvar FDSDB_XXth_CT)
(defpackage FDSDB_XXth_CT (:use “COMMON-LISP” “OpenMusic” “CL-USER”))
(in-package :FDSDB_XXth_CT)

I don’t succeed in specifying something for loading Situation library, in (:use ….) instruction or elsewhere.

This for running (I hope) the following code, for generating an all interval series:

(om::defmethod! All-Interval-Series ((Lower-pitch number))
:initvals ‘(6000) ; an initial values list
:indoc ‘(“Lower pitch” ) ; a string list with short docs
:icon 112 ; the icon
:doc “All-Interval-Series.
A series that contains all intervals without repetitions.
This example requires some hand modification, putting some pitches into different octave register to have a real All-Interval series”

(ch-sol (Csolver (12 (|60_72|) (1) (2 7) (list (x-dst_rnw ‘(11 1)) (pts_rnw ‘(12 0 t))) (1_11)))))

Lower-pitch parameter is not necessary, but I don’t know how to eliminate the input in an object. The code would be the code translation of a patch that runs without problems (it is one of tutorial 3 in Situation library). On evaluating the All-Interval-Series object I have the error enclosed in the screenshot. I understand that of course ch-sol and company are not functions of my library (at the top of Dodecaphony.lisp I have (in-package :FDSDB_XXth_CT) ). But I don’t know how to laod and use Situation functions.

Thank you all in advance for eventual help.

Ciao

fdsdb

Attachments:
  1. Schermata-2018-03-07-alle-16.41.26

    Schermata-2018-03-07-alle-16.41.26.png

  2. Schermata-2018-03-07-alle-16.41.26

    Schermata-2018-03-07-alle-16.41.26.png

March 7, 2018 at 16:53 #25817
Profile photo of Karim
Karim

Hi Favio,

As Anders put it you should first put these lines :

(in-package :om)
(require-library “Situation”)

Before doing : (in-package :FDSDB_XXth_CT)

Because then your require-library function will not be an om func .

So put first :
(in-package :om)
(require-library “Situation”)
then :
(defvar FDSDB_XXth_CT)
(defpackage FDSDB_XXth_CT (:use “COMMON-LISP” “OpenMusic” “CL-USER”))
(in-package :FDSDB_XXth_CT)

and when you call a Situation function inside your code , just put om::csolver
add the om::

I hope this helps

best
K

March 7, 2018 at 17:23 #25820
Profile photo of fdsdb
fdsdb

Dear KArim,

Thank you, and thanks to Anders, too: now it seems better, only I receive another error (I enclose the screenshot), I have googled about illegal car, but I am not able to resolve it.
I have adjusted the code of the beginning of my FDSDB_XXth_CT.lisp file, and the code of All-Interval-Series object now is

(om::ch-sol (om::csolver (12 (|48_72|) (1) (2 7) (list (om::x-dst_rnw ‘(11 1)) (om::pts_rnw ‘(12 0 t))) (1_11))))

I will try again tomorrow…

Ciao

Fabio

Attachments:
  1. Schermata-2018-03-07-alle-19.54.17

    Schermata-2018-03-07-alle-19.54.17.png

  2. Schermata-2018-03-07-alle-19.54.17

    Schermata-2018-03-07-alle-19.54.17.png

March 7, 2018 at 19:55 #25821
Profile photo of Karim
Karim

Hi Fabio

It’s just that you have a wrong parenthesis. Here it works…

(om::ch-sol (om::csolver 12 ‘(|48_72|) ‘(1) ‘(2 7) (list (om::x-dst_rnw ‘(11 1)) (om::pts_rnw ‘(12 0 t))) ‘(|1_11|)))

Best
Have fun

K

March 8, 2018 at 02:24 #25824
Profile photo of Karim
Karim

… and sorry also watch out for the quotes i added…

note :
‘(1 2) is equivalent to (list 1 2)

K

March 8, 2018 at 02:28 #25825
Profile photo of fdsdb
fdsdb

Dear Karim,

Thank you very much, it perfectly runs.
Just a curiosity, if possible (I don’t want to annoy you, I apologize if so): how can one arrive to understand correct setting for parenthesis in a particular OM object code?
In general I am studying Lisp and parenthesis and so on, but this case seems pertinent to om::csolver.
Must I observe original lisp code of the object?
Thank you again, ciao

Fabio

March 8, 2018 at 08:35 #25826
Profile photo of Karim
Karim

Dear Fabio,

One thing: here it is not a special case of csolver. You just misspelled the expression. So i will try to explain lisp basics and hope i will be as clear as i could:

1.
(maybe you can skip this, but it is just a reminder)
In lisp you have either atoms or lists. So if it is not a list it is an atom.

we can use the atom function to test this :

(atom nil) => T
(atom ‘some-symbol) => T
(atom 3) => T
(atom “moo”) => T
(atom (cons 1 2)) => NIL
(atom ‘(1 . 2)) => NIL
(atom ‘(1 2 3 4)) => NIL
(atom (list 1 2 3 4)) => NIL

2.
Starting from this if you want to “transcribe” an om function in a lisp expression you should proceed so :

let’s take om+ function :

here we have two atoms

(om+ 3 4)
=> 7

Now we try with an atom and a list :
(om+ 3 ‘(3 4))

notice you should either use the quote in order that om+ accepts the ‘(3 4) as a list.
if you omit the quote, you’ll get illegal car WHY ?

Well without the quote, lisp will consider the car of the expression (yes it is an expression like (om+ 3 4) is an expression) to be either a function or a macro.
IMPORTANT: Because in lisp a function call is a list where the car of the list is either a function, method or a macro. So in order to consider ‘(3 4) as a list and not a function call to be evaluated, we should use a quote OR just make it an expression by using (list 3 4) …

3.
So if we consider the default values of csolver (cf. screenshot) we will have

(csolver 8 ‘(|48_72|) ‘(3) ‘(2 7) nil ‘(1 3))
Because csolver takes 6 arguments

if you transcribe it as :

(csolver (8 ‘(|48_72|) ‘(3) ‘(2 7) nil ‘(1 3)))
this is wrong because the compiler will consider 8 as a function and tries to evaluate it.
and if you use it so :

(csolver ‘(8 ‘(|48_72|) ‘(3) ‘(2 7) nil ‘(1 3)))

or so :

(csolver (list 8 ‘(|48_72|) ‘(3) ‘(2 7) nil ‘(1 3)))

there will be just one argument to csolver method, and it requires 6 arguments.

Ok hope this was rather clear.

Best
K

Attachments:
  1. Screenshot_2018-03-08_13-10-18

    Screenshot_2018-03-08_13-10-18.png

  2. Screenshot_2018-03-08_13-10-18

    Screenshot_2018-03-08_13-10-18.png

March 8, 2018 at 13:20 #25834
Profile photo of fdsdb
fdsdb

Dear Karim,

Thank you very much for explanation, very kind by you. Yes, after your explanation it is clearer and obvious because I had that error. Sorry, I should be more analytical in building expressions and so on, but I have been not still arrived to that level, sometimes I proceed by (wrong) intuiton and experiments…

I hope we meet again in person, it will be a pleasure.

Ciao

Fabio

March 8, 2018 at 16:52 #25837

You must be logged in to reply to this topic.

Log in now