Ocaml error unbound Value - emacs

When i try to evaluate line 2 or 5 of this program, i get "Unbound value carre" or "Unbound value bis".
To evaluate it i use emacs with tuareg, could it be related ?
let carre x = x*x;;
carre(9);;
let bis y = y^y;;
bis("ab");;
For example, here is what i get for line 2 :
# Characters 0-5:
carre(9);;
^^^^^
Error: Unbound value carre
#
The code is very simple so i feel like the problem comes from emacs.
I've tried to change function names, variables names, but nothing worked.
Does anybody see what's wrong here ?

You need to evaluate the first line of your program before the second.
The interpretor doesn't know the definition of carre or bis until you've evaluated it.

Related

how to store/replace local variable in debugger lldb in Xcode

I am new to Xcode and came by pycharm. In pycharm, I am able to use watcher to execute the statement and store as local variable in debugger mode. How could I do that same thing from Xcode debugger lldb?
for example
let a = 5
letba = 5
let aPlusb = Self.addFunc(a, b)
after place debugger on line 3. how can i call Self.addFunc() and store into some variable xy
I have tried expression or e under lldb and then po xy but it does not work with error
error: expression failed to parse:
error: <EXPR>:8:1: error: cannot find 'xy' in scope
`xy`
You're right that the expression parser is the command you want to use to create scratch variables that can record values in lldb. There are two ways to do this.
First of all, when you evaluate any expression using lldb's expression parser, lldb creates a "result variable" which stores the result of the expression:
(lldb) expr myVar
(Int) $R0 = 10
This can be used in future expressions, e.g.:
(lldb) expr print($R0)
10
The other way you can do this is to take advantage of the lldb convention that an identifier in an lldb expression which begins with a $ is treated as an lldb "persistent declaration", and can be used in future expressions. Except for a very few exceptions like this, lldb parses expressions exactly as they would be in source code compiled in the context of the current frame. So you just use the same syntax you would use to define the identifier in swift, so:
(lldb) expr var $myVar = 10
(lldb) expr print($myVar)
10
BTW, I'm not being abstruse using "identifier" instead of "variable" above. The same convention holds for other instances of identifiers, e.g. for type and function definitions as well.

implicit __source__ argument to julia macro can't be used within quote block

I'll start with my code:
macro example(args...)
local s = __source__
println(s) # This part works, showing macro is called on line 9
quote
println(s) # Julia tells me this variable "s" is not defined
println(__source__) # Likewise, "__source__" is not defined here either
end
end
#example 42 # Line 9 of my file
In my macro above I want to record the line number that is calling the macro and use it within my quote block. Both capturing it in a variable outside the quote block and using it within, or using it directly in the quote block don't work. My understanding is the code outside the quote block runs at parse-time, and the expression returned from the quote block is evaluated at run-time.
I feel like there must be a way to capture that variable and inject it right into the expression that will be evaluated later, but I haven't figured out how to do that. Any help here is appreciated. If there is a better way to do this let me know.
I ended up finding out an answer on my own. In the second line if I changed __source__ to __source__.line or __source__.file it worked fine as long as I then used $ to interpolate the result into the expression the macro returned. I'm still not sure why __source__ on its own didn't work, but using either .line or .file methods is working for me now.
I'm experiencing a similar problem trying to use __source__.
I think I can offer insight into why source.line, etc worked though.
The value of source.line is an integer. The value of source.fike is a string. Numbers and strings evaluate to themselves.
A symbol, on the other hand, evaluates to whatever value it has in the environment.

SPSS Macro - Generate dynamic Varnames

I am currently trying to create dynamic variable names based on the valuelabels of the passed Argument. Currently, I have something like this:
COMPUTE counter = 0.
APPLY DICTIONARY FROM *
/SOURCE VARIABLES = V601
/TARGET VARIABLES = counter.
DEFINE !macro1 (!POS !CMDEND).
STRING name (A20).
!DO !#i = 1 !TO 62
COMPUTE counter = #i
!IF (!POS !EQ !i)
!THEN
COMPUTE name = VALUELABEL(!POS)
COMPUTE !CONCAT('wasnot', name) = 1.
!ELSE
COMPUTE name = VALUELABEL(!counter).
COMPUTE !CONCAT('wasnot', name) = 0.
!IFEND
!DOEND
CROSSTABS v15 by !CONCAT('wasnot', name) /cells = column.
!ENDDEFINE.
The idea is, that for every unique value of V601 a flag variable will be created (e.g. "wasnotvaluelabel1"). This variable will either have value = 1 or 0 respectively. However, it seems that concat cannot be used the way I intended. I get these errors:
Error # 6843 in column 7. Text: !POS
The end of a macro expression occurred when an operand was expected.
Execution of this command stops.
Error # 6846 in column 7. Text: !POS
A macro expression includes an undefined macro variable or a macro operator
which is not valid within an expression.
Error # 6836 in column 12. Text: !EQ
In a macro expression, an operator was not preceded by an operand.
Error # 6846 in column 2. Text: !THEN
A macro expression includes an undefined macro variable or a macro operator
which is not valid within an expression.
Error # 6846 in column 28. Text: !POS
A macro expression includes an undefined macro variable or a macro operator
which is not valid within an expression.
Questions I have right now:
Is it even possible to generate dynamic names? I have tried
different attempts over the last hours but the SPSS macro "language"
seems very restricted.
Is there perhaps some other way to achieve this Task? It seems rather unconvenient.
Please note, working with the Python AddIn is sadly not an Option. I'm grateful for any received advice.
There is an extension command, SPSSINC CREATE DUMMIES, that will create all these dummy variables automatically. It's on the Transform menu. And it is implemented in Python.
Using Python you can easily read case data and do lots more.
Thanks for all the Help. In the end I did it with generating new syntax using Outfile.

Strange syntax error

I'm new to MATLAB, and I have the following problem:
I have the line:
[~, j] = min(matrix);
I don't understand what the ~ sign is for(I have to learn this code..) and the error is:
Expression or statement is incorrect--possibly unbalanced (, {, or [.
What can be the reason?
Another question, suppose I have got a file.m and inside of it I have the declaration:
methods (Static)
function var = func(n, d)
How do I call this function with the 2 parameters from the command windows?
i dont understand whats for ~ sign
Discard first returning output, it is not going to be used.
What can be the reason?
What version of Matlab do you use? This syntax has only been part of MATLAB since about R2009b or so.
How do i call this function func with the 2 parameters from the command windows?
Yes, otherwise - http://www.mathworks.com/help/matlab/matlab_prog/support-variable-number-of-inputs.html

Octave : Index exceeds matrix dimensions

I wrote the following function in a file named conditionals.m:
function result = conditionals(category, feature)
result=5;
end
I call this function from Octave's command line:
v=conditionals(3,4)
I get the following error:
error : A(I) : Index exceeds matrix dimension.
Whats wrong here?
The error:
error : A(I) : Index exceeds matrix dimension.
Indicates that octave thinks that conditionals is a matrix, not a function.
Octave probably doesn't know that conditionals is a function - and instead it's treating it as a matrix.
Have you checked to see if the function is in Octave's search path?
This works for me.
octave> function result = conditionals (category, feature)
> result = 5;
> endfunction
octave> v = conditionals (3, 4)
v = 5
The error suggests that you have a variable with the same name as the function. Type whos at the Octave prompt to see a list of defined variables. If you see one named conditionals, remove it with clear conditionals
Also, if conditionals is a conditionals.m file, make sure it's on the function search path. Run path at the Octave prompt to see the function search path. Run which conditionals at the command prompt to see where the function is located.
It happened to me as well and it can happen on any command, regardless of the command name. When I run the PS1(">>"); to change the command prompt in Ovtave, I got the same error.
octave-3.2.3.exe:9> PS1(">>");
error: A(I): Index exceeds matrix dimension.
As others also mentioned, this error fires when there is a parameter with the same command name. It happens when we mistakenly enter the command with wrong syntax and hence, octave run the command and produce a variable with your command name that overload the internal command.
You can verify this status by who command. If you can see the same variable name as your command here, you have to remove it. Use clear variable_name to remove the variable.
Here is my output for PS1 command.
Hope it helps.