Closed nicolewhite closed 8 years ago
Hey, good catch with the 0! That's an easy fix.
Can you show me the full query that threw that error?
Hey @jexp what do you think of handling the eval
stuff by having a flag -e
for starting cycli in "evaluate exports" mode? With the changes above:
$ cycli -e
> export nums=[x**2 for x in range(5)]
> env
nums=[0, 1, 4, 9, 16]
> UNWIND {nums} AS n RETURN n;
| n
---+----
1 | 0
2 | 1
3 | 4
4 | 9
5 | 16
15 ms
So by default it will parse the value with json.loads
but if you're in -e
mode it'll parse the value with eval
.
Hmm that would mean depending on which mode you run cycli with your scripts would work or not? I think the eval thing is something on a case-by-case basis rather.
I could rather imagine an export -e nums=[x**2 for x in range(5)]
if you rather want to have a flag than a second keyword :)
Would it be possible for the eval code to access existing parameters? Like env['nums']
?
Yeah, that's a good point about scripts. I was trying to avoid having a separate keyword. :) But I like your idea of using a flag for the export command itself.
I think I'm going to stick with the -e
flag to start cycli in "evaluate export" mode despite your (@jexp) concern about script compatibility. Because anything you do in the default mode (where it uses json.loads
) should be compatible with eval
mode. For example, setting constants such as strings or numbers will be the same whether it's passed to json.loads
or eval
:
>>> json.loads('54')
54
>>> eval('54')
54
>>> json.loads('"Tom Hanks"')
'Tom Hanks'
>>> eval('"Tom Hanks"')
'Tom Hanks'
Same with maps and collections:
>>> json.loads('{"name":"Nicole"}')
{'name': 'Nicole'}
>>> eval('{"name":"Nicole"}')
{'name': 'Nicole'}
>>> json.loads('[1,2,3]')
[1, 2, 3]
>>> eval('[1,2,3]')
[1, 2, 3]
So you can run your scripts in -e
mode to ensure compatibility. Can you think of any exceptions to this?
Btw I added the ability to access variables by key.
> export age=54
> env
age=54
> env["age"]
54
> env['age']
54
> env['lol']
>
Alright, new plan is just to use eval
all the time since anything that you'd throw at json.loads
can be handled by eval
as far as Cypher syntax is concerned.
Parameters can be set with
export key=value
and viewed withenv
.Closes #33.