I have the following module:
module TestModule
export foo
function foo()
return 1
end
end
and a calling script:
using .TestModule
println(foo())
I get the following error:
ERROR: UndefVarError: TestModule not defined
According to the documentation this should work. I know this can be accomplished via include() but I read that this can cause inconsistencies when trying to include the module multiple times. Another way of achieving this seems to be editing the LOAD_PATH but that seems rather inconvenient and also causes the project to not be portable.
I'm wondering if those are the only current solutions to the problem or if there is something better (The two other post regarding this question are 6+ years old and the docs currently state that this is the way to do it, so I wonder if the problem has been fixed by now). Any help is greatly appreciated.
Cheers
I'm closing this thread as it has been tagged a duplicate multiple times now. I conclude from this that there currently is no way of splitting code into multiple local modules while maintaining portability. The canonical way of splitting code into modules is by adding the module paths to the LOAD_PATH (julia push!(LOAD_PATH, "\path\to\module")). Thanks to everyone for the feedback nonetheless!
Edit:
After executing the TestModule file it works for this example (I missed that this was necessary, at least in VSCode). My actual program still produces module-not-found errors but since I'm unable to reproduce them in a simple example I'll try figuring it out myself first.
Another Edit:
Renaming the modules solved the problem. I suppose the names were already taken by public packages. For any reader wondering how to solve this problem without renaming the custom module, please have a look at this documentation
Cheers
Related
I'm currenty cleaning up my first big R project and at a point, where I have a lot of functions implemented but I am not sure, which function got called and used by me in an other script and which function got never used. So now I want to get all calls of this function in my project. Is this possible?
I'm using RStudio and a lot of other IDEs I've used got a feature like this, so I was wondering if this is also implemented in RStudio.
I searched the web and stack overflow, but got no answer, so I assume that this is not possible but I wanted to ask, just in case it IS possible but I didn't found the right answer.
Thank you!
I'm working on a sniff for PHP_CodeSniffer 3.x. For example, the class declaration class NoInlineFullyQualifiedClassNameUnitTestInc extends \PSR2R\Base\AbstractBase should be split into a uses and class AbstractBase. The sniff detects similar issues for method signatures.
I believe the problem is that I'm generating and inserting multiple use statements at the same line (i.e., same token), but doing so in separate fixer->beginChangeset() ... fixer->endChangeset() sequences. The fixer treats multiple sets of changes to the same token as a conflict, and things get messy (and wrong).
The GitHub issue is here: https://github.com/php-fig-rectified/psr2r-sniffer/issues/9
Has anyone figured out how to do this writing custom sniffs for the latest 3.x CodeSniffer?
You can also use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff
It turns this
Into this
How to use it?
The best is to use it with EasyCodingStandard like this:
# easy-coding-standard.neon
checkers:
- SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff
Install it:
composer require --dev symplify\easy-coding-standard
Run it:
vendor/bin/ecs check src
Fix it:
vendor/bin/ecs check src --fix
Enjoy and let me know how it works for you.
If any troubles come up, just create an issue here. I'm happy to improve this tool as much as possible.
The problem is multiple Sniffer (fixer) changesets editing the same token. I was able to get the Sniff to work by collecting a list of USE statements and inserting them at the end of the Sniff's processing.
I identified the end of processing by searching backwards from the last token to find the first token of the list of registered tokens.
Edit: Here is the sniff: https://github.com/php-fig-rectified/psr2r-sniffer/blob/master/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php
I've started to use closure compiler and still hittin lot's of obstacles:)
I'm looking for the option that will output the list of removed methods/properties whatnot during the optimisation done by compiler - this would help me a lot when debugging the code.
There is no default option that lists removed symbols.
This should be possible by using a tool to highlight all of the lines that have mappings in a generated source map. Any line that has no mapping was dropped as dead code.
However I have not stumbled across a tool that would do this. It would be highly useful though and not specific to Closure-compiler.
I'm stuck using the 4.0 version of lua which does not seem to support the os library. Is there a way to include this library into my project?
Or get another way to use the functionality contained within pertaining to date time calculations?
Preferably by using a *.lua file and not a *.c file since I don't have complete access to the code.
When I run the following line,
print(os.time{year=1970, month=1, day=1, hour=0})
I get an error stating:
attempt to index global 'os'(a nil value)
As #Colonel Thirty Two said it's not possible to use the os library. So the time() funciton is not available for me.
Adding to the (totally correct) currently accepted answer (that if "os" access was not allowed to you, you're generally done), there's some very slight chance the Original Programmer may have provided you with some alternative facilities to do your thing (fingers crossed). In a perfect world, those would be described in some kind of a User's Manual for your scripting environment. But if the manual was lost to time (or never existed in the first place), you might possibly try your luck at exploring any preloaded libraries by digging through the result of the globals() Basic Function. (At least I hope that's how it was done in 4.0 too.) That is, if the Original Programmer didn't block globals() for you too...
I have a hudge code, and where all the libraries are attached in the begining of the code. Now, I'm cleaning a bit this code, removing parts of it / re-writting other.
I was wondering if there was a way to know if a specific library is used or not by the code (in order to clean the library part too)? I could list, for each library, all the functions that are attached, then search in the code that this function are not called, but it will become long. I could also remove this library and try to run the code, but I don't like this solution (not enough robust).
I'm sorry if the question have already been asked, but so far, I haven't found any solution :(.