Thread: [q-lang-users] modules and visibility
Brought to you by:
agraef
From: Arnoldo J. M. M. <ar...@da...> - 2006-01-08 04:03:37
|
Dear All, Thank you so much for all your previous help. Thanks to your advice I've been able to understand Q better. Every day I like Q more and more! (* x *)V I have two files: t1.q: //////////////////////////// public fspec; fspec(fcondition) = true; fspec(parameterRef) = true; fspec(methodRef) = true; fspec(fieldRef) = true; fspec(ftype) = true; fspec(localRef) = true; fspec(_) = false; //////////////////////////// and t2.q: //////////////////////////// import "t1"; //////////////////////////// When I execute the interpreter with "q t1.q" and enter the following: ==> fspec(localRef) true I will of course get true, When I execute the interpreter with "q t2.q" and enter: ==> fspec(localRef); false I unexpectedly get false... Using "debug on" I get the following: ==> fspec(localRef); 0> t1.q, line 10: fspec localRef ==> false (type ? for help) : ** fspec localRef ==> false false (Line 10 is the last rule of the t1.q file) What am I doing wrong? If I comment out line 10, Q will not execute the rule fspec, it's like the fspec rule disappears. (T _ T) Thanks in advance! |
From: Arnoldo J. M. M. <ar...@da...> - 2006-01-08 04:10:16
|
Hello All, Just after sending the e-mail it occurred to me that Q wasn't publishing the symbols I was using when matching, so I changed t2.q to: ///////////////////// public fspec; // change: (* x *)V public fcondition; public parameterRef; public methodRef; public fieldRef; public ftype; public localRef; // change: (* x *)V fspec(fcondition) = true; fspec(parameterRef) = true; fspec(methodRef) = true; fspec(fieldRef) = true; fspec(ftype) = true; fspec(localRef) = true; fspec(_) = false; ///////////////////// Now it works... Would this be the best solution? Thanks again! Best regards, AJMM. On Sun, 2006-01-08 at 13:02 +0900, Arnoldo Jose Muller Molina wrote: > Dear All, > > Thank you so much for all your previous help. Thanks to your advice I've > been able to understand Q better. Every day I like Q more and more! > (* x *)V > > > I have two files: > t1.q: > //////////////////////////// > public fspec; > > fspec(fcondition) = true; > fspec(parameterRef) = true; > fspec(methodRef) = true; > fspec(fieldRef) = true; > fspec(ftype) = true; > fspec(localRef) = true; > fspec(_) = false; > //////////////////////////// > > > and t2.q: > //////////////////////////// > import "t1"; > //////////////////////////// > > When I execute the interpreter with "q t1.q" and enter the following: > ==> fspec(localRef) > true > > I will of course get true, > > When I execute the interpreter with "q t2.q" and enter: > ==> fspec(localRef); > false > > I unexpectedly get false... > > Using "debug on" I get the following: > > ==> fspec(localRef); > 0> t1.q, line 10: fspec localRef ==> false > (type ? for help) > : > ** fspec localRef ==> false > false > > (Line 10 is the last rule of the t1.q file) > > What am I doing wrong? If I comment out line 10, Q will not execute the > rule fspec, it's like the fspec rule disappears. > (T _ T) > > Thanks in advance! > > > > > |
From: Albert G. <Dr....@t-...> - 2006-01-08 05:25:47
|
Arnoldo Jose Muller Molina wrote: > Just after sending the e-mail it occurred to me that Q wasn't publishing > the symbols I was using when matching, so I changed t2.q to: Exactly. :) In the interpreter you're always in the namespace of the main script you're running. You were running t2, t1 doesn't export those symbols to t2 => same identifier will refer to a different symbol in the namespace of the main script (that symbol is created by the interpreter on the fly). Exactly like it's supposed to be. When in doubt, try the whos command: ==> whos fcondition fcondition not a defined symbol If the interpreter actually knows the symbol then whos will show you the module in which it is defined. ==> whos map map function symbol defined in /usr/share/q/lib/stdlib.q map $1 $2 > public fcondition; > public parameterRef; > public methodRef; > public fieldRef; > public ftype; > public localRef; Of course you could just write: public fcondition, parameterRef, methodRef, fieldRef, ftype, localRef; > Now it works... Would this be the best solution? Well, it looks like your symbols are actually supposed to be constants, so why not turn them into an enumeration type: public type FSpec = const fcondition, parameterRef, methodRef, fieldRef, ftype, localRef; Then you can just write: fspec _:FSpec = true; fspec _ = false otherwise; As another nice side effect, you can now also compare the FSpec values using (=), (<) etc. :) HTH, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |