wxMaxima: "*" wrong number of arguments - tex

I used texput to redefine the tex1 output for *:
texput("*", "", infix);
but this causes an error when there are more than two terms:
tex1(a*b);
> ab
tex1(a*b*c);
> "*": wrong number of arguments.
Any idea why this is happening or how I might work around it?

Related

Problem with do if command in spss: "expression is incomplete"

I would like to compute in spss a multiple if condition. My data looks like this:
DO IF (A<75 & DN<75).
COMPUTE AD=0.
else if (A=75 & DN<75).
COMPUTE AD=(A-75).
else if (A<75 & DN=75).
COMPUTE AD=(DN-75).
else if (A=75 & DN=75).
COMPUTE AD=[(A-75)+(DN-75)].
END IF.
EXECUTE.
It gives me an error at the last compute command, saying:
The expression is incomplete. Check for missing operands, invalid operators,
unmatched parentheses or excessive string length.
Execution of this command stops.
Can anyone tell me please how should I formulate the equation in order to be acceptable to spss?
Right, square and curly brackets are not allowed in COMPUTE expressions, only parentheses. Spaces in between nested parentheses are allowed, but not required.

Kapacitor: Getting error while defining tick file

I'm on my very first script with kapacitor. I've written a tick file. Following is the script.
stream
.from().measurement('cpu')
.where("cpu" == 'cpu-total')
.alert()
.info(lamda:TRUE)
.log('/tmp/cpu.log')
I'm defining tick file to kapacitor using following command
kapacitor define highcpu -type stream -dbrp telegraf.default -tick cpu.tick
Getting Following error
invalid TICKscript: parser: unexpected unknown state, last char: ':' line 5 char 14 in "info(lamda:TRUE)". expected: ")"
I'm not getting exactly going wrong. I'm sure there is nothing wrong with config and telegraf and influxdb.
Kapacitor version 1.3.1
OS: Fedora 22
Missing 'b' in lamda.
Should be: lambda.
Q: I'm not getting exactly going wrong.
A: Short answer, syntax error.
Unfortunately the parser for Kapacitor's TICK script is not that mature yet and you really can't blame them for it. This project is still a baby, hence these such of errors only appear during runtime.
The problem is with your lambda expression .info(lamda:TRUE). You need to tell the expression which field or tag to lookup its value.
A typical lambda expression looks like
info(lambda: if ("sum" >= 45000, '1', '0'))
info(lambda: "isPeakHour" == 'true')
Something to note here is that, there is no True or False in Kapacitor yet. 1 or 0 is typically used to represent boolean.
You might also want to take note of single quote and double quotes in TICK script.
Single quotes are string literals
Double quotes are references to a field or tag. Double quotes are
only used in lambda expressions.

How does groovy distinguish division from strings?

Groovy supports / as a division operator:
groovy> 1 / 2
===> 0.5
It supports / as a string delimiter, which can even be multiline:
groovy> x = /foo/
===> foo
groovy:000> x = /foo
groovy:001> bar/
===> foo
bar
Given this, why can't I evaluate a slashy-string literal in groovysh?
groovy:000> /foo/
groovy:001>
clearly groovysh thinks this is unterminated for some reason.
How does groovy avoid getting confused between division and strings? What does this code mean:
groovy> f / 2
Is this a function call f(/2 .../) where / is beginning a multiline slashy-string, or f divided by 2?
How does Groovy distinguish division from strings?
I'm not entirely sure how Groovy does it, but I'll describe how I'd do it, and I'd be very surprised if Groovy didn't work in a similar way.
Most parsing algorithms I've heard of (Shunting-yard, Pratt, etc) recognize two distinct kinds of tokens:
Those that expect to be preceded by an expression (infix operators, postfix operators, closing parentheses, etc). If one of these is not preceded by an expression, it's a syntax error.
Those that do not expect to be preceded by an expression (prefix operators, opening parentheses, identifiers, literals, etc). If one of these is preceded by an expression, it's a syntax error.
To make things easier, from this point onward I'm going to refer to the former kind of token as an operator and the latter as a non-operator.
Now, the interesting thing about this distinction is that it's made not based on what the token actually is, but rather on the immediate context, particularly the preceding tokens. Because of this, the same token can be interpreted very differently depending on its position in the code, and whether the parser classifies it as an operator or a non-operator. For example, the '-' token, if in an operator position, denotes a subtraction, but the same token in a non-operator position is a negation. There is no issue deciding whether a '-' is a subtraction operator or not, because you can tell based on its context.
The same is, in general, true for the '/' character in Groovy. If preceded by an expression, it's interpreted as an operator, which means it's a division. Otherwise, it's a non-operator, which makes it a string literal. So, you can generally tell if a '/' is a division or not, by looking at the token that immediately precedes it:
The '/' is a division if it follows an identifier, literal, postfix operator, closing parenthesis, or other token that denotes the end of an expression.
The '/' begins a string if it follows a prefix operator, infix operator, opening parenthesis, or other such token, or if it begins a line.
Of course, it isn't quite so simple in practice. Groovy is designed to be flexible in the face of various styles and uses, and therefore things like semicolons or parentheses are often optional. This can make parsing somewhat ambiguous at times. For example, say our parser comes across the following line:
println / foo
This is most likely an attempt to print a multiline string: foo is the beginning of a string being passed to println as an argument, and the optional parentheses around the argument list are left out. Of course, to a simple parser it looks like a division. I expect the Groovy parser can tell the difference by reading ahead to the following lines to see which interpretation does not give an error, but for something like groovysh that is literally impossible (since, as a repl, it doesn't yet have access to more lines), so it's forced to just guess.
Why can't I evaluate a slashy-string literal in groovysh?
As before, I don't know the exact reason, but I do know that because groovysh is a repl, it's bound to have more trouble with the more ambiguous rules. Even so, a simple single-line slashy-string is pretty unambiguous, so I believe something else may be going on here. Here is the result of me playing with various forms in groovysh:
> /foo - unexpected char: '/' # line 2, column 1.
> /foo/ - awaits further input
> /foo/bar - unexpected char: '/' # line 2, column 1.
> /foo/bar/ - awaits further input
> /foo/ + 'bar' - unexpected char: '/' # line 2, column 1.
> 'foo' + /bar/ - evaluates to 'foobar'
> /foo/ - evaluates to 'foo'
> /foo - awaits further input
> /foo/bar - Unknown property: bar
It appears that something strange happens when a '/' character is the first character in a line. The pattern it appears to follow (as far as I can tell) is this:
A slash as the first character of a line begins a strange parsing mode.
In this mode, every line that ends with a slash followed by nothing but whitespace causes the repl to await further lines.
On the first line that ends with something other than a slash (or whitespace following a slash), the error unexpected char: '/' # line 2, column 1. is printed.
I've also noticed a couple of interesting points regarding this:
Both forward slashes (/) and backslashes (\) appear to count, and seem to be completely interchangeable, in this special mode.
This does not appear to happen at all in groovyConsole or in actual Groovy files.
Putting any whitespace before the opening slash character causes groovysh to interpret it correctly, but only if the opening slash is a forward slash, not a backslash.
So, I personally expect that this is just a quirk of groovysh, either a bug or some under-documented feature I haven't heard about.

Lpeg "empty loop in rule" error

Can anyone provide a clear explanation and some simple examples that show this error, apparently related to match-time capture (Cmt) ?
I don't understand the only mention that I can find, which is at
http://lua-users.org/lists/lua-l/2013-06/msg00086.html
Thanks
So this question is a bit old, but it's one of the first search results. There's not a lot on the Internet about this, and it may not be super obvious what's wrong.
The error message is a bit misleading, but what's happening - in formal PEG terms, at least as I understand them - there is a repetition operator applied to an parsing expression that can consume no input.
Or other words, LPeg has detected a loop that can match an empty string, which will never complete. There's a pure Lua implementation called LuLPeg which lacks this particular check, and if you execute your grammar it could easily enter an infinite loop.
I'm tinkering with little toy BASIC-ish language, and had the above issue with the following:
grammar = P{ "input",
input = V"block"^0 * -1,
block = V"expression"^0,
-- (define expression here)
}
With that idea that the root input is an optional block of code, and a block is zero or more expressions. This is pretty simplified, of course, I'm leaving out whitespace handling and that sort of thing. But what happens when you call grammar:match("")?
remaining string: "", at input. See if it matches a block.
remaining string: "", at block. See if it matches an expression.
remaining string: "", at expression. For the sake of time, let's say it doesn't match
remaining string: "", at block. Rule concludes with zero expressions, no input consumed.
remaining string: "", at input. One block consumed, check if more blocks match.
remaining string: "", at block. See if it matches an expression.
And so on. Since V"block" matches the empty string, input can find an infinite number of blocks to fulfil the rule V"block"^0. In this case, there's two good solutions: Set input to at most one block, or require block to be a least one expression and wherever there could be a block set it to ^0. So either:
grammar = P{ "input", -- blocks can be empty, input contains one (empty or otherwise) block
input = V"block" * -1,
block = V"expression"^0,
-- (define expression here)
}
Or:
grammar = P{ "input", -- blocks must be at least one expression, root can have one
input = V"block"^0 * -1,
block = V"expression"^1,
-- (define expression here)
}
In the first case, an empty string will match a block, which fulfills the the input rule. In the second, an empty string will fail block, fulfilling the input rule with zero matching blocks.
I haven't needed to use Cmt yet, but I believe what happened was old versions of LPeg assumed the function would either fail or consume input, even if the rule inside the Cmt call could match an empty string. More recent releases don't have this assumption.

what does this kinds of if mean?

I saw a config file on:
https://github.com/tzengyuxio/pages/blob/gh-pages/pandoc/pm-template.latex
In this file, there is some kinds of "if" that make me confused.
$if(fontsize)$$fontsize$,$endif$ % In my mind $xxx$ means a mathematical formula, but why does it appear in if-else statement?
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % What does this means? Does the 0, 1, 1 mean argument for commands ifnum, ifxetex and ifluatex? Shouldn't the arguments be in braces "{}" ? And what does it mean together?
And there is another kind of if: \IfFileExists{upquote.sty}{\usepackage{upquote}}{} % Why does this command have so many braces?
Why is there so many kinds of if? What is the differences of them?

Resources