Cannot import defined variables from Dart file to an another - dart

I have defined the int c in a dart file called (main.dart)
I want to use this variable in another Dart file called (ex.dart). The both dart files are in the same directory (bin)
I used this code (import 'main.dart';) also this (import './main.dart';) . But it gives me this Error: Getter not found: 'c'.
it could not define c , although it was previously defined in (main.dart) file.
any one can help ?

Related

Agda Installation PLFA Configuration

I am trying to use the Programming Language Foundation with Agda plfa library, however the import does not appear to be working properly.
I have cloned the repository and added the repository path to: ~/.agda/libraries and plfa to ~/.agda/defaults.
When I create a test.agda file and check a single line
module plfa.part1.Naturals where
I get an import error:
You tried to load /Users/johngfisher/Desktop/agda_test/nats.agda
which defines the module plfa.part1.Naturals. However, according to
the include path this module should be defined in
/Users/johngfisher/agda_env/libraries/plfa/src/plfa/part1/Naturals.lagda.md
The file is present in the location the import is coming from so I am unsure of why Agda is unable to find it. Any help would be appreciated.
module plfa.part1.Naturals where
defines a module named plfa.part1.Naturals
Did you mean to type
module test where
open import plfa.part1.Naturals
instead?

F#: Why does script file not recognize module?

I create a new F# console application project in Visual Studio 2015
I create a simple new module file called Calc.fs like so:
module Calc
let add a b = a + b
I add an F# script file to the project like so:
open Calc
let c = add 1 2
I get the following compiler errors in the script file:
The namespace or module 'Calc' is not defined
and
The value or constructor 'add' is not defined
Why is my module not recognized by my script file? How can I fix this?
Please note that my script file appears after the module in the order of files in the project:
.fsx files are not compiled together with the rest of the project; they don't "know" about any other code unless you explicitly make it known to them. This is true for any external DLLs (and in fact even many in the .NET Framework) as well as other F# code.
You need to add
#load "Calc.fs"
at the top of the script file to tell the compiler to load that code before evaluating the rest of the script.

How to check object class type in Dart

In my code, there is a place where I need to take different actions based on the input class type.
So I write two lines to check an input object's class type.
debugPrint("Let me know the next action: $action");
debugPrint((action is LoadPomodorosAction).toString());
And the output is
I/flutter (24128): Let me know the next action: Instance of 'LoadPomodorosAction'
I/flutter (24128): false
What does this mean?
The object 'action' is "Instance of 'LoadPomodorosAction'" and at the same time its class type is not LoadPomodorosAction .
how do I adjust my code so that I can know the class type of action?
I was suspecting that maybe there is something wrong with runtimetype. But how do I get to know the runtimetype?
I've tried replicating your issue and I'm not able to reproduce it. But to explain your inquiry, here is a complete details about the difference between the relative path and absolute path when used in imports as discussed in this SO post:
package imports
'package:... imports work from everywhere to import files from
lib/*.
relative imports
Relative imports are always relative to the importing file. If
lib/model/test.dart imports 'example.dart', it imports
lib/model/example.dart.
If you want to import test/model_tests/fixture.dart from any file
within test/*, you can only use relative imports because package
imports always assume lib/.
This also applies for all other non-lib/ top-level directories like
drive_test/, example/, tool/, ...
lib/main.dart
There is currently a known issue with entry-point files in lib/*
like lib/main.dart in Flutter.
https://github.com/dart-lang/sdk/issues/33076
Dart always assumed entry-point files to be in other top-level
directories then lib/ (like bin/, web/, tool/, example/,
...). Flutter broke this assumption. Therefore you currently must not
use relative imports in entry-point files inside lib/
See also
How to reference another file in Dart?
Previously, this bug was posted in GitHub as an issue between relative and absolute path. It seems that this was resolved per this GitHub post.

Require custom C module in Lua by path

This is a problem that plagued me for quite a while.
After I wrote and compiled my custom functions into a shared library, require('mylib') would only work when the shared library was directly in the same directory as the script I called it from.
Any efforts to try require('/path/to/mylib') or similar absolute paths failed. Furthermore, "backtracking" through a relative path (i.e. using .. failed as well.
So how can one specify the bin directory, or wherever the shared library is output to?
Well according to the Lua documentation on the require call (using Lua 5.2 here), there are a few places the loader looks for these loadable modules.
It seems that require() uses what are called "searchers" (docs linked to in above) to determine where to find these modules. There are four searchers in total. From the docs:
The first searcher simply looks for a loader in the package.preload
table.
The second searcher looks for a loader as a Lua library, using the
path stored at package.path. The search is done as described in
function package.searchpath.
The third searcher looks for a loader as a C library, using the path
given by the variable package.cpath. Again, the search is done as
described in function package.searchpath. For instance, if the C path
is the string "./?.so;./?.dll;/usr/local/?/init.so" the searcher for module foo will try to open the files ./foo.so, ./foo.dll, and
/usr/local/foo/init.so, in that order. Once it finds a C library, this
searcher first uses a dynamic link facility to link the application
with the library. Then it tries to find a C function inside the
library to be used as the loader. The name of this C function is the
string "luaopen_" concatenated with a copy of the module name where
each dot is replaced by an underscore. Moreover, if the module name
has a hyphen, its prefix up to (and including) the first hyphen is
removed. For instance, if the module name is a.v1-b.c, the function
name will be luaopen_b_c.
The fourth searcher tries an all-in-one loader. It searches the C path
for a library for the root name of the given module. For instance,
when requiring a.b.c, it will search for a C library for a. If found,
it looks into it for an open function for the submodule; in our
example, that would be luaopen_a_b_c. With this facility, a package
can pack several C submodules into one single library, with each
submodule keeping its original open function.
The searcher of use to us is the third one: it is used for any shared libraries (.dll or .so) which is generally how our custom C modules are built.
Using the template string (the one with the question marks), the searcher will look in each of the specified paths, substituting the argument of require() in place of the question mark. In order to specify the path for this third searcher, one must set (or append to) package.cpath and then call require().
So perhaps you have a directory structure as
- ROOT
|-lua
|-bin
where lua contains script.lua and bin contains mylib.so
To load mylib.so, you just need these two lines of code in script.lua:
package.cpath = '/ROOT/bin/?.so;' .. package.cpath
libfuncs = require('mylib')
NOTE: Notice the semicolon. If you append (as opposed to the prepending above), make sure to lead with the semicolon on your added path. It is not there buy default. Otherwise your new path will be merged to the current default cpath, which is just ./?.so.
If you whant just configure your system to use some path to store
libraries there then best way just use LUA_PATH and LUA_CPATH env variables.
e.g.LUA_CPATH=/path/to/?.so. Or for specific Lua version like LUA_CPATH_5_3=/path/to/?.so.
But if you have full path to some library and whant just load this particular library from this directory you can use package.loadlib function.
local function loadlib(path, name)
local sep = string.sub(package.config, 1, 1)
local file = path .. sep .. name .. ((sep == '/') and '.so' or '.dll')
local func = 'luaopen_' .. name
local loader, msg = package.loadlib(file, func)
assert(loader, msg)
return assert(loader())
end
local mylib = loadlib([[/path/to]], 'mylib')

In lua how to use load file variable in main file

my main file syntax is bellow
dofile("subFile.lua")
main('a')
print(subVariable)
my sub file syntax is bellow
local subVariable=""
function main(x)
subVariable="from sub"
end
my subfile contain variable named subVariable want to use this variable in my main file ,why i always get nil.
How to use main file variable in subfile and subfile variable in main file
You're using a local. Remove the " local" and it'll work.
Locals are only accessible by the functions and code behind it.

Resources