I want to do the following:
let dist = Stack.pop stck and dir = Stack.pop stck in (
print_endline(dist);
print_endline(dir);
......
......
)
The above gives me the following error:
Error: This expression has type unit
This is not a function; it cannot be applied.
How can I use the variables dist and dir over multiple lines?
The error is not in the piece of code you show here. I guess you forgot a ; somewhere.
But there is a subtle error in your code.
In this line of code
let dist = Stack.pop stck and dir = Stack.pop stck in
You expect to obtain the first element of the stack in dist and the second one in dir but it may not be the case as the order of evaluation is unspecified.
The basic syntax of your code is OK. Here's a simple example showing that it works fine:
$ ocaml
OCaml version 4.01.0
# let x = 5 and y = 4 in (
print_int x;
print_int y;
);;
54- : unit = ()
#
The reported errors have to do with other problems. We would need more context to see what's wrong. Possibly the errors are in the lines you elided. Or they could be caused by what comes next.
Related
I have a snippet of python code as a function here. The purpose of the code is to use the combinations tool of itertools and turn a list of pairs into a list of triplets by matching items that correlate with each other. Due to the time consuming nature of the function, I have been trying to get it to work using a GPU through numba. Here is the function followed by me calling it:
#jit(target_backend='cuda')
def combinator(size, theuniquegenes, thetuplelist):
limiter = size+1
lengths = [l + 1 for l in range(len(theuniquegenes)) if (l + 1 > 2) and (l + 1 < limiter)]
new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
correlations = {x for x in new_combs if all([c in thetuplelist for c in combinations(x, 2)])}
print(len(correlations))
tuplelist = thetuplelist + list(correlations)
print(len(tuplelist))
return tuplelist
tuplelist = combinator(3, uniquegenes, tuplelist)
Unfortunately, I keep encountering the following error message:
numba.core.errors.UnsupportedError: Failed in object mode pipeline (step: inline calls to locally defined closures)
Use of unsupported opcode (SET_ADD) found
new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
^
How can I rewrite this line to work?
I am passing initial conditions as string, to be used to solving an ODE in sympy.
It is a first order ode, so for example, lets take initial conditions as y(0):3 for example. From help
ics is the set of initial/boundary conditions for the differential
equation. It should be given in the form of {f(x0): x1,
f(x).diff(x).subs(x, x2): x3}
I need to pass this to sympy.dsolve. But sympify(ic) gives an error for some reason.
What other tricks to use to make this work? Here is MWE. First one shows it works without initial conditions being string (normal mode of operation)
from sympy import *
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics={y(0):3})
gives sol Eq(y(x), x**2 + x + 3)
Now the case when ics is string
from sympy import *
ic = "y(0):3"
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics={ sympify(ic) })
gives
SympifyError: Sympify of expression 'could not parse 'y(0):3'' failed,
because of exception being raised: SyntaxError: invalid syntax
(, line 1)
So looking at sympify webpage
sympify(a, locals=None, convert_xor=True, strict=False, rational=False, evaluate=None)
And tried changing different options as shown above, still the syntax error shows up.
I also tried
sol = dsolve(ode,y(x),ics= { eval(ic) } )
But this gives syntax error as well
Is there a trick to use to convert this initial conditions string to something sympy is happy with?
Python 4.7 with sympy 1.5
As temporary work around, currently I do this
from sympy import *
ic = "y(0):3"
ic = ic.split(":")
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics= {S(ic[0]):S(ic[1])} )
Which works. So the problem is with : initially, sympify (or S) do not handle : it seems.
You can use sympify('{y(0):3}').
I don't know what your actual goal is but I don't recommend parsing strings like this in general. The format for ICs is actually slightly awkward so that for a second order ODE it looks like:
ics = '{y(0):3, y(x).diff(x).subs(x, 0):1}'
If you're parsing a string then you can come up with a better syntax than that like
ics = "y(0)=3, y'(0)=1"
Also you should use parse_expr rather than converting strings with sympify or S:
https://docs.sympy.org/latest/modules/parsing.html#sympy.parsing.sympy_parser.parse_expr
I want to call a second web service with the result from the first one.
Below is some code that highlights my intent.
By the way it compiles fine in IntelliJ(Probable a bug in the IDE).
def get = {
for {
respA <- WS.url(url1).get
id <- respA.body.split(",").take(2)
respB <- WS.url(url2 + id).get // Here is a compile error
} yield {
getMyObjects(respB.xml)
}
}
respA = is a comma separated list with ids used in the next call.
respB = is an XML response that I parse in the yield method
The compile error Play Framework gives me:
type mismatch;
found : scala.concurrent.Future[Seq[MyObject]]
required: scala.collection.GenTraversableOnce[?]
I find the compile error strange.
How can a Future of [Seq[MyObject]] exist at that line?
It shouldn't be any different from the line two lines up that compiles?
WS.url(url1).get returns Future[Response] so all your generators in the for comprehension should be futures. In your code snippet, you are mixing Array[String] and Future[Response]. See Type Mismatch on Scala For Comprehension for some background on for comprehension.
So I would try something like this:
for {
respA <- WS.url(url1).get
ids = respA.body.split(",").take(2)
responsesB <- Future.sequence(ids.map(id => WS.url(url2 + id).get))
} yield {
responsesB.map(respB => getMyObjects(respB.xml))
}
So the types are:
respA: Response
ids: Array[String]
ids.map(id => WS.url(url2 + id).get): Array[Future[Response]]
Future.sequence(ids.map(id => WS.url(url2 + id).get)): Future[Array[Response]]
responsesB: Array[Response]
And the return type of the for comprehension is a Future of an array of whatever getMyObjects returns.
Note that if sequence does not work on Future[Array[_]] try to do ids = respA.body.split(",").toList.take(2).
Hi everyone I'm newbie in prolog and I have such a list: (actually It is output of my predicate not a list )
P = [1/1, 1/3] ;
P = [1/1, 2/3] ;
P = [1/3, 1/1] ;
P = [1/3, 2/1] ;
P = [2/1, 1/3] ;
P = [2/1, 2/3] ;
P = [2/3, 1/1] ;
P = [2/3, 2/1] ;
and I need to remove dublicete terms.For example [1/1,2/3] and [2/3,1/1]is same and I should remove one of them , which one is not important ,How could I do that in prolog ?? Thanks in advance
NOTE I LEARNT THAT findALL should be good way for this but still dont know the answer please help me .
Unless you actually show us your code, it's never going to be possible to give you precise answers.
I assume you have a predicate f/1 such that:
?- f(P).
produces the interactive result you show above. A simple solution is to change your query:
?- f([X,Y]), X < Y.
This will produce the following result:
X = 1/3, Y = 1/1 ;
X = 1/3, Y = 2/1 ;
X = 2/3, Y = 1/1 ;
X = 2/3, Y = 2/1 ;
findall/3 isn't sufficient to solve this particular situation, because you've defined uniqueness in a way that ignores the position in the list. In Prolog (and everything else) [X,Y] and [Y,X] are not equal, so you'd have to find a trick to get this to give you "unique" results.
This works ok
let staticParams = [ProvidedStaticParameter("filename", typeof<string>)
ProvidedStaticParameter("forcestring", typeof<bool>, false)]
but this does not
let filename3 = ProvidedStaticParameter("filename", typeof<string>)
let forcestring = ProvidedStaticParameter("forcestring", typeof<bool>, false)
let staticParams = [filename3
forcestring]
What is the difference ?
Then if I type this, it is correctly recognized aggain
let filename3 = ProvidedStaticParameter("filename", typeof<string>)
let forcestring = ProvidedStaticParameter("forcestring", typeof<bool>, false)
let staticParams = [filename3 ;
forcestring]
The ; is an archaic syntax (coming from ML). There is no reason to use it, unless you are typing several elements in the same line (e.g. [ 1; 2 ]). Also in records, you don't have to put ; between the fields.
The second code doesn't compile because all the elements must have the same indentation level:
let staticParams = [filename3
forcestring]
In F#, indentation is significant. For example:
let staticParams = [filename3
forcestring]
two values have the same indentation level, they are parsed as list elements.
However in the following case:
let staticParams = [filename3
forcestring]
// ^
// Notice different indentation here.
two values are parsed as function application of filename3 to forcestring and hence an error message.
Since ; is list delimiter, in your last example F# parser expects another list element in the next line. Therefore, there is no problem with wrong indentation there.