I have a rather peculiar problem with IBM Doors, using its DXL language:
I CAN get a variable to the module I want to access:
our_mod = module "<path_including_filename_of_module>"
I can NOT perform any of the usual functions pertaining to modules on that variable, e.g.:
name (our_mod) //or entering the string consisting of path + filename directly)
it gives me the error output: "incorrect arguments for fucntion (name)"
BUT, if I search through the folder containing the module, I can grab it via its filename:
Item x
Item my_module
for x in my_folder do
{
if (name(x) == "<filename>")
{
my_module = x
}
}
THEN I can perform name(my_module) or type (my_module):
returns the filename and "Formal" as expected
But even if I get the module that way, I still can NOT iterate over the objects inside that module like with
Object o
for o in my_module do // ...in all my_module... does not work either, same error msg
{
//Do what I came to do...
}
It just gives me the error message "incorrect arguments for (do)"
If anybody had any idea whatsoever as to what might be causing this, would be much obliged.
thanks and regards
There are several data types in DXL that have something to do with modules, all of them have different access functions (perms). E.g. variables of type Item are good for iterating over "everything in a folder or project". If you want to iterate over objects, you need a variable of type Module. As you already found out, the perm "module (string)" does NOT return data of type Module. It returns either a variable of type bool or of type ModName_ (which is a module reference, not a module), depending on the data type where you assign the result. For details, see e.g. the perms list on Tony Goodman's page at http://www.smartdxl.com/downloads/undoc31.html.
In DXL, make sure that you ALWAYS declare variables with a type, never use Auto-Declare if you want to keep your sanity (if you say print our_mod in your upper example you will find that you got a bool, which of course has neither a name nor a type).
For getting a variable of type Module, you first need to open the module (like in real life :) :)). You can open it using edit, share or read. E.g. like this
Module m = read ("/path/to/my_mod", false /* display */, true /* load standard view */)
if null m then error "could not open the module"
Object o
for o in entire m do {print o."Absolute Number" ""}
close m
Related
One of my modules - let it be a - has an output definition as
output "data_table_arn" {
value = aws_dynamodb_table.data_table.*.arn
}
This is accessed one level above in module b
module "b" {
source = "../c"
data_lookup_table_arn = module.a.data_table_arn
The code above makes the variable module.a.data_table_arn accessible to module c through the variable data_lookup_table_arn. And now I am trying to access it in module c in an aws policy document definition
data "aws_iam_policy_document" "dynamo-read-policy-document" {
count = local.one_if_uses_dynamo
statement {
actions = ["dynamodb:GetItem"]
resources = [
var.data_table_arn
]
}
}
The exception I am getting is
Inappropriate value for attribute "resources": element 0: string required.
I want to debug this thing somehow and I cannot find a way to inspect the outputs or the variables defined inside a module. I can list the resources using terraform state list <resource_name> but this is not what I really want to do here.
How can I inspect the variables and outputs of a TF module?
Is this even possible?
Can you see anything faulty with my approach
I though of also using a heredoc instead of a aws_iam_policy_document but I would still need to make use of the output mentioned above - but this time in an interpolation I guess. Is this better or worse? They should be the same thing right?
I'm writing a drawing package with some parts, and I have operators and data types scattered througout. However I don't want the users to add the corresponding modules every time, since it would be quite messy, for instance I'd have a Point class, a Monoid role and a Style class
in different paths like this
unit module Package::Data::Monoid;
# $?FILE = lib/Package/Data/Monoid.pm6
role Monoid {...}
unit module Package::Data::Point;
# $?FILE = lib/Package/Data/Point.pm6
class Point {...}
unit module Package::Data::Style;
# $?FILE = lib/Package/Data/Style.pm6
class Style {...}
I would like to have a haskell like prelude in lib/Package/Prelude.pm6
with the effect that I can write such scripts
use Package::Prelude;
# I can use Point right away, Style etc...
instead of doing
use Package::Data::Style;
use Package::Data::Point;
use Package::Data::Monoid;
# I can too use point right away, but for users not knowing the
# inner workings it's too overwhelming
I've tried many things:
This version doesn't give me the right effect, I have to type
the whole path to point, i.e., Package::Data::Point...
unit module Package::Prelude;
# $?FILE = lib/Package/Prelude.pm6
use Package::Data::Style;
use Package::Data::Point;
use Package::Data::Monoid;
This version gives me the Point right away, but I get
problems with the operators and so on, also I would just like to
add automatically everything from the exported routines in the mentioned
example packages.
# $?FILE = lib/Package/Prelude.pm6
use Package::Data::Style;
use Package::Data::Point;
use Package::Data::Monoid;
sub EXPORT {
hash <Point> => Point
, <Style> => Style
, <mappend> => &mappend
...
}
Do you people know a better and quick way of getting such a prelude-like
file?
Using EXPORT is in the right direction. The key things to know are:
Imports are lexical
We can use introspection to obtain and access the symbols in the current lexical scope
So the recipe is:
use all the modules inside of EXPORT
Then extract all the imported symbols and return them as the result from EXPORT
As an example, I create a module Foo::Point, including an operator and a class:
unit module Foo::Point;
class Point is export {
has ($.x, $.y);
}
multi infix:<+>(Point $a, Point $b) is export {
Point.new(x => $a.x + $b.x, y => $a.y + $b.y)
}
And, just to demonstrate it can work with multiple modules, also a Foo::Monad:
unit module Foo::Monad;
class Monad is export {
method explain() { say "Just think of a burrito..." }
}
The goal is to make this work:
use Foo::Prelude;
say Point.new(x => 2, y => 4) + Point.new(x => 3, y => 5);
Monad.explain;
Which can be achieved by writing a Foo::Prelude that contains:
sub EXPORT() {
{
use Foo::Point;
use Foo::Monad;
return ::.pairs.grep(*.key ne '$_').Map;
}
}
There's a few oddities in here to explain:
A sub has implicit declarations of $_, $/, and $!. Exporting these would result in a compile-time symbol clash error when the module is use'd. A block only has an implicit $_. Thus we make our life easier with a nested bare block.
The grep is to make sure we don't export our implicitly declared $_ symbol (thanks to the nested block, it's the only one we have to care about).
:: is a way to reference the current scope (etymology: :: is the package separator). ::.pairs thus obtains Pair objects for each symbol in the current scope.
There's a speculated re-export mechanism that may appear in a future Raku language release that would eliminate the need for this bit of boilerplate.
I get unexpected results from the following code snippet using the eclipse ide:
class Example(String s = "init") {
shared String a() => "Func 1";
shared String b = "Attr 1";
shared String c(Integer i) { return "Func 2"; }
}
shared
void run() {
// 1.
print("getAttributes: " + `Example`.getAttributes().string);
print("getMethods: " + `Example`.getMethods().string);
// prints: []
// i.e. doesnt print any attribute or method
// 2.
value e = Example()
type(e); // error
e.type(); // error, should be replaced by the ide with the above version.
}
ad 1.) I get as a result:
getAttributes: []
getMethods: []
where I expected lists containing attributes or methods.
ad 2.) The doc says:
"The type() function will return the closed type of the given instance, which can only be a ClassModel since only classes can be instantiated.
..."
But I cant find the type() function and others related to meta programming, i.e. I dont get a tooltip, but instead I get a runtime (!) error:
Exception in thread "main" com.redhat.ceylon.compiler.java.language.UnresolvedCompilationError: method or attribute does not exist: 'type' in type 'Example'
So, where is the equivalent to the backticks `Example`.... as a function ?
`Example`.getAttributes() returns an empty list because getAttributes takes three type arguments: Container, Get, Set. When called as getAttributes(), the typechecker tries to infer them, but since there’s no information (no arguments with the appropriate type), the inferred type argument is Nothing. Since Nothing is not a container of any of the class’ members, the resulting list is empty. Use getAttributes<>() instead to use the default type arguments, or specify them explicitly (e. g. getAttributes<Example>()). Same thing with getMethods(). Try online
The type function is in ceylon.language.meta and needs to be imported: import ceylon.language.meta { type }. Once you do that (and remove the e.type() line), the compilation error will go away.
If you directly want a meta object of the function, you can write `Example.a`.
I struck to pass multiple arguments in define.
The following is my code. I would like to pass two array inside the define, But I'm able to pass only one as like the following.
class test {
$path = [$path1,$path2]
$filename = [$name1,$name2]
define testscript { $filename: } // Can able to pass one value.
}
define testscript () {
file {"/etc/init.d/${title}": //Can able to receive the file name.
ensure => file,
content => template('test/test.conf.erb'),
}
From my above code, I could retrieve the filename inside the define resource. I also need path to set the value in the template. I`m not able to send / retrieve second argument in template.
Is there any way to improve my code to pass two values ( $path and $filename ) inside define resource ?
Any help is much appreciated.
Is there any way to improve my code to pass the two values ( $path and $filename ) inside define resource ?
Puppet has good documentation, which covers this area well.
To begin, you need to appreciate that a defined type is a resource type, in almost every way analogous to any built-in or extension type. If your defined type accepts parameters, then you bind values to those parameters just as you would in any other resource declaration. For example:
class mymodule::test {
mymodule::testscript { $name1: path => $path1 }
mymodule::testscript { $name2: path => $path2 }
}
define mymodule::testscript ($path) {
file {"${path}/${title}":
ensure => 'file',
content => template('test/test.conf.erb')
}
}
Additionally, because defined types are resource types, you should discard the concept of "passing" values as to them as if they were instead functions. That mental model is likely to betray you. In particular, it will certainly give you the wrong expectation about what would happen if you specify an array or a hash as your resource title.
In particular, you need to understand that in any resource declaration, if you give the resource title as an array, then that means a separate resource for each array member, with the array member as that resource's title. In that case, every one of those resources receives the same parameter values, as declared in the body of the declaration. Moreover, resource titles are always strings. Except for one level of arrays, as described above, if you give anything else as a resource title then it will be converted to a string.
UDATED
How do I go about this?
I got this from Main.hx:
function onMouseOver(e:MouseEvent){
if(Std.is(e.currentTarget, MovieClip)){
initializer (cast e.currentTarget,["scaleX",1.5,"scaleY",1.5])
}
}
Then this is the pointed function in my Animation Class
//here if i set mc:Dynamic everything goes great! but when this one
function initializer(mc:MovieClip, vars:Array<Dynamic>){
var varsLength:Int = Math.round(vars.length/2);
for(m in 0...varsLength){
ini[m] = mc[vars[2*m]];
}
}
then when i compile it, an error appears:
Error: Array access is not allowed in flash.display.MovieClip
How do I resolve this?
EDIT:
vars: are properties of the MovieClip, for example when I pass these parameters:
initializer (mcClip1,["scaleX",1.5,"scaleY",1.5])
so:
vars = ["scaleX",1.5,"scaleY",1.5]
and:
ini[m] will store "scaleX" and "scaleY"`
X-Ref: https://groups.google.com/forum/#!topic/haxelang/_hkyt__Rrzw
In AS3, you can access fields of an object via their String name using [] (array access). This is called Reflection.
In Haxe, Reflection works differently - you need to make use of the Reflect API.
It's considered bad practice - it's not type-safe, which means the compiler can do very little to help you with error messages, and it's quite slow as well. This is why the usage makes it very explicit that Reflection is actually going on (while in AS3, this fact is somewhat hidden). Consider if there are other ways of solving this problem that don't require Reflection.
Now, to get back to your example, here's what it would look like in Haxe:
function onMouseOver(e:MouseEvent){
if (Std.is(e.currentTarget, MovieClip)) {
initializer(cast e.currentTarget, ["scaleX", 1.5, "scaleY", 1.5])
}
}
function initializer(mc:MovieClip, vars:Array<Dynamic>) {
for (m in 0...Std.int(vars.length / 2)) {
ini[m] = Reflect.getProperty(mc, vars[2*m]);
}
}
Btw, your loop was running for too long since you only use half of the values in the array - if you don't divide it by two like I did, you'll end up with [scaleX, scaleY, null, null] instead of the desired [scaleX, scaleY].