Like there is no official document for it
http://clojuredocs.org/clojure_core/clojure.core/allow-unresolved-vars
Apologies -- this is not a complete answer. I haven't figured out everything about it yet.
*allow-unresolved-vars* is defined in RT.java:
final static Var ALLOW_UNRESOLVED_VARS = Var.intern(CLOJURE_NS, Symbol.intern("*allow-unresolved-vars*"), F).setDynamic();
and used in Compiler.java:
if(o == null)
{
if(RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.deref()))
{
return sym;
}
else
{
throw Util.runtimeException("Unable to resolve symbol: " + sym + " in this context");
}
}
So clearly, its use here is to decide whether or not an exception should be immediately thrown when an unresolved symbol is encountered.
You can mess with it like so:
myns.core=> (ns clojure.core)
nil
clojure.core=> oops!
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:884)
clojure.core=> (defn q [] (oops!))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:12)
clojure.core=> (def *allow-unresolved-vars* true)
Warning: *allow-unresolved-vars* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *allow-unresolved-vars* or change the name. (/tmp/form-init1596111142512149454.clj:1)
#'clojure.core/*allow-unresolved-vars*
clojure.core=> oops!
IllegalArgumentException UnresolvedVarExpr cannot be evalled clojure.lang.Compiler$UnresolvedVarExpr.eval (Compiler.java:1771)
clojure.core=>
clojure.core=> (defn q [] (oops!))
CompilerException java.lang.VerifyError: (class: clojure/core$q, method: invoke signature: ()Ljava/lang/Object;) Unable to pop operand off an empty stack, compiling:(form-init1596111142512149454.clj:1:1)
But I haven't figured out a use yet, because unresolved variables still cause errors -- they're just different errors. Also, I don't understand the warning when re-def-ing it, because the warning says that it's not declared dynamic, whereas it looks to me as though it is declared dynamic in RT.java.
Related
As you see i have a check method defined in the class definition. The problem is that i cant compare the two characters since it doesnt let me to define char e in the class defintion. How do i fix this task? a==e is written by me for reference of what i have been doing, but i get the error message:
Syntax Error(s)
tester.java:7: error: cannot find symbol
if(a==e){
^
symbol: variable e
location: class tester
1 error
Thankful for any help!
public static void check (char a){`
`if(a==e){`
`System.out.println("if");`
`}else{`
`System.out.println("else");
}
}
I have a third-party library, and I want to use one of the supplied constructors.
ex.h:
/** Construct example from string and a list of symbols. The input grammar is
* similar to the GiNaC output format. All symbols and indices to be used
* in the expression must be specified in a lst in the second argument.
* Undefined symbols and other parser errors will throw an exception. */
ex(const std::string &s, const ex &l);
I tried the following:
symbol x("x");
ex e("x^2",x);
Unfortunately the usage of this constructor is incorrect. I get the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
All documentation that is provided is the comment above the declaration. I am a C++ novice, so I have no idea what is wrong.
I tried the suggestion in the first answer like the following:
symbol x("x");
ex expression;
ex e("x^2",expression);
std::cout << diff(e,x) << std::end
This results in the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
(lldb)
Note: I tried using e and expression in diff().
You need to provide an ex reference, not a symbol reference;
Try this:
ex MyEx1; //This will call to the ex default constructor for MyEx1, if it exist.
ex e("x^2",MyEx1); //This will call to the ex constructor that you want to use for e.
The second argument should be a list of symbols occuring in the string (more precisely, a GiNaC::ex handling a GiNaC::lst). This works:
symbol x("x");
ex e("x^2", lst{x});
The idea is that it should work with more than just one symbol:
symbol x("x"), y("y");
ex e("x^2-2*x*y+y^2", lst{x,y});
cout << diff(e, x) << endl; // prints "2*x-2*y" or similar
Error occurs when I try to delete raw_ostream
void LLVMGenerator::SaveModule(string path) {
std::string ErrInfo = "";
llvm::raw_ostream *out =
new llvm::raw_fd_ostream(path.c_str(), ErrInfo, llvm::sys::fs::F_None);
llvm::WriteBitcodeToFile(_mod, *out);
out->flush();
delete out; // LLVM ERROR: IO failure on output stream.
return;
}
OS Ubuntu 13.10 x64, LLVM 3.4
Some IO error occurred on the raw_fd_ostream object - perhaps the underlying writev call encountered a non-recoverable error. raw_fd_ostream's behavior in this case is to turn on a flag indicating an error has occurred, and if that flag is still on during destruction, it reports a fatal error (=crashes).
If you want to avoid this crash, you can call clear_error() on the object before you destruct it; though it's of course recommended that you first check whether an error occurred yourself, via has_error(), and try to handle it.
I am trying to take a list data type I created and make it a template. In doing so I've run into the following obscure problem. I can post all of the code if needed, but this is really the function that is causing the problem.
Note: This code was compiling just fine until I got to this method. I was compiling after writing every few lines as a sanity check, and everything was fine, but then I get to this point and it blows up. If I take the try/catch block out of this method it compiles just fine, so I'm pretty sure the problem is isolated there, not a missing semicolon in a header/etc. as reported from other answers -- though I did of course triple-check to be sure! :)
Here's the code that is causing the problem:
template<class T>
bool UnsortedListType<T>::IsFull()
{
try { return false; }
catch(std::bad_alloc exception) { return true; } // line 35
}
Like I said, I simplified it as much as possible while still triggering the error. Here is the error:
UnsortedListType.cpp||In member function 'bool UnsortedListType<T>::IsFull()':
UnsortedListType.cpp|35|error: expected type-specifier
UnsortedListType.cpp|35|error: expected unqualified-id before 'exception'
UnsortedListType.cpp|35|error: expected ')' before 'exception'
UnsortedListType.cpp|35|error: expected '{' before 'exception'
UnsortedListType.cpp|35|error: 'exception' was not declared in this scope
UnsortedListType.cpp|35|error: expected ';' before ')' token
Everything I can find on this error says the problem is either an extra semicolon or a missing semicolon, either in the header or this file. I can't find an instance of either. And if I remove the try/catch block, it compiles fine.
Plus, if I catch an int, it compiles just fine:
template<class T>
bool UnsortedListType<T>::IsFull()
{
try { return false; }
catch(int exception) { return true; }
}
I can also catch(int) and it will compile just fine, but if I try to catch(std::bad_alloc) (i.e. with no "exception" variable name) it throws the same error listed above. Even if I try simply catch(std::exception) it fails to compile.
So now I'm stumped. I'm not an expert at C++ by any stretch, this is for a class, and I'm not sure how to get past this error.
Incidentally, here's the code from the non-generic version, which also compiles just fine, and is verbatim from the textbook I'm using (Dale, if anyone wonders):
bool UnsortedListType::IsFull() const
{
NodeType* location;
try
{
location = new NodeType;
delete location;
return false;
}
catch (std::bad_alloc exception)
{
return true;
}
}
I am using CodeBlocks 12.11 IDE on Windows 7 with the built-in GNU compiler.
Any help appreciated, and I'll be happy to post more code if requested, I just didn't want to fill the page up.
Many thanks in advance.
PS I should state, yes I am doing homework, but the homework doesn't call for me to make a template, I am choosing to go that route myself. Not sure if it has any relevance, but this is the first time I've used C++ templates, so just tossing that out there.
std::bad_alloc is defined in the header <new>, so you need to include that.
Also, it's better to catch exceptions by reference. Catching by value causes a copy, perhaps sliced, of the exception object to be made. Personally I make non-const reference a habit, allowing exception state to be added during handling, but most basic exception types are stateless so there's no practical difference between const & and non-const &.
I'm trying to use the Gl3n (https://bitbucket.org/dav1d/gl3n) but
I keep getting error 42 whenever I try this:
alias Vector!(float, 2) vect2;
vect2 position;
position.x = 2.0f; //This is what causes the error
I looked into how the struct was implemented and x is an alias
for a get/set function that interacts with the array that stores
the values for the vector. I've tried something like this:
alias Vector!(float, 2) vect2;
vect2 position;
position = vect2(0.0f, 0.0f);
However, both methods give the same error:
Error 42: Symbol Undefined pure nothrow #property #safe void
gl3n.linalg.Vector!(float,
2).Vector.set_!('x').set_(float) C:\Users\CP\Documents\Visual
Studio 2010\Projects\D\STDS\
Error 42: Symbol Undefined
_D4gl3n6linalg16__T6VectorTfVi2Z6Vector6__initZ
I have the module linalg imported like this at the top:
import Gl3n.linalg; //Gl3n is the folder the source files are in
If I remember correctly, Error 42 is the linker error (optlink).
I don't remember the linker flag, but you need to tell the linker where the library is (gl3n.lib I suppose).
You can use pragma(lib, "gl3n.lib") at the top of your main file assuming gl3n.lib is located in the directory you are compiling from.