What does this curly braces mean in Systemverilog? [duplicate] - system-verilog

This question already has answers here:
What do curly braces mean in Verilog?
(2 answers)
Closed 3 years ago.
I am starting to learn SystemVerilog. I am stuck with a priority encoder and can't get this part :
priority if (encoder_in == {{14{1'bx}},1'b1,{1{1'b0}}})

this is actually a concatenation of 3 constants.
{ {14{1'bx}}, 1'b1, {1{1'b0}} }
1--^^^^^^^^^^
2--------------^^^^
3--------------------^^^^^^^^^
is a replication operator and it generates a 14-bits of 'x'.
is a one-bit 1
is a replication operator with a single repetition. I have no idea why it is used this way.
The following would be an equivalent expression:
{{14{1'bx}}, 1'b1, 1'b0}
or this
{{14{1'bx}}, 2'b10}
or this:
16'xxxxxxxxxxxxxx10
Next, priority is a system verilog modifier which could be applied to an if or a case operators. Read about unique end priority modifiers in system verilog.

Related

How to match the first word after a specific expressions with regex? [duplicate]

This question already has answers here:
Python Regex Engine - "look-behind requires fixed-width pattern" Error
(3 answers)
Regex to get the word after specific match words
(5 answers)
Closed 8 months ago.
This post was edited and submitted for review 8 months ago and failed to reopen the post:
Original close reason(s) were not resolved
My code below match the first word after one expression "let" :
(?<=\blet\s)(\w+)
What I need is to match the first word after a specific expressions, "let", "var", "func"
Input text:
let name: String
var age: Int
func foo() {
//...
Expected:
name
age
foo
Here is an image for clarity:
Since some regex flavors do not allow using groups inside lookbehinds and alternatives of different length, it is safe to use a non-capturing group with the lookbehind as alternatives:
(?:(?<=\blet\s)|(?<=\bvar\s)|(?<=\bfunc\s))\w+
Here, (?:...|...|...) is a non-capturing group matching one of the three alternatives: (?<=\blet\s), (?<=\bvar\s) and (?<=\bfunc\s).

What is (!). in kdb and are below usecases valid to use it?

What is (!). called in kdb?
and are below use cases valid to use (!). to convert a list to a dictionary or are there better ways and other uses of (!). ?
Example:
q)(!). (`A`B;(`C`D`E;`F`G`H));
q).[(!);flip (`A`B;`C`D;`E`F)]
I cannot find any documentation on the use cases on (!). in kdb tutorials. Please share any information on (!). and its uses?
It's a version of apply & yep your use case is valid. The reason the operator is wrapped in parentheses is because it itself is a dyadic infix operator as is dot apply (.)
If you attempt to apply it as is, your expression is like so, which Q doesn't like
// infixOp infixOp operand
q)+ . 4 5
'
[0] + . 4 5
^
Wrapping the operator within parentheses effectively transforms it so the expression now becomes
// operand infixOp operand
q)(+). 4 5
9
If you define a function which can't be used infix, then there's no need to wrap it
q)f:+
q)4 f 5
'type
[0] 4 f 5
^
q)f . 4 5
9
If using apply with bracket notation as in your example, there's no need to wrap the function
q).[+;4 5]
9
https://code.kx.com/q/ref/apply/#apply-index
https://code.kx.com/q/basics/syntax/#parentheses-around-a-function-with-infix-syntax
Jason
In terms of use-cases, I find it very useful when defining dictionaries/tables as configs particularly when dictionaries are too wide (horizontal) for the screen or when it's more useful to see fields/mappings vertically as pairs. From a code/script point of view that is.
For example:
mapping:(!) . flip(
(`one; 1);
(`two; 2);
(`three; 3));
is much easier to read when scanning through a q script than
mapping2:`one`two`three!1 2 3
when the latter gets very wide.
It makes no difference to the actual dictionary of course because as Jason pointed out it's the same thing.

Difference between & and && in Scala? [duplicate]

This question already has answers here:
Are there good uses for non-short-circuiting logical (boolean) operators in Java/Scala?
(4 answers)
What is the difference between the | and || or operators?
(12 answers)
Why doesn't the bitwise & operator short-circuit?
(5 answers)
Closed 5 years ago.
I am trying to figure out the difference between & and && in Scala. I got this after searching
& <-- verifies both operands
&& <-- stops evaluating if the first operand evaluates to false since the result will be false
Can somebody explain the same with example as am not clear, what verifying both operands means here. Are we talking about just Booleans?
Both are logical AND operators in Scala. The first form, &, will evaluate both operands values, for example:
val first = false
val second = true
if (first & second) println("Hello!")
Will evaluate both first and second before exiting the if condition, although we know that once a false appears in a logical AND, that entire expression will already yield false.
This is what && is for, and what it does is short-circuit the evaluation, meaning you only ever evaluate firsts value and then exit the conditional.
You can use bitwise AND (&) to perform bitwise operations on integers, which is similar to most programming languages.

'If' efficiency when evaluating 2 expressions [duplicate]

This question already has answers here:
Is Perl optimized to skip remaining logic operands if the answer is already decided?
(6 answers)
Closed 7 years ago.
if(expression1 or expression 2)
{
do something
}
If 'expression1' returns true, does the compiler starts to execute 'do something' or it evaluates the second expression too?
No, expression2 will not be evaluated if expression1 is true.
This is because or is short-circutted in perl: once the result of the entire expression is known, evaluation stops. Evaluation occurs from left to right.

what does "::" mean in Scala ? [duplicate]

This question already has answers here:
What do all of Scala's symbolic operators mean?
(11 answers)
Closed 8 years ago.
What does :: mean here ?
listeners ::= listener
list = num :: list
Specially I don't understand the "::" operator.
Its the list cons operator. It creates a new list whose head is first argument and whose tail is contents of the second argument.