What does the ? in the last line means and why does this evaluates to true?
let
attr = {a="a"; b = 1; c = true;};
in
ex7 = ! attr ? a == false;
I've also tried
{a="a"; b = 1; c = true;} ? false
also evaluate to true, but
! {a="a"; b = 1; c = true;} ? a==true
! {a="a"; b = 1; c = true;} ? a==1
both evaluate to false.
I've found it in the manual of nix language https://nixos.org/nix/manual/#sec-language-operators .
Test whether set e contains the attribute denoted by attrpath; return
true or false.
Related
If I have a set, I can get easily a element of this set.
{ a = 1; b = 2; c = 3; }
{ a = 1; b = 2; c = 3; }
builtins.typeOf {a = 1; b = 2; c = 3; }
"set"
{ a = 1; b = 2; c = 3; }.a
1
Now I have another set
builtins.typeOf (let f= builtins.getFlake "github:informalsystems/cosmos.nix"; in let ff= f.outputs.devShells.x86_64-linux; in ff.cosmos-shell)
"set"
Ok that a set but it doesn't really look like a set ( «» instead of{})
let f= builtins.getFlake "github:informalsystems/cosmos.nix"; in let ff= f.outputs.devShells.x86_64-linux; in ff.cosmos-shell
«derivation /nix/store/drfgr6zlkbv70wmml5n8h9x2wj29kk39-nix-shell.drv»
and I can't take the field derivation
builtins.attrNames (let f= builtins.getFlake "github:informalsystems/cosmos.nix"; in let ff= f.outputs.devShells.x86_64-linux; in ff.cosmos-shell
give others field. That are the elements used to build cosmos-shell
My question is why this command
let f= builtins.getFlake "github:informalsystems/cosmos.nix"; in let ff= f.outputs.devShells.x86_64-linux; in ff.cosmos-shell
doesn't return
a set with the element defining cosmos-shell
or
another type giving the derivation where cosmos-shell is defined and with method to get the element defining cosmos-shell
Why am I asking this question
Normally I can easily export a set as a json string
builtins.toJSON { a = 1; b = 2; c = 3; }
"{"a":1,"b":2,"c":3}"
But in this case I can't.
builtins.toJSON (let f= builtins.getFlake "github:informalsystems/cosmos.nix"; in let ff= f.outputs.devShells.x86_64-linux; in ff.cosmos-shell)
'>""/nix/store/wf3inmq4x93s3z32m90xz8d10gkz55zb-nix-shell""'
A derivation is little more than an attribute set with the name type having the value "derivation". (Whether such a set can be used as a derivation is meant to be used is another matter.) The Nix repl recognizes all such sets and diplays them in a special way.
> { type = "derivation"; }
«derivation ???»
I want to take a look at all of the options which have been set to some window
current_window = vim.api.nvim_get_current_win()
vim.wo[current_window].wrap = true
Trying just to call print(vim.inspect(current_window)) gives me this:
{
<metatable> = {
__index = <function 1>,
__newindex = <function 2>
}
}
Trying to get size of the table gives me zero:
local v = vim.wo[current_window]
print(#v) -- result is 0
But at the same time this property exists. The next snippet gives me true
print(vim.inspect(vim.wo[current_window].wrap)) -- result is true
How can I extract all of the window options?
Type :h options.txt
Type /local to window and press enter
Press n or N to go forward and backward
Make sure you've read :h help-summary and :h user-manual
Came to the next snippet, which will print out options for the current window in neovim
local all_options = api.nvim_get_all_options_info()
local win_number = api.nvim_get_current_win()
local v = vim.wo[win_number]
local all_options = api.nvim_get_all_options_info()
local result = ""
for key, val in pairs(all_options) do
if val.global_local == false and val.scope == "win" then
result = result .. "|" .. key .. "=" .. tostring(v[key] or "<not set>")
end
end
print(result)
guys!
Can you help me, please!
I want to add a number to a table, and I want to have it like this:
A={1,2,3}
B=A+5
--- now B is {6,7,8}
I don't want to create any classes, additional modules. May be some kind of extension to global table?
I think it can be done via global __add overrides.. Any thoughts?
A = setmetatable({1,2,3},
{
__add = function (t, add)
assert(type(add) == "number", "invalid addend! number expected")
local result = {}
for i,v in ipairs(t) do
result[i] = v + add
end
return result
end
})
B = A + 5
print(table.concat(B, ","))
C = A + "f"
You can do this by iterating through the table with ipairs and setting each element of B to the sum of the number and the corresponding element of A
For example
local B = {};
local numberToAdd = 5;
for i, v in ipairs(A) do
B[i] = v + numberToAdd;
end
A metatable can also be used to have the syntax B = A + 5. You would use the same code as the example, but you would need to use setmetatable on A then set the __add function of the metatable to the example code.
I want to use z3py to implement an access policy analyzer just like AWS Zelkova. The first step I need to do is to encode the policy language into logical expressions. For instance, a control policy
effect:Allow
principal:students
action: getObject
resource: cs240/Example.pdf,cs240/Answer.pdf
should be converted into
p = students ∧ a = getObject ∧ (r = cs240/Example.pdf ∨ r = cs240/Answer.pdf)
and using z3py I can represent it as
s.add(x1 == And(a == StringVal("GetObject"),p == StringVal("tas"),Or(r == StringVal("cs240/Exam.pdf"),r == StringVal("cs240/Answer.pdf"))))
Here comes the question. When input a policy, After parsing the policy, I may get an Array of values about one key and I need to use a loop to call Or() in order to get the result as Or(r[0],r[1],...). How can I do that? I have tried something like this but obviously it doesn't work.
from z3 import *
Action = ["getObject"]
Principal = ["tas"]
Resource = ["cs240/Exam.pdf","cs240/Answer.pdf"]
a,p,r,x = Bools('a p r x')
a_t,p_t,r_t = Strings('a_t p_t r_t')
s = Solver()
for act in Action:
a = Or(a,a_t == StringVal(act))
for principal in Principal:
p = Or(p,p_t == StringVal(principal))
for resource in Resource:
r = Or(r,r_t == StringVal(resource))
s.add(And(a,p,r))
print(s.check())
print(s.model())
That's the result of my program:
sat
[a_t = "", p = True, r_t = "", a = True, p_t = "", r = True]
You should build the expression one piece at a time and add it all together. Pseudocode:
foo = False
for i in items:
foo = Or(foo, i == ...whatever it should equal...)
s.add(foo)
When you build the expression, make sure to start the variable at False. Something like:
from z3 import *
Action = ["getObject"]
Principal = ["tas"]
Resource = ["cs240/Exam.pdf","cs240/Answer.pdf"]
a = False
p = False
r = False
a_t,p_t,r_t = Strings('a_t p_t r_t')
s = Solver()
for act in Action:
a = Or(a,a_t == StringVal(act))
for principal in Principal:
p = Or(p,p_t == StringVal(principal))
for resource in Resource:
r = Or(r,r_t == StringVal(resource))
s.add(And(a,p,r))
print(s.check())
print(s.model())
This prints:
sat
[r_t = "cs240/Exam.pdf", p_t = "tas", a_t = "getObject"]
I can't tell whether this is a correct answer as I haven't really studied your constraints, but the model seems more relevant to the question.
I have a form list in a tuple in the following format and a current page
CurrPageName = "ihtx_f_10_00_00_00_00_h210401".
FormList = {form_list, [{"IHTX_F_10_00_00_00_00_H210401",true},
{"IHTX_F_09_00_00_00_00_H210401",true},
{"IHTX_F_11_11_02_02_01_H220401",true},
{"IHTX_F_03_00_00_00_00_H210401",false},
{"IHTX_F_12_00_00_00_00_H211215",true},
{"IHTX_F_07_00_00_00_00_H210401",true},
{"IHTX_F_15_00_00_00_00_H210401",false},
{"IHTX_F_11_00_00_00_00_H210401",false},
{"IHTX_F_02_00_00_00_00_H210401",true},
{"IHTX_F_01_00_00_00_00_H240401",true}]}.
How to find CurrPageName from the FormList? I tried lists:keyfind, keysearch to the innerlist but always returning false or some error. If the CurrPageName exist and if its value is true then only it should return a true else false.
I'm newbie to erlang. Thanks
The list stores the page names as upper-case strings, so first make sure your CurrPageName variable contains upper-case string too
CurrPageName = string:to_upper("ihtx_f_10_00_00_00_00_h210401").
Then extract the list of tuples and search for the page
{form_list, L} = FormList, % Extract tuple list to L
KeyPosition=1, % The name we look for is at position 1 in the tuple
T=lists:keyfind(CurrPageName, KeyPosition, L),
case T of
{_Key, true} ->
true ;
false ->
false
end.
you can use proplists.
CurrPageName = string:to_upper("ihtx_f_10_00_00_00_00_h210401").
{form_list, L} = FormList,
Res = proplists:is_defined(CurrPageName, L)