In Graphql, I can create a union such as the following:
union SearchResult = Book | Movie
Is there a way I can do this for plain strings? Something like this:
union AccountRole = "admin" | "consumer"
I am afraid you cannot do that because it is what defined by the specification.
From the union syntax mentioned at specification here , the part that you want to change should follow the Names syntax , which the first character is only allow to be upper case letter, lower case latter or _
(i.e. the characters set as follows)
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m
n o p q r s t u v w x y z _
Related
I am having some trouble figuring out how to iterate over space separated words/characters in a shell script. For instance I would like to iterate over a variable containing the characters in the alphabet separated by a space.
NOTE: The result should be the same even if the alphabet variable contained space separated strings instead of characters, i.e "aa bb cc ..." instead of "a b c .."
I have tried a lot of the alternatives provided from:
How to split a line into words separated by one or more spaces in bash?
Example:
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local index="0"
for character in $alphabet; do
index=$((++index))
echo "$index. $character"
# Possibility to do some more stuff
done
Expected/Desired output:
1. a
2. b
3. c
and so on..
Result:
1. a b c d e f g h i j k l m n o p q r s t u v w x y z
Additional tests(without success):
####################################################################
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local index="0"
for character in ${alphabet[#]}; do
index=$((++index))
echo "$index. $character"
# Possibility to do some more stuff
done
####################################################################
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local alphabetArray=( ${alphabet} )
local index="0"
for character in "${alphabetArray[#]}"; do
index=$((++index))
echo "$index. $character"
# Possibility to do some more stuff
done
####################################################################
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local alphabetArray=( ${alphabet} )
local index="0"
for character in ${alphabetArray}; do
index=$((++index))
echo "$index. $character"
# Possibility to do some more stuff
done
Could someone provide a solution on how to solve this(I would prefer a solution that iterates the alphabet variable without explicitly using an index variable, i.e $alphabet[index] )?
Thanks for your help. I discovered the error thanks to your feedback.
I thought that it was irrelevant when I posted this question but I was experimenting with functions in my .zshrc file. Hence I was using (just my assumption) the zsh interpreter and not the sh or bash interpreter.
By realizing that this could be a potential problem, I googled and found the following How to iterate through string one word at a time in zsh
So I tested the following and it works as expected:
setopt shwordsplit
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local index="0"
for character in $alphabet; do
index=$(($index+1))
echo "$index. $character"
# Possibility to do some more stuff
done
unsetopt shwordsplit
NOTE:
index=$((++$index))
and/or
index=$(($index++))
Doesn't seem to work as I expected in zsh.
... The little gritty details, I should have used:
((++index))
or
((index++))
instead of
index=$((++$index))
Try this
IFS=$' \t\n'
local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z"
local index="0"
for character in $alphabet; do
index=$((++index))
echo "$index. $character"
# Possibility to do some more stuff
done
Hope it helps
the algorithm is pretty straight forward I implemented it as soon as I saw newtons equation
function sq(x , e , g ){
g = g || x / 2
if(Math.abs( g * g - x ) < e )
return g
else
return sq( x , e , ( g + x / g ) / 2 )
}
now here is the thing on really small values the algorithm gives a way off answer and on really large values the algorithm exceeds the call stack .
I understand why
what I don't understand is in the first condition ..
if(Math.abs(g*g -x) < e ) why!! if we divide by x before comparing solves the problem e.g:
if(Math.abs(g*g -x) / x < e)
function sq(x , e , g ){
g = g || x / 2
if(Math.abs( g * g - x ) / x < e )
return g
else
return sq( x , e , ( g + x / g ) / 2 )
}
call the function like this first arg is the number you wanna compute the square root of , second is epsilon which is the range is which when I get a value should be acceptable , you could define an initial guess as a third argument
e.g:
sq( 9 , 0.01)
or:
sq(9 , 0.01 , 2)
Typically, you would specify ε as a fraction of g, not x, since normally you would want to say that the result has some precision ("six digits", for example) which is necessarily relative to the result. But it doesn't make much difference aside from interpreting the meaning of the ε parameter.
It is certainly the case that choosing some absolute error threshold makes no sense unless you know that the possible arguments are within a very restricted set of values.
[] = always
O = next
! = negation
<> = eventually
Wondering is it []<> is that equivalent to just []?
Also having a hard time understanding how to distribute temporal logic.
[][] (a OR !b)
!<>(!a AND b)
[]([] a ==> <> b)
I'll use the following notations:
F = eventually
G = always
X = next
U = until
In my model-checking course, we defined LTL the following way:
LTL: p | φ ∩ ψ | ¬φ | Xφ | φ U ψ
With F being a syntactic sugar for :
F (future)
Fφ = True U φ
and G:
G (global)
Gφ = ¬F¬φ
With that, your question is :
Is it true that : Gφ ?= GFφ
GFφ <=> G (True U φ)
Knowing that :
P ⊧ φ U ψ <=> exists i >= 0: P_(>= i) ⊧ ψ AND forall 0 <= j < i : P_(<= j) ⊧ φ
From that, we can clearly see that GFφ indicates that it must always be true that φ will be always be verified after some time i, and before that (j before i) True must be verified (trivial).
But Gφ indicates that φ must always be true, "from now to forever" and not "from i to forever".
G p indicates that at all times p holds. GF p indidcates that at all times, eventually p will hold. So while the infinite trace pppppp... satisfies both of the specifications, an infinite trace of the form p(!p)(!p!)p(!p)p... satisfies only GF p but not G p.
To be clear, both these example traces need to contain infinitely many locations, where p holds. But in the case of GF p, and only in this case, it is acceptable that there be locations in between, where p does not hold.
So the short answer to the above question by counterexample is: no, those two specifications aren't the same.
This is an extract of a file from this project (full text here):
Method redirects() [ Private, ProcedureBlock = 0 ]
{
/// Mnemonics
APC d APC^%X364 q
BEL d BEL^%X364 q
CBT(%1) d CBT^%X364(%1) q
CCH d CCH^%X364 q
CHA(%1) d CHA^%X364(%1) q
CHT(%1) d CHT^%X364(%1) q
CNL(%1) d CNL^%X364(%1) q
CPL(%1) d CPL^%X364(%1) q
CPR d CPR^%X364 q
CTC(%1,%2,%3,%4,%5,%6,%7,%8,%9) d CTC^%X364(%1,%2,%3,%4,%5,%6,%7,%8,%9) q
CUB(%1) d CUB^%X364(%1) q
CUD(%1) d CUD^%X364(%1) q
CUF(%1) d CUF^%X364(%1) q
CUP(%2,%1) d CUP^%X364(%2,%1) q
CUU(%1) d CUU^%X364(%1) q
CVT(%1) d CVT^%X364(%1) q
DA d DA^%X364 q
DAQ(%1,%2,%3,%4,%5,%6,%7,%8,%9) d DAQ^%X364(%1,%2,%3,%4,%5,%6,%7,%8,%9) q
DCH(%1) d DCH^%X364(%1) q
DCS d DCS^%X364 q
DL(%1) d DL^%X364(%1) q
DMI d DMI^%X364 q
DSR(%1) d DSR^%X364(%1) q
EA(%1) d EA^%X364(%1) q
ECH(%1) d ECH^%X364(%1) q
ED(%1) d ED^%X364(%1) q
EF(%1) d EF^%X364(%1) q
EL(%1) d EL^%X364(%1) q
EMI d EMI^%X364 q
EPA d EPA^%X364 q
ESA d ESA^%X364 q
FNT d DNT^%X364 q
GSM d GSM^%X364 q
GSS d GSS^%X364 q
HPA(%1) d HPA^%X364(%1) q
HPR(%1) d HPR^%X364(%1) q
HTJ d HTJ^%X364 q
HTS d HTS^%X364 q
HVP(%1,%2) d HVP^%X364(%1,%2) q
ICH(%1) d ICH^%X364(%1) q
IL(%1) d IL^%X364(%1) q
IND d IND^%X364 q
// And others, followed by old style MAC routines
}
This is the first time I see that... And I can't find documentation on what those "mnemonics" are.
What are they? Where is the documentation for it?
This is a standard mnemonics implementation for WebTerminal inside WebTerminal itself.
To make WebTerminal work as common terminal do over WebSockets, one of the most important things is a little line of code
use $io:(/NOXY:/BREAK):"^" _ ..InitialZName
which is executed at the beginning of WebSocket server initialization, and which actually set up the name of the mnemonic space, which is equal to WebTerminal's compiled routine name (like WebTerminal.Engine.1.int).
These mnemonics (APC, BEL, etc) are a little macro programs, which user can call from the terminal using the special syntax. For example, mnemonic "CHA" is used to set the caret position:
USER > w "Pos 0", /CHA(14), "Pos 14", /CHA(35), "Pos 35"
Pos 0 Pos 14 Pos 35
In order to make user able to access all of these with this syntax, there were a need to include all standard mnemonics names into terminal routine, which is set as a mnemonic space for each client by default (because setting the default mnemonic space, which include these mnemonics breaks WebTerminal). The only solution left is to declare them inside any method (in this case, the method named "redirects") using ProcedureBlock = 0.
Talking about the syntax, in general, we have
MNEMONICNAME(%ArgByRef) do MNEMONICNAME^%SYSTEMROUTINE(%ArgByRef) quit
This just calls all of the standard mnemonics which can be found in ^%X364 system routine.
i have a string that random generate by a special characters (B,C,D,F,X,Z),for example to generate a following string list:
B D Z Z Z C D C Z
B D C
B Z Z Z D X
D B Z F
Z B D C C Z
B D C F Z
..........
i also have a pattern list, that is to match the generate string and return a best pattern and extract some string from the string.
string pattern
B D C [D must appear before the C >> DC]
B C F
B D C F
B X [if string have X,must be matched.]
.......
for example,
B D Z Z Z C D C Z,that have B and DC,so that can match by B D C
D B Z C F,that have B and C and F,so that can match by B C F
D B Z D F,that have B and F,so that can match by B F
.......
now,i just think about suffix array.
1.first convert a string to suffix array object.
2.loop each a pattern,that find which suffix array can be matched.
3.compare all matched patterns and get which is a best pattern.
var suffix_array=Convert a string to suffix array.
var list=new List();
for (int i=0;i<pattern length;i++){
if (suffix_array.match(pattern))
list.Add(pattern);
}
var max=list[0];
for (int i=1;i<list.length;i++){
{
if (list[i]>max)
max=list[i];
Write(list[i]);
}
i just think this method is to complex,that need to build a tree for a pattern ,and take it to match suffix array.who have a more idea?
====================update
i get a best solution now,i create a new class,that have a B,C,D,X...'s property that is array type.each property save a position that appear at the string.
now,if the B not appear at the string,we can immediately end this processing.
we can also get all the C and D position,and then compare it whether can sequential appear(DC,DCC,CCC....)
I'm not sure what programming language you are using; have you checked its capabilities with regular expressions ? If you are not familiar with these, you should be, hit Google.
var suffix_array=Convert a string to suffix array.
var best=(worst value - presumably zero - pattern);
for (int i=0;i<pattern list array length;i++){
if (suffix_array.match(pattern[i])){
if(pattern[i]>best){
best=pattern[i];
}
(add pattern[i] to list here if you still want a list of all matches)
}
}
write best;
Roughly, anyway, if I understand what you're looking for that's a slight improvement though I'm sure there may be a better solution.