In Python I can add a custom message to an assertion to help with code development:
assert False, "Expected true"
How can I do the same in Julia?
From the documentation:
#assert false "Expected true"
#assert cond [text]
Throw an AssertionError if cond is false. Preferred syntax for writing assertions. Message text is optionally displayed upon assertion failure.
Related
We have a following code in Python
def function1()
...........
raise Exception ..
...............
return 0
Robot script:
${STATUS}= function1
Can anyone please let me know how in Robot script we can catch the return code / exception and branch accordingly?
Run Keyword And Return Status will return a boolean true/false did the enclose keyword succeed.
Run Keyword And Ignore Error returns a tuple of two values - the 1st is the string "PASS" or "FAIL" depending did your keyword succeed or not; the second - the keyword's return value if it passed, or any error messages if not.
Thus surround your keyword with one of these 2 - it really boils down to do you care about the returned value in success or the error in failure - and work with the returned values.
${passed}= Run Keyword And Return Status function1
Run Keyword If ${passed} Action When Passed ELSE Different Action
${rc} ${msg} Run Keyword And Ignore Error function1
Run Keyword If "${rc}" == 'PASS' Log The keyword returned the value: ${msg}
... ELSE Log The keyword failed with the message: ${msg}
I am working in Julia and I'm trying to use Documenter.jl to create a documentation page for Examples.jl and I keep getting this error when I try to run my make.jl file:
ERROR: LoadError: UndefVarError: type not defined
Here is my code for the make.jl file:
using Documenter
using Examples
makedocs(
sitename = "Examples.jl",
pages = Any[
"About" => "index.md",
"Main" => "main.md",
"Graphs" => "graphs.md",
"Utilities" => "utilities.md",
"Tutorial" => "tutorial.md"
]
)
Any ideas how to fix this error? Thanks
As #Matt B. pointed out, type is no longer a valid keyword. In Julia 0.x you used to define types as:
type foo
bar
end
Now we use struct or mutable struct instead. e.g.
struct foo
bar
end
Go through your code and see if you see type anywhere.
As an experiment, I wanted to add type annotations to my project and test it with mypy --strict. Consider the following code and the error message below:
#!/usr/bin/env python
import typing as T
from dataclasses import dataclass
#dataclass(frozen=True)
class Question:
choices: T.Tuple[None]
def gen_question() -> Question:
choices = [None]
return Question(choices=tuple(choices))
if __name__ == '__main__':
gen_question()
Here's the error message:
test.py:18: error: Argument "choices" to "Question" has incompatible type "Tuple[None, ...]"; expected "Tuple[None]"
Is there something I'm doing wrong, or is that a bug? How can I solve the problem?
It appears that in case of typing.Tuple, according to the documentation, if I need to specify a variable-length tuple I need to add , ... as in the following:
choices: T.Tuple[None, ...]
Note that this doesn't seem to apply to lists.
I managed to compile the mruby code adding the mrubygem - mruby-require from https://github.com/mattn/mruby-require
However when I try to call the require './' I get an error. Below is my code:
inc.rb
def test(a, b)
print "Inside the include->test(..)"
return a+b
end
test1.rb
require 'inc.rb'
def helloworld(var1)
print 'hello world ' + var1 + ". Test number = " + test(4, 5)
end
helloworld('test')
When I execute test1.rb I get this error from mruby:
NoMethodError: undefined method 'puts' for main
After some analysis I found out the 'puts' is not working with mruby. Infact after adding mruby-require gem, no ruby code gets execute. Do I need to add any dependency with mruby-require?
Can someone help me please?
Update: Pasting the content of build_config.rb as requested. I have removed the lines which are commented.
build_config.rb
MRuby::Build.new do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# adding the mruby-require library
conf.gem 'mrbgems/mruby-require'
conf.gembox 'default'
end
MRuby::Build.new('host-debug') do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.gembox 'default'
conf.cc.defines = %w(ENABLE_DEBUG)
conf.gem :core => "mruby-bin-debugger"
end
The following quote is from its README.md:
When mruby-require is being used, additional mrbgems that appear after mruby-require in build_config.rb must be required to be used.
This is from your build_config.rb:
conf.gem 'mrbgems/mruby-require'
conf.gembox 'default'
The default gembox contains mruby-print. So either require mruby-print or preferably swap the lines to make it a built-in gem (the default behavior without mruby-require).
I'm trying to abort a task in ada program but I get this error during compilation:
expect task name or task interface class-wide object for "abort"
The code looks like this:
task type Sending_Message;
type Send_Message is access Sending_Message;
declare
send : Send_Message;
begin
send := new Sending_Message;
...
abort send; -- this line throws error
end;
And again when I try line like this:
abort Sending_Message;
I get error:
invalid use of subtype mark in expression or call
Any idea what is wrong?
You have to explicitly dereference the access type:
abort send.all;